diff options
Diffstat (limited to '')
-rw-r--r-- | commands.lua | 396 |
1 files changed, 396 insertions, 0 deletions
diff --git a/commands.lua b/commands.lua new file mode 100644 index 0000000..dfad669 --- /dev/null +++ b/commands.lua @@ -0,0 +1,396 @@ +--[[ + +Commands file for HaxServ. + +Written by: Test_User <hax@andrewyu.org> + +This is free and unencumbered software released into the public +domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +]] + +local rickroll = { + "We're no strangers to love", + "You know the rules, and so do I", + "A full commitment is what I'm thinking of", + + "You wouldn't get this from any other guy", + + "I just wanna tell you how I'm feeling", + "Gotta make you, understand", + + "Never gonna give you up", + "Never gonna let you down", + "Never gonna run around and desert you", + + "Never gonna make you cry", + "Never gonna say goodbye", + "Never gonna tell a lie, and hurt you", + + "We've known each other, for so long", + "Your heart's been aching but, you're too shy to say it", + "Inside we both know what's been going on", + "We know the game and we're gonna play it", + + "And if you ask me how I'm feeling", + "Don't tell me you're too blind to see", + + "Never gonna give you up", + "Never gonna let you down", + "Never gonna run around, and desert you", + + "Never gonna make you cry", + "Never gonna say goodbye", + "never gonna tell a lie, and hurt you", + + "Never gonna give you up", + "Never gonna let you down", + "Never gonna run around, and desert you", + + "Never gonna make you cry", + "Never gonna say goodbye", + "never gonna tell a lie, and hurt you", + + "Give you up", + "Never gonna give, never gonna give", + "Give you up", + "Never gonna give, never gonna give", + + "We've known each other, for so long", + "Your heart's been aching but, you're too shy to say it", + "Inside we both know what's been going on", + "We know the game and we're gonna play it", + + "I just wanna tell you how I'm feelin", + "Gotta make you, understand", + "Never gonna give you up", + "Never gonna let you down", + "Never gonna run around, and desert you", + "Never gonna make you cry", + "Never gonna say goodbye", + "never gonna tell a lie, and hurt you", + "Never gonna give you up", + "Never gonna let you down", + "Never gonna run around, and desert you", + "Never gonna make you cry", + "Never gonna say goodbye", + "never gonna tell a lie, and hurt you", +} + + +commands = { + ["SANICK"] = { + func = function(con, user, cmd, args, resp) + if #args < 2 then + con:send(":1HC000000 NOTICE "..resp.." :Not enough args.\n") + else + con:send("SANICK "..args[1].." :"..table.concat(args, " ", 2).."\n") + end + end, + privs = {"Admin"}, + args = "<target> <new nick>", + }, + + ["RELOAD"] = { + func = function(con, user, cmd, args, resp) + if #args == 0 then + config_file:seek("set", 0) + local success, value_or_err = pcall(json.decode, config_file:read("*a")) + if success then + config = value_or_err + con:send(":1HC000000 NOTICE "..resp.." :Successfully reloaded config.json\n") + else + con:send(":1HC000000 NOTICE "..resp.." :Unable to reload config.json, check /dev/stdout for details.\n") + print("config.json") + print(value_or_err) + end + + for file, _ in pairs(config.files) do + local success, err = pcall(dofile, path..file) + if success then + con:send(":1HC000000 NOTICE "..resp.." :Successfully reloaded "..file.."\n") + else + con:send(":1HC000000 NOTICE "..resp.." :Unable to reload "..file..", check /dev/stdout for details.\n") + print(file) + print(err) + end + end + else + local file = args[1]..".lua" + if config.files[file] then + local success, err = pcall(dofile, path..file) + if success then + con:send(":1HC000000 NOTICE "..resp.." :Successfully reloaded "..file.."\n") + else + con:send(":1HC000000 NOTICE "..resp.." :Unable to reload "..file..", check /dev/stdout for details.\n") + print(file) + print(err) + end + elseif args[1] == "config" then + config_file:seek("set", 0) + local success, value_or_err = pcall(json.decode, config_file:read("*a")) + if success then + config = value_or_err + con:send(":1HC000000 NOTICE "..resp.." :Successfully reloaded config.json\n") + else + con:send(":1HC000000 NOTICE "..resp.." :Unable to reload config.json, check /dev/stdout for details.\n") + print("CoupServConfig.json") + print(value_or_err) + end + else + con:send(":1HC000000 NOTICE "..resp.." :Invalid section.\n") + end + end + end, + privs = {"Admin"}, + args = "[<section>]", + }, + + ["NGGYU"] = { + func = function(con, user, cmd, args, resp) + if #args == 0 then + for _, line in pairs(rickroll) do + con:send(":1HC000000 PRIVMSG "..resp.." :"..line.."\n") + end + else + for _, line in pairs(rickroll) do + con:send(":1HC000000 PRIVMSG "..args[1].." :"..line.."\n") + end + end + end, + privs = {"Admin"}, + args = "[<target>]", + }, + + ["RECONNECT"] = { + func = function(con, user, cmd, args, resp) + return true + end, + privs = {"Admin"}, + }, + + [":"] = { + func = function(con, user, cmd, args, resp) + con:send(table.concat(args, " ").."\n") + end, + privs = {"Admin"}, + args = "<raw IRC message>", + }, + + ["HELP"] = { + func = function(con, user, cmd, args, resp) + for command, tbl in pairs(commands) do + if has_permission(userlist[user], tbl.privs) then + if tbl.args then + con:send(":1HC000000 NOTICE "..resp.." :"..command.." "..tbl.args.."\n") + else + con:send(":1HC000000 NOTICE "..resp.." :"..command.."\n") + end + end + end + end, + }, + + ["SHUTDOWN"] = { + func = function(con, user, cmd, args, resp) + local crash_me = nil + crash_me() + end, + privs = {"Owner"}, + }, + + ["SPAM"] = { + func = function(con, user, cmd, args, resp) + if #args < 3 then + con:send(":1HC000000 NOTICE "..resp.." :Not enough args.\n") + elseif tonumber(args[2]) == nil then + con:send(":1HC000000 NOTICE "..resp.." :"..args[2]..": Not a valid positive integer.\n") + elseif tonumber(args[2]) < 1 then + con:send(":1HC000000 NOTICE "..resp.." :"..args[2]..": Not a valid positive integer.\n") + elseif tonumber(args[2]) > 1000 then + con:send(":1HC000000 NOTICE "..resp.." :"..args[2]..": Too large of a number, max is 1000.\n") + else + local msg = ":1HC000000 PRIVMSG "..args[1].." :"..table.concat(args, " ", 3).."\n" + for i=1, tonumber(args[2]), 1 do + con:send(msg) + end + end + end, + privs = {"Admin"}, + args = "<target> <count> <message>", + }, + + ["OP"] = { + func = function(con, user, cmd, args, resp) + if resp:sub(1, 1) ~= "#" then + con:send(":1HC000000 NOTICE "..resp.." :This command must be executed within a channel.\n") + return + end + + if #args == 0 then + con:send(":1HC000000 MODE "..resp.." +o "..user.."\n") + else + con:send(":1HC000000 MODE "..resp.." +o "..args[1].."\n") + end + end, + privs = {"Admin"}, + args = "[<target>]", + }, + + ["GETUID"] = { + func = function(con, user, cmd, args, resp) + if #args == 0 then + con:send(":1HC000000 NOTICE "..resp.." :"..user.."\n") + else + local nick = table.concat(args, " ") + for uid, tbl in pairs(userlist) do + if tbl.nick == nick then + con:send(":1HC000000 NOTICE "..resp.." :"..uid.."\n") + return + end + end + con:send(":1HC000000 NOTICE "..resp.." :Nick not found.\n") + end + end, + args = "[<nick>]", + }, + + ["PRINT"] = { + func = function(con, user, cmd, args, resp) + if #args == 0 then + con:send(":1HC000000 NOTICE "..resp.." :Not enough args.\n") + else + local list + if args[1] == "userlist" then + list = userlist + elseif args[1] == "chanlist" then + list = chanlist + elseif args[1] == "servlist" then + list = servlist + else + con:send(":1HC000000 NOTICE "..resp.." :Unknown list.\n") + return + end + + for k, v in pairs(list) do + local msg = {} + for key, val in pairs(v) do + table.insert(msg, "["..(type(key) == "string" and ("%q"):format(key) or tostring(key)).."] = "..(type(val) == "string" and ("%q"):format(val) or tostring(val))) + end + print("["..(type(k) == "string" and ("%q"):format(k) or tostring(k)).."] = {"..table.concat(msg, ", ").."}") + end + end + end, + privs = {"Admin"}, + args = "<list>", + }, + + ["GETUSERINFO"] = { + func = function(con, user, cmd, args, resp) + if #args == 0 then + args[1] = source + end + + if userlist[args[1]] then + local msg = {} + for key, val in pairs(userlist[args[1]]) do + table.insert(msg, "["..(type(key) == "string" and ("%q"):format(key) or tostring(key)).."] = "..(type(val) == "string" and ("%q"):format(val) or tostring(val))) + end + con:send(":1HC000000 PRIVMSG "..resp.." :{"..table.concat(msg, ", ").."}\n") + else + con:send(":1HC000000 PRIVMSG "..resp.." :Nonexistant UID\n") + end + end, + privs = {"Admin"}, + args = "[<UID>]", + }, + + ["GETNICK"] = { + func = function(con, user, cmd, args, resp) + if userlist[args[1]] then + con:send(":1HC000000 NOTICE "..resp.." :"..userlist[args[1]].nick.."\n") + else + con:send(":1HC000000 NOTICE "..resp.." :Nonexistant UID\n") + end + end, + args = "[<UID>]", + }, + + ["JUPE"] = { + func = function(con, user, cmd, args, resp) + if #args == 0 then + con:send(":1HC000000 NOTICE "..resp.." :Not enough args.\n") + else + for id, tbl in pairs(servlist) do + if tbl.address == args[1] then + con:send("RSQUIT "..args[1].." :"..table.concat(args, " ", 2).."\n") + con:send(":1HC SERVER "..args[1].." * 0 "..id.." :Juped.\n") + return + end + end + con:send(":1HC000000 NOTICE "..resp.." :Server not found.\n") + end + end, + privs = {"Admin"}, + args = "<server>", + }, + + ["ALLOW"] = { + func = function(con, user, cmd, args, resp) + if #args == 0 then + con:send(":1HC000000 NOTICE "..resp.." :Not enough args.\n") + else + for id, tbl in pairs(userlist) do + if tbl.nick == args[1] then + userlist[id].opertype = "Admin" + con:send(":1HC000000 NOTICE "..resp.." :"..args[1].." is now considered an oper.\n") + return + end + end + con:send(":1HC000000 NOTICE "..resp.." :Nick not found.\n") + end + end, + privs = {"Admin"}, + args = "<user>", + }, + + ["DENY"] = { + func = function(con, user, cmd, args, resp) + if #args == 0 then + con:send(":1HC000000 NOTICE "..resp.." :Not enough args.\n") + else + for id, tbl in pairs(userlist) do + if tbl.nick == args[1] then + userlist[id].opertype = nil + con:send(":1HC000000 MODE "..id.." -o\n") + con:send(":1HC000000 NOTICE "..resp.." :"..args[1].." is no longer an oper.\n") + return + end + end + con:send(":1HC000000 NOTICE "..resp.." :Nick not found.\n") + end + end, + privs = {"Admin"}, + args = "<user>", + }, +} |