Compare commits

...

5 Commits

Author SHA1 Message Date
ShadowNinja 22e523cc7a Update to latest API version 2014-05-28 20:29:32 -04:00
ShadowNinja e2ff55d70f Reply when you have insufficient privileges for a command 2014-02-05 19:40:25 -05:00
ShadowNinja 55ea96e88e Use the reply API to reply in-channel 2013-12-03 16:37:02 -05:00
ShadowNinja 64e53cba45 Fix spelling of "logged" 2013-11-17 19:59:10 -05:00
ShadowNinja 0e0ce48738 Update to the new IRC mod API 2013-08-25 00:00:14 -04:00
1 changed files with 89 additions and 63 deletions

152
init.lua
View File

@ -1,77 +1,97 @@
irc_users = {}
local irc_users = {}
local old_chat_send_player = minetest.chat_send_player local old_chat_send_player = minetest.chat_send_player
minetest.chat_send_player = function(name, message) minetest.chat_send_player = function(name, message)
for nick, user in pairs(irc_users) do for nick, loggedInAs in pairs(irc_users) do
if name == user then if name == loggedInAs and not minetest.get_player_by_name(name) then
mt_irc.say(nick, message) irc:say(nick, message)
end end
end end
return old_chat_send_player(name, message) return old_chat_send_player(name, message)
end end
mt_irc.register_callback("nick_change", function (old_nick, new_nick) irc:register_hook("NickChange", function(user, newNick)
for nick, user in pairs(irc_users) do for nick, player in pairs(irc_users) do
if nick == old_nick then if nick == user.nick then
irc_users[new_nick] = irc_users[old_nick] irc_users[newNick] = irc_users[user.nick]
irc_users[old_nick] = nil irc_users[user.nick] = nil
end end
end end
end) end)
mt_irc.register_callback("part", function (nick, part_msg) irc:register_hook("OnPart", function(user, channel, reason)
if irc_users[nick] then irc_users[user.nick] = nil
irc_users[nick] = nil
end
end) end)
mt_irc.register_bot_command("login", { irc:register_hook("OnKick", function(user, channel, target, reason)
irc_users[target] = nil
end)
irc:register_hook("OnQuit", function(user, reason)
irc_users[user.nick] = nil
end)
irc:register_bot_command("login", {
params = "<username> <password>", params = "<username> <password>",
description = "Login as a user to run commands", description = "Login as a user to run commands",
func = function (from, args) func = function(user, args)
if args == "" then if args == "" then
mt_irc.say(from, "You need a username and password") return false, "You need a username and password."
return
end end
local found, _, username, password = args:find("^([^%s]+)%s([^%s]+)$") local playerName, password = args:match("^(%S+)%s(%S+)$")
if not found then if not playerName then
username = args return false, "Player name and password required."
password = ""
end end
if minetest.auth_table[username] and local inChannel = false
minetest.auth_table[username].password == minetest.get_password_hash(username, password) then local users = irc.conn.channels[irc.config.channel].users
minetest.debug("User "..from.." from IRC logs in as "..username) for cnick, cuser in pairs(users) do
irc_users[from] = username if user.nick == cnick then
mt_irc.say(from, "You are now logged in as "..username) inChannel = true
break
end
end
if not inChannel then
return false, "You need to be in the server's channel to login."
end
if minetest.auth_table[playerName] and
minetest.auth_table[playerName].password ==
minetest.get_password_hash(playerName, password) then
minetest.log("action", "User "..user.nick
.." from IRC logs in as "..playerName)
irc_users[user.nick] = playerName
return true, "You are now logged in as "..playerName
else else
minetest.debug("User "..from.." from IRC attempted log in as "..username.." unsuccessfully") minetest.log("action", user.nick.."@IRC attempted to log in as "
mt_irc.say(from, "Incorrect password or player does not exist") ..playerName.." unsuccessfully")
return false, "Incorrect password or player does not exist."
end end
end}) end
})
mt_irc.register_bot_command("logout", { irc:register_bot_command("logout", {
description = "Logout", description = "Logout",
func = function (from, args) func = function (user, args)
if irc_users[from] then if irc_users[user.nick] then
minetest.debug("User "..from.." from IRC logs out of "..irc_users[from]) minetest.log("action", user.nick.."@IRC logs out from "
irc_users[from] = nil ..irc_users[user.nick])
mt_irc.say(from, "You are now logged off") irc_users[user.nick] = nil
return true, "You are now logged off."
else else
mt_irc.say(from, "You are not logged in") return false, "You are not logged in."
end end
end}) end,
})
mt_irc.register_bot_command("cmd", { irc:register_bot_command("cmd", {
params = "<command>", params = "<command>",
description = "Run a command on the server", description = "Run a command on the server",
func = function (from, args) func = function (user, args)
if args == "" then if args == "" then
mt_irc.say(from, "You need a command") return false, "You need a command."
return
end end
if not irc_users[from] then if not irc_users[user.nick] then
mt_irc.say(from, "You are not loged in") return false, "You are not logged in."
return
end end
local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$") local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$")
if not found then if not found then
@ -79,31 +99,37 @@ mt_irc.register_bot_command("cmd", {
end end
local command = minetest.chatcommands[commandname] local command = minetest.chatcommands[commandname]
if not command then if not command then
mt_irc.say(from, "Not a valid command") return false, "Not a valid command."
return
end end
if minetest.check_player_privs(irc_users[from], command.privs) then if not minetest.check_player_privs(irc_users[user.nick], command.privs) then
minetest.debug("User "..from.." from IRC runs "..args.." as "..irc_users[from]) return false, "Your privileges are insufficient."
command.func(irc_users[from], (params or ""))
mt_irc.say(from, "Command run successfuly")
end end
end}) minetest.log("action", user.nick.."@IRC runs "
..args.." as "..irc_users[user.nick])
return command.func(irc_users[user.nick], (params or ""))
end
})
mt_irc.register_bot_command("say", { irc:register_bot_command("say", {
params = "message", params = "message",
description = "Say something", description = "Say something",
func = function (from, args) func = function (user, args)
if args == "" then if args == "" then
mt_irc.say(from, "You need a message") return false, "You need a message."
return
end end
if not irc_users[from] then if not irc_users[user.nick] then
mt_irc.say(from, "You are not loged in") return false, "You are not logged in."
return
end end
if minetest.check_player_privs(irc_users[from], {shout=true}) then if not minetest.check_player_privs(irc_users[user.nick], {shout=true}) then
minetest.debug("User "..from.." from IRC says "..args.." as "..irc_users[from]) minetest.log("action", ("%s@IRC tried to say %q as %s"
minetest.chat_send_all("<"..irc_users[from].."@IRC> "..args) .." without the shout privilege.")
mt_irc.say(from, "Message sent successfuly") :format(user.nick, args, irc_users[user.nick]))
return false, "You can not shout."
end end
end}) minetest.log("action", ("%s@IRC says %q as %s.")
:format(user.nick, args, irc_users[user.nick]))
minetest.chat_send_all("<"..irc_users[user.nick].."@IRC> "..args)
return true, "Message sent successfuly."
end
})