From 55ea96e88e1d0d52ca1a6e8cfff0dbdfea9672b3 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Tue, 3 Dec 2013 16:37:02 -0500 Subject: [PATCH] Use the reply API to reply in-channel --- init.lua | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/init.lua b/init.lua index a79d250..030aafd 100644 --- a/init.lua +++ b/init.lua @@ -1,15 +1,11 @@ irc_users = {} -local function notify(nick, message) - return mt_irc:queueMsg(mt_irc.msgs.privmsg(nick, message)) -end - local old_chat_send_player = minetest.chat_send_player minetest.chat_send_player = function(name, message) for nick, loggedInAs in pairs(irc_users) do if name == loggedInAs and not minetest.get_player_by_name(name) then - notify(nick, message) + mt_irc:say(nick, message) end end return old_chat_send_player(name, message) @@ -33,7 +29,7 @@ mt_irc:register_bot_command("login", { description = "Login as a user to run commands", func = function(user, args) if args == "" then - notify(user.nick, "You need a username and password") + mt_irc:reply("You need a username and password") return end local found, _, playername, password = args:find("^([^%s]+)%s([^%s]+)$") @@ -47,11 +43,11 @@ mt_irc:register_bot_command("login", { minetest.log("action", "User "..user.nick .." from IRC logs in as "..playername) irc_users[user.nick] = playername - notify(user.nick, "You are now logged in as "..playername) + mt_irc:reply("You are now logged in as "..playername) else minetest.log("action", user.nick.."@IRC attempted to log in as " ..playername.." unsuccessfully") - notify(user.nick, "Incorrect password or player does not exist") + mt_irc:reply("Incorrect password or player does not exist") end end}) @@ -62,22 +58,23 @@ mt_irc:register_bot_command("logout", { minetest.log("action", user.nick.."@IRC logs out from " ..irc_users[user.nick]) irc_users[user.nick] = nil - notify(user.nick, "You are now logged off") + mt_irc:reply("You are now logged off") else - notify(from, "You are not logged in") + mt_irc:reply("You are not logged in") end -end}) + end, +}) mt_irc:register_bot_command("cmd", { params = "", description = "Run a command on the server", func = function (user, args) if args == "" then - notify(user.nick, "You need a command") + mt_irc:reply("You need a command") return end if not irc_users[user.nick] then - notify(user.nick, "You are not logged in") + mt_irc:reply("You are not logged in") return end local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$") @@ -86,7 +83,7 @@ mt_irc:register_bot_command("cmd", { end local command = minetest.chatcommands[commandname] if not command then - notify(user.nick, "Not a valid command") + mt_irc:reply("Not a valid command") return end if minetest.check_player_privs(irc_users[user.nick], command.privs) then @@ -101,18 +98,18 @@ mt_irc:register_bot_command("say", { description = "Say something", func = function (user, args) if args == "" then - notify(from, "You need a message") + mt_irc:reply("You need a message") return end if not irc_users[user.nick] then - notify(user.nick, "You are not logged in") + mt_irc:reply("You are not logged in") return end if minetest.check_player_privs(irc_users[user.nick], {shout=true}) then minetest.log("action", user.nick.."@IRC says " ..args.." as "..irc_users[user.nick]) minetest.chat_send_all("<"..irc_users[user.nick].."@IRC> "..args) - notify(user.nick, "Message sent successfuly") + mt_irc:reply("Message sent successfuly") end end})