mirror of
https://github.com/minetest-mods/irc.git
synced 2025-07-01 07:30:30 +02:00
Add better support for multiple servers and remove format_in/format_out
This commit is contained in:
@ -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)
|
||||
|
||||
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
--
|
||||
|
||||
|
Reference in New Issue
Block a user