1
0
mirror of https://github.com/minetest-mods/irc.git synced 2024-11-05 17:50:20 +01:00

Add better support for multiple servers and remove format_in/format_out

This commit is contained in:
ShadowNinja 2013-08-26 13:25:06 -04:00
parent b3ae3f5f03
commit 25696a8e9a
5 changed files with 35 additions and 64 deletions

View File

@ -88,38 +88,6 @@ All settings are changed in 'minetest.conf'. If any of these settings
irc.SASLUser (string, default irc.nick) irc.SASLUser (string, default irc.nick)
The SASL username. This should normaly be set to your main NickServ account name. The SASL username. This should normaly be set to your main NickServ account name.
irc.format_out (string, default "<$(name)> $(message)")
This specifies how to send the messages from in-game to IRC.
The strings can contain "macros" (or variable substitutions), which
are specified as "$(macro_name)".
Currently, these macros are supported:
$(name) The name of the player sending the message.
$(message) The actual message text.
Any unrecognized macro will be left in the message verbatim.
For example, if a user named "mtuser" is saying "Hello!", then:
"<$(name)> $(message)"
...will yield...
"<mtuser> Hello!"
...and...
"$(name): $(message) $(xyz)"
...will yield...
"mtuser: Hello! $(xyz)"
irc.format_in (string,
default "<$(name)@IRC> $(message)")
This specifies how the messages gotten from the IRC channel are
displayed in-game.
The strings can contain "macros" (or variable substitutions), which
are specified as "$(macro_name)".
Currently, these macros are supported:
$(name) The nickname of the user sending the message.
$(message) The actual message text.
$(server) The IRC server.
$(port) The IRC server port.
$(channel) The IRC channel.
In the default configuration, this will yield:
<IRCUser@IRC> Hello!
irc.debug (boolean, default false) irc.debug (boolean, default false)
Whether to output debug information. Whether to output debug information.

View File

@ -25,7 +25,8 @@ minetest.register_on_chat_message(function(name, message)
or (not minetest.check_player_privs(name, {shout=true})) then or (not minetest.check_player_privs(name, {shout=true})) then
return return
end end
mt_irc:queueMsg(mt_irc.msgs.playerMessage(mt_irc.config.channel, name, message)) mt_irc:queueMsg(mt_irc.msgs.playerMessage(
mt_irc.config.channel, name, message))
end) end)

View File

@ -54,14 +54,6 @@ config.timeout = tonumber(minetest.setting_get("irc.timeout")) or 60.0
config.command_prefix = minetest.setting_get("irc.command_prefix") or '!' config.command_prefix = minetest.setting_get("irc.command_prefix") or '!'
config.command_prefix = config.command_prefix:sub(1, 1) config.command_prefix = config.command_prefix:sub(1, 1)
-- The format of messages sent to IRC server (string, default "<$(name)> $(message)")
-- See `README.txt' for the macros supported here.
config.format_out = minetest.setting_get("irc.format_out") or "<$(name)> $(message)"
-- The format of messages sent to IRC server (string, default "<$(name)@IRC> $(message)")
-- See `README.txt' for the macros supported here.
config.format_in = minetest.setting_get("irc.format_in") or "<$(name)@IRC> $(message)"
-- Enable debug output (boolean, default false) -- Enable debug output (boolean, default false)
config.debug = minetest.setting_getbool("irc.debug") config.debug = minetest.setting_getbool("irc.debug")

View File

@ -55,16 +55,34 @@ end
function mt_irc.hooks.channelChat(user, channel, message) function mt_irc.hooks.channelChat(user, channel, message)
local t = { -- Support multiple servers in a channel better by converting:
access=user.access, -- "<server@IRC> <player> message" into "<player@server> message"
name=user.nick, -- "<server@IRC> *** player joined/left the game" into "*** player@server joined/left the game"
message=message, -- and "<server@IRC> * player orders a pizza" into "* player@server orders a pizza"
server=mt_irc.conn.host, local foundchat, _, chatnick, chatmessage
port=mt_irc.conn.port, = message:find("^<([^>]+)> (.*)$")
channel=channel local foundjoin, _, joinnick
} = message:find("^%*%*%* ([^%s]+) joined the game$")
local text = mt_irc.config.format_in:expandvars(t) local foundleave, _, leavenick
mt_irc:sendLocal(text) = message:find("^%*%*%* ([^%s]+) left the game$")
local foundaction, _, actionnick, actionmessage
= message:find("^%* ([^%s]+) (.*)$")
if foundchat then
mt_irc:sendLocal(("<%s@%s> %s")
:format(chatnick, user.nick, chatmessage))
elseif foundjoin then
mt_irc:sendLocal(("*** %s@%s joined the game")
:format(joinnick, user.nick))
elseif foundleave then
mt_irc:sendLocal(("*** %s@%s left the game")
:format(leavenick, user.nick))
elseif foundaction then
mt_irc:sendLocal(("* %s@%s %s")
:format(actionnick, user.nick, actionmessage))
else
mt_irc:sendLocal(("<%s@IRC> %s"):format(user.nick, message))
end
end end
@ -80,15 +98,8 @@ function mt_irc.hooks.pm(user, message)
mt_irc:say(user.nick, "User '"..player_to.."' is not in the game.") mt_irc:say(user.nick, "User '"..player_to.."' is not in the game.")
return return
end end
local t = { minetest.chat_send_player(player_to,
name=user.nick, "PM from "..user.nick.."@IRC: "..message, false)
message=message,
server=mt_irc.server,
port=mt_irc.port,
channel=mt_irc.channel
}
local text = mt_irc.config.format_in:expandvars(t)
minetest.chat_send_player(player_to, "PM: "..text, false)
mt_irc:say(user.nick, "Message sent!") mt_irc:say(user.nick, "Message sent!")
elseif message:sub(1, 1) == "!" then elseif message:sub(1, 1) == "!" then
mt_irc:bot_command(user, message:sub(2)) mt_irc:bot_command(user, message:sub(2))

View File

@ -32,9 +32,8 @@ function mt_irc.msgs.action(to, message)
end end
function mt_irc.msgs.playerMessage(to, name, message) function mt_irc.msgs.playerMessage(to, name, message)
local t = {name=name, message=message} return mt_irc.msgs.privmsg(to, ("<%s> %s"):format(name, message))
local text = mt_irc.config.format_out:expandvars(t)
return mt_irc.msgs.privmsg(to, text)
end end
-- TODO Add more message types -- TODO Add more message types
--