irc_commands/init.lua

95 lines
2.8 KiB
Lua
Raw Normal View History

2013-03-26 05:54:29 +01:00
irc_users = {}
local old_chat_send_player = minetest.chat_send_player
minetest.chat_send_player = function(name, message)
for nick, user in pairs(irc_users) do
if name == user then
mt_irc.say(nick, message)
end
end
return old_chat_send_player(name, message)
end
2013-03-26 05:54:29 +01:00
mt_irc.register_bot_command("login", {
params = "<username> <password>",
description = "Login as a user to run commands",
func = function (from, args)
2013-03-28 03:27:15 +01:00
if args == "" then
2013-03-26 05:54:29 +01:00
mt_irc.say(from, "You need a username and password")
return
end
local found, _, username, password = args:find("^([^%s]+)%s([^%s]+)$")
if not found then
username = args
2013-03-28 03:34:26 +01:00
password = ""
2013-03-26 05:54:29 +01:00
end
if minetest.auth_table[username] and
2013-03-28 03:34:26 +01:00
minetest.auth_table[username].password == minetest.get_password_hash(username, password) then
minetest.debug("User "..from.." from IRC logs in as "..username)
2013-03-26 05:54:29 +01:00
irc_users[from] = username
mt_irc.say(from, "You are now logged in as "..username)
else
2013-03-28 03:34:26 +01:00
minetest.debug("User "..from.." from IRC attempted log in as "..username.." unsuccessfully")
2013-03-26 05:54:29 +01:00
mt_irc.say(from, "Incorrect password or player does not exist")
end
end})
mt_irc.register_bot_command("logout", {
description = "Logout",
func = function (from, args)
if irc_users[from] then
2013-03-28 03:34:26 +01:00
minetest.debug("User "..from.." from IRC logs out of "..irc_users[from])
irc_users[from] = nil
mt_irc.say(from, "You are now logged off")
else
mt_irc.say(from, "You are not logged in")
end
2013-03-26 05:54:29 +01:00
end})
2013-03-28 03:20:00 +01:00
mt_irc.register_bot_command("cmd", {
2013-03-26 05:54:29 +01:00
params = "<command>",
2013-03-28 03:27:15 +01:00
description = "Run a command on the server",
2013-03-26 05:54:29 +01:00
func = function (from, args)
if args == "" then
mt_irc.say(from, "You need a command")
return
end
if not irc_users[from] then
mt_irc.say(from, "You are not loged in")
return
end
local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$")
if not found then
commandname = args
end
local command = minetest.chatcommands[commandname]
if not command then
mt_irc.say(from, "Not a valid command")
return
end
if minetest.check_player_privs(irc_users[from], command.privs) then
2013-03-28 03:34:26 +01:00
minetest.debug("User "..from.." from IRC runs "..args.." as "..irc_users[from])
2013-03-26 05:54:29 +01:00
command.func(irc_users[from], (params or ""))
mt_irc.say(from, "Command run successfuly")
end
end})
2013-03-28 03:22:28 +01:00
mt_irc.register_bot_command("say", {
params = "message",
description = "Say something",
func = function (from, args)
if args == "" then
mt_irc.say(from, "You need a message")
return
end
if not irc_users[from] then
mt_irc.say(from, "You are not loged in")
return
end
if minetest.check_player_privs(irc_users[from], {shout=true}) then
2013-03-28 03:34:26 +01:00
minetest.debug("User "..from.." from IRC says "..args.." as "..irc_users[from])
2013-03-28 03:22:28 +01:00
minetest.chat_send_all("<"..irc_users[from].."@IRC> "..args)
mt_irc.say(from, "Message sent successfuly")
end
end})