mirror of
https://github.com/minetest-mods/irc_commands.git
synced 2025-01-09 15:20:19 +01:00
Use the reply API to reply in-channel
This commit is contained in:
parent
64e53cba45
commit
55ea96e88e
31
init.lua
31
init.lua
@ -1,15 +1,11 @@
|
|||||||
|
|
||||||
irc_users = {}
|
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
|
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, loggedInAs in pairs(irc_users) do
|
for nick, loggedInAs in pairs(irc_users) do
|
||||||
if name == loggedInAs and not minetest.get_player_by_name(name) then
|
if name == loggedInAs and not minetest.get_player_by_name(name) then
|
||||||
notify(nick, message)
|
mt_irc:say(nick, message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return old_chat_send_player(name, message)
|
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",
|
description = "Login as a user to run commands",
|
||||||
func = function(user, args)
|
func = function(user, args)
|
||||||
if args == "" then
|
if args == "" then
|
||||||
notify(user.nick, "You need a username and password")
|
mt_irc:reply("You need a username and password")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local found, _, playername, password = args:find("^([^%s]+)%s([^%s]+)$")
|
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
|
minetest.log("action", "User "..user.nick
|
||||||
.." from IRC logs in as "..playername)
|
.." from IRC logs in as "..playername)
|
||||||
irc_users[user.nick] = 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
|
else
|
||||||
minetest.log("action", user.nick.."@IRC attempted to log in as "
|
minetest.log("action", user.nick.."@IRC attempted to log in as "
|
||||||
..playername.." unsuccessfully")
|
..playername.." unsuccessfully")
|
||||||
notify(user.nick, "Incorrect password or player does not exist")
|
mt_irc:reply("Incorrect password or player does not exist")
|
||||||
end
|
end
|
||||||
end})
|
end})
|
||||||
|
|
||||||
@ -62,22 +58,23 @@ mt_irc:register_bot_command("logout", {
|
|||||||
minetest.log("action", user.nick.."@IRC logs out from "
|
minetest.log("action", user.nick.."@IRC logs out from "
|
||||||
..irc_users[user.nick])
|
..irc_users[user.nick])
|
||||||
irc_users[user.nick] = nil
|
irc_users[user.nick] = nil
|
||||||
notify(user.nick, "You are now logged off")
|
mt_irc:reply("You are now logged off")
|
||||||
else
|
else
|
||||||
notify(from, "You are not logged in")
|
mt_irc:reply("You are not logged in")
|
||||||
end
|
end
|
||||||
end})
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
mt_irc:register_bot_command("cmd", {
|
mt_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 (user, args)
|
func = function (user, args)
|
||||||
if args == "" then
|
if args == "" then
|
||||||
notify(user.nick, "You need a command")
|
mt_irc:reply("You need a command")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not irc_users[user.nick] then
|
if not irc_users[user.nick] then
|
||||||
notify(user.nick, "You are not logged in")
|
mt_irc:reply("You are not logged in")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$")
|
local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$")
|
||||||
@ -86,7 +83,7 @@ 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
|
||||||
notify(user.nick, "Not a valid command")
|
mt_irc:reply("Not a valid command")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if minetest.check_player_privs(irc_users[user.nick], command.privs) then
|
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",
|
description = "Say something",
|
||||||
func = function (user, args)
|
func = function (user, args)
|
||||||
if args == "" then
|
if args == "" then
|
||||||
notify(from, "You need a message")
|
mt_irc:reply("You need a message")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not irc_users[user.nick] then
|
if not irc_users[user.nick] then
|
||||||
notify(user.nick, "You are not logged in")
|
mt_irc:reply("You are not logged in")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if minetest.check_player_privs(irc_users[user.nick], {shout=true}) then
|
if minetest.check_player_privs(irc_users[user.nick], {shout=true}) then
|
||||||
minetest.log("action", user.nick.."@IRC says "
|
minetest.log("action", user.nick.."@IRC says "
|
||||||
..args.." as "..irc_users[user.nick])
|
..args.." as "..irc_users[user.nick])
|
||||||
minetest.chat_send_all("<"..irc_users[user.nick].."@IRC> "..args)
|
minetest.chat_send_all("<"..irc_users[user.nick].."@IRC> "..args)
|
||||||
notify(user.nick, "Message sent successfuly")
|
mt_irc:reply("Message sent successfuly")
|
||||||
end
|
end
|
||||||
end})
|
end})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user