1
0
mirror of https://github.com/minetest-mods/irc.git synced 2024-12-27 09:10:21 +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)
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)
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
return
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)

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 = 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)
config.debug = minetest.setting_getbool("irc.debug")

View File

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

View File

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