From f9bb6824f34efa7e9c1ae97f8b890d3d7ffaa392 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Sat, 21 May 2022 01:21:23 +0400 Subject: [PATCH] Ain't afraid of no bed --- libraries/classes/command-handler.lua | 116 +++--- libraries/classes/command.lua | 2 +- libraries/classes/plugin.lua | 23 ++ libraries/classes/server-handler.lua | 4 +- libraries/import.lua | 2 +- libraries/purify.lua | 2 + libraries/table-utils.lua | 26 +- plugins/cron/help.lua | 50 +++ plugins/cron/init.lua | 75 +--- plugins/debug/help.lua | 6 + plugins/debug/init.lua | 5 +- plugins/esolang/init.lua | 194 +++++---- plugins/help/help.lua | 11 + plugins/help/init.lua | 125 ++---- plugins/meta/init.lua | 423 +++++++++----------- plugins/plugins/help.lua | 32 ++ plugins/plugins/init.lua | 139 +++---- plugins/reactions/help.lua | 42 ++ plugins/reactions/init.lua | 547 ++++++++++++-------------- plugins/roledefaults/help.lua | 5 + plugins/roledefaults/init.lua | 22 +- plugins/security/help.lua | 46 +++ plugins/security/init.lua | 46 +-- plugins/tools/help.lua | 37 ++ plugins/tools/init.lua | 225 +++++------ 25 files changed, 1078 insertions(+), 1127 deletions(-) create mode 100644 plugins/cron/help.lua create mode 100644 plugins/debug/help.lua create mode 100644 plugins/help/help.lua create mode 100644 plugins/plugins/help.lua create mode 100644 plugins/reactions/help.lua create mode 100644 plugins/roledefaults/help.lua create mode 100644 plugins/security/help.lua create mode 100644 plugins/tools/help.lua diff --git a/libraries/classes/command-handler.lua b/libraries/classes/command-handler.lua index 1f1575b..6ce87ca 100644 --- a/libraries/classes/command-handler.lua +++ b/libraries/classes/command-handler.lua @@ -10,106 +10,94 @@ local table_utils = import("table-utils") local purify = import("purify") function command_handler:__init(parent_server) self.server_handler = assert(parent_server,"parent server handler not provided") - self.command_pool = {} + self.pool = {} self.prefixes = {} - self.command_meta = { + self.meta = { plugins = {}, categories = {} } end function command_handler:add_prefix(prefix) - local purified_prefix = purify.purify_escapes(prefix) - self.prefixes[purified_prefix] = purified_prefix + self.prefixes[prefix] = purify.purify_escapes(prefix) return true end function command_handler:remove_prefix(prefix) - local purified_prefix = purify.purify_escapes(prefix) - if self.prefixes[purified_prefix] or table_utils.count(self.prefixes) <= 1 then - self.prefix[purified_prefix] = nil + local prefix = purify_escapes(prefix) + if self.prefixes[prefix] and table_utils.count(self.prefixes) > 1 then + self.prefixes[prefix] = nil return true - else - return false, ( - (self.prefixes[purified_prefix] and "No such prefix") or - "Cannot remove the last remaining prefix" - ) end + if not self.prefixes[prefix] then + return false, "Prefix not found" + end + return false, "Cannot remove last remaining prefix!" end function command_handler:get_prefixes() return table_utils.deepcopy(self.prefixes) end function command_handler:add_command(command) assert(type(command) == "table","command object expected") - local purified_name = purify.purify_escapes(command.name) - self.command_pool[purified_name] = command - if not self.command_meta.plugins[command.parent.name] then - self.command_meta.plugins[command.parent.name] = {} + if self.pool[command.name] then + return false, "Already have a command with the same name" end - if not self.command_meta.categories[command.options.category] then - self.command_meta.categories[command.options.category] = {} + self.pool[command.name] = command + if not self.meta.plugins[command.parent.name] then + self.meta.plugins[command.parent.name] = {} end - table.insert(self.command_meta.categories[command.options.category],command.name) - table.insert(self.command_meta.plugins[command.parent.name],command.name) + self.meta.plugins[command.parent.name][command.name] = command.name + if not self.meta.categories[command.category] then + self.meta.categories[command.category] = {} + end + self.meta.categories[command.category][command.name] = command.name return command end function command_handler:remove_command(command) assert(type(command) == "table","command object expected") - local purified_name = purify.purify_escapes(command.name) - if self.command_pool[purified_name] then - local command = self.command_pool[purified_name] - --not exactly optimal, but lists are lists. can't do much about them. - table_utils.remove_value(self.command_meta.plugins[command.parent.name],command.name) - if #self.command_meta.plugins[command.parent.name] == 0 then - self.command_meta.plugins[command.parent.name] = nil - end - table_utils.remove_value(self.command_meta.categories[command.options.category],command.name) - if #self.command_meta.categories[command.options.category] == 0 then - self.command_meta.categories[command.options.category] = nil - end - self.command_pool[purified_name] = nil - return true - else + if not self.pool[command.name] then return false end + self.pool[command.name] = nil + self.meta.categories[command.category][command.name] = nil + self.meta.plugins[command.parent.name][command.name] = nil end function command_handler:get_command(name) - local purified_name = purify.purify_escapes(assert(type(name) == "string") and name) - if self.command_pool[purified_name] then - return self.command_pool[purified_name] - else - return false - end + return self.pool[name] end function command_handler:get_commands(name) local list = {} - for k,v in pairs(self.command_pool) do + for k,v in pairs(self.pool) do table.insert(list,k) end return list end -function command_handler:get_commands_metadata() - return table_utils.deepcopy(self.command_meta) +function command_handler:get_metadata() + local plugins,categories = {},{} + for k,v in pairs(self.meta.plugins) do + plugins[k] = table_utils.listcopy(v) + end + for k,v in pairs(self.meta.categories) do + categories[k] = table_utils.listcopy(v) + end + return { + plugins = plugins, + categories = categories + } end function command_handler:handle(message) - for name,command in pairs(self.command_pool) do - if command.options.regex then - if message.content:match(command.options.regex) then - command:exec(message) - return - end - else - if command.options.prefix then - for _,prefix in pairs(self.prefixes) do - if message.content:match("^"..prefix..name.."$") or message.content:match("^"..prefix..name.."%s") then - command:exec(message) - return - end - end - else - if message.content:match("^"..name.."$") or message.content:match("^"..name.."%s") then - command:exec(message) - return - end - end + local content = message.content + local prefix = "" + local command + for k,v in pairs(self.prefixes) do + if content:match("^"..v) then + prefix = v + end + end + command = content:sub(prefix:len()+1,-1):match("^[%-_%w]+") + if self.pool[command] then + if (prefix == "") and self.pool[command].options.prefix == false then + self.pool[command]:exec(message) + elseif (prefix ~= "") and self.pool[command].options.prefix == true then + self.pool[command]:exec(message) end end end diff --git a/libraries/classes/command.lua b/libraries/classes/command.lua index 13902f5..9cd0771 100644 --- a/libraries/classes/command.lua +++ b/libraries/classes/command.lua @@ -11,10 +11,10 @@ function command:__init(name,callback) self.rules = acl() self.name = name self.timer = discordia.Date():toMilliseconds() + self.category = "None" self.options = { allow_bots = false, --allow bots to execute the command typing_decorator = false, --set if the bot should be "typing" while the command executes - category = "None", --set category for the command prefix = true, --if true check for prefix at the start. if not, don't check for prefix no_parsing = false, --check if you want to disable the message argument parsing process timeout = 1000, --set the timeout for a command diff --git a/libraries/classes/plugin.lua b/libraries/classes/plugin.lua index fc6f760..2acbfed 100644 --- a/libraries/classes/plugin.lua +++ b/libraries/classes/plugin.lua @@ -56,4 +56,27 @@ function plugin:remove_command(command_object) self.command_handler:remove_command(command_object) end end + +function plugin:load_helpdb(path) + local helpdb_file = io.open(path,r) + local helpdb,err = load(helpdb_file:read("*a") or "","helpdb "..path,nil, + setmetatable({ + require = require, + import = import + },{ + __index = _G + }) + ) + helpdb_file:close() + if not helpdb then + error(err) + end + helpdb = helpdb() + self:for_all_commands(function(command) + if helpdb[command.name] then + command:set_help(helpdb[command.name]) + end + end) +end + return plugin diff --git a/libraries/classes/server-handler.lua b/libraries/classes/server-handler.lua index 6441a3d..0859f01 100644 --- a/libraries/classes/server-handler.lua +++ b/libraries/classes/server-handler.lua @@ -38,8 +38,8 @@ function server_handler:__init(client,guild,options) self.autosave = options.path or true self.autosave_frequency = options.autosave_frequency or 10 self.plugin_search_paths = options.plugin_search_paths or {"./plugins/"} - self.default_plugins = options.default_plugins or {"test"} - self.default_prefixes = options.default_prefixes or {"&","<@!"..self.client.user.id..">"} + self.default_plugins = options.default_plugins or {"plugins"} + self.default_prefixes = options.default_prefixes or {"&","<@"..self.client.user.id.."> "} self.config = {} self.config_path = self.config_path:gsub("%%id",self.id) self:load_config() diff --git a/libraries/import.lua b/libraries/import.lua index 3febeed..f7ba240 100644 --- a/libraries/import.lua +++ b/libraries/import.lua @@ -28,7 +28,7 @@ return function(reqfunc) import = import, },{__index = _G})) if err then - error("[import: "..filname.."] "..tostring(err)) + error("[import: "..filename.."] "..tostring(err)) end return f() end diff --git a/libraries/purify.lua b/libraries/purify.lua index d77dd38..dee1024 100644 --- a/libraries/purify.lua +++ b/libraries/purify.lua @@ -21,6 +21,8 @@ purify.purify_pings = function(msg,input) end text = text:gsub("<@(%D*)"..id..">",substitution) end + text = text:gsub("@everyone","") + text = text:gsub("@here","") return text end diff --git a/libraries/table-utils.lua b/libraries/table-utils.lua index 0bfd817..39cc7b0 100644 --- a/libraries/table-utils.lua +++ b/libraries/table-utils.lua @@ -17,22 +17,30 @@ end utilities.slice = function(list,start,list_end) local output = {} for I = (start or 1),(list_end or #table) do - table.insert(output,list[I]) + table.insert(output,list[I]) end return output end utilities.shallowcopy = function(orig) local copy = {} for k,v in pairs(orig) do - copy[k] = v + copy[k] = v end return copy end + +utilities.listcopy = function(orig) + local list = {} + for k,v in pairs(orig) do + table.insert(list,v) + end + return list +end --overwrite the original table's properties with new properties utilities.overwrite = function(original,overwrite) local new = utilities.shallowcopy(original) for k,v in pairs(overwrite) do - new[k] = v + new[k] = v end return new end @@ -42,13 +50,13 @@ utilities.merge = function(...) local args = {...} local new = {} for k,v in pairs(args) do - if type(v) == "table" then - for k2,v2 in pairs(v) do - table.insert(new,v2) + if type(v) == "table" then + for k2,v2 in pairs(v) do + table.insert(new,v2) + end + else + table.insert(new,v) end - else - table.insert(new,v) - end end return new end diff --git a/plugins/cron/help.lua b/plugins/cron/help.lua new file mode 100644 index 0000000..ab76649 --- /dev/null +++ b/plugins/cron/help.lua @@ -0,0 +1,50 @@ +return { + ["event"] = {embed={ + title = "Add a cron event", + description = "https://github.com/512mb-org/512mb.org-bot/wiki/Events-and-cronjobs", + fields = { + {name = "Usage:",value = "event ..."}, + {name = "Perms:",value = "administrator"}, + } + }}, + ["delay"] = {embed={ + title = "Delay a command", + description = "Delay fromat is , where unit is one of the follwing:\n\"h\" - hour,\n\"m\" - minute,\n\"d\" - day,\n\"w\" - week,\n\"y\" - year", + fields = { + {name = "Usage:",value = "delay "}, + {name = "Perms:",value = "any"}, + } + }}, + ["events"] = {embed={ + title = "View your running events", + description = "nuff said.", + fields = { + {name = "Usage:",value = "events "}, + {name = "Perms:",value = "any"}, + } + }}, + ["user-events"] = {embed={ + title = "View running events of a certain user", + description = "nuff said.", + fields = { + {name = "Usage:",value = "user-events "}, + {name = "Perms:",value = "administrator"}, + } + }}, + ["remove-event"] = {embed={ + title = "Remove an event", + description = "nuff said.", + fields = { + {name = "Usage:",value = "remove-event "}, + {name = "Perms:",value = "any"}, + } + }}, + ["remove-user-event"] = {embed={ + title = "Remove an event from a user", + description = "nuff said.", + fields = { + {name = "Usage:",value = "remove-user-event "}, + {name = "Perms:",value = "administrator"}, + } + }}, +} diff --git a/plugins/cron/init.lua b/plugins/cron/init.lua index 46e478e..add3d19 100644 --- a/plugins/cron/init.lua +++ b/plugins/cron/init.lua @@ -195,20 +195,8 @@ for _,evtype in pairs(config.events.event) do end local event = command("event",{ - help = {embed={ - title = "Add a cron event", - description = "https://github.com/512mb-org/512mb.org-bot/wiki/Events-and-cronjobs", - fields = { - {name = "Usage:",value = "event ..."}, - {name = "Perms:",value = "administrator"}, - } - }}, - perms = { - "administrator" - }, - args = { - "string" - }, + perms = {"administrator"}, + args = {"string"}, exec = function(msg,args,opts) return create_event(msg,table.concat(args," ")) end @@ -216,14 +204,6 @@ local event = command("event",{ plugin:add_command(event) local delay = command("delay",{ - help = {embed={ - title = "Delay a command", - description = "Delay fromat is , where unit is one of the follwing:\n\"h\" - hour,\n\"m\" - minute,\n\"d\" - day,\n\"w\" - week,\n\"y\" - year", - fields = { - {name = "Usage:",value = "delay "}, - {name = "Perms:",value = "any"}, - } - }}, args = { "string", "string" @@ -238,14 +218,6 @@ local delay = command("delay",{ plugin:add_command(delay) local events_comm = command("events",{ - help = {embed={ - title = "View your running events", - description = "nuff said.", - fields = { - {name = "Usage:",value = "events "}, - {name = "Perms:",value = "any"}, - } - }}, exec = function(msg,args,opts) args[1] = tonumber(args[1]) or 1 local upto = args[1]*5 @@ -269,20 +241,8 @@ local events_comm = command("events",{ plugin:add_command(events_comm) local user_events_comm = command("user-events",{ - help = {embed={ - title = "View running events of a certain user", - description = "nuff said.", - fields = { - {name = "Usage:",value = "user-events "}, - {name = "Perms:",value = "administrator"}, - } - }}, - args = { - "member" - }, - perms = { - "administrator" - }, + args = {"member"}, + perms = {"administrator"}, exec = function(msg,args,opts) args[2] = tonumber(args[2]) or 1 local upto = args[2]*5 @@ -306,17 +266,7 @@ local user_events_comm = command("user-events",{ plugin:add_command(user_events_comm) local remove_event= command("remove-event",{ - help = {embed={ - title = "Remove an event", - description = "nuff said.", - fields = { - {name = "Usage:",value = "remove-event "}, - {name = "Perms:",value = "any"}, - } - }}, - args = { - "string" - }, + args = {"string"}, exec = function(msg,args,opts) return remove_user_event(msg.author.id,args[1]) end @@ -324,14 +274,6 @@ local remove_event= command("remove-event",{ plugin:add_command(remove_event) local remove_user_event_c = command("remove-user-event",{ - help = {embed={ - title = "Remove an event from a user", - description = "nuff said.", - fields = { - {name = "Usage:",value = "remove-user-event "}, - {name = "Perms:",value = "administrator"}, - } - }}, args = { "member", "string" @@ -360,10 +302,10 @@ timer:on("min",function() end) --load events file -local fhandler = io.open("./plugins/cron/events.lua","r") +local fhandler = io.open(plugin_path.."/events.lua","r") local data = fhandler:read("*a") fhandler:close() -local eventfunc = load(data,"event loader: ./plugins/cron/events.lua",nil,setmetatable({ +local eventfunc = load(data,"event loader: "..plugin_path.."/events.lua",nil,setmetatable({ id = id, client = client, exec = exec, @@ -371,6 +313,7 @@ local eventfunc = load(data,"event loader: ./plugins/cron/events.lua",nil,setmet config = config },{__index = _G})) eventfunc() - timer:start(true) + +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/debug/help.lua b/plugins/debug/help.lua new file mode 100644 index 0000000..e241776 --- /dev/null +++ b/plugins/debug/help.lua @@ -0,0 +1,6 @@ +return { + ["save"] = "Force-save config data", + ["error"] = "Force error", + ["permerror"] = "Force permission error", + ["return_error"] = "Force a return value error", +} diff --git a/plugins/debug/init.lua b/plugins/debug/init.lua index c5835a3..4ee065e 100644 --- a/plugins/debug/init.lua +++ b/plugins/debug/init.lua @@ -1,21 +1,18 @@ local plugin = import("classes.plugin")("debug") local command = import("classes.command") local save = command("save",{ - help = "Force-save config data", exec = function() server:save_config() end }) plugin:add_command(save) local err = command("error",{ - help = "Force error", exec = function() error("Errored successfully!") end }) plugin:add_command(err) local perm_error = command("permerror",{ - help = "Force permission error", users = { ["245973168257368076"] = -1 }, @@ -25,11 +22,11 @@ local perm_error = command("permerror",{ }) plugin:add_command(perm_error) local return_error = command("return_error",{ - help = "Force a return value error", exec = function(msg) msg:reply("nono :)") return false end }) plugin:add_command(return_error) +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/esolang/init.lua b/plugins/esolang/init.lua index 04aa629..8af58d8 100644 --- a/plugins/esolang/init.lua +++ b/plugins/esolang/init.lua @@ -4,112 +4,108 @@ local plugin_class = import("classes.plugin") local command = import("classes.command") local plugin = plugin_class() local settings = { - tapesize = 30000, - cellsize = 1, - debug = true, - limit = 500000 + tapesize = 30000, + cellsize = 1, + debug = true, + limit = 500000 } c_brainfuck = command("brainfuck",{ - args = { - "string" - }, - exec = function(msg,args,opts) - settings.load_extensions = {} - settings.path = "./lib/brainfuck/" - local instance = brainfuck.new(args[1],settings) - local result,opcount,err = instance:run(args[2] or "") - if result == "" then - result = "" - end - if not err then - if opts["o"] or opts["output-only"] then - msg:reply(tostring(result):gsub("@","\\@")) - else - msg:reply({ embed = { - title = "Result:", - color = discordia.Color.fromHex("#32cd32").value, - description = "```"..tostring(result):gsub("`","\\`").." ```", - footer = { - text = "Finished in "..opcount.." operations" - } - }}) + args = { + "string" + }, + exec = function(msg,args,opts) + settings.load_extensions = {} + settings.path = "./lib/brainfuck/" + local instance = brainfuck.new(args[1],settings) + local result,opcount,err = instance:run(args[2] or "") + if result == "" then + result = "" + end + if not err then + if opts["o"] or opts["output-only"] then + msg:reply(tostring(result):gsub("@","\\@")) + else + msg:reply({ embed = { + title = "Result:", + color = discordia.Color.fromHex("#32cd32").value, + description = "```"..tostring(result):gsub("`","\\`").." ```", + footer = { + text = "Finished in "..opcount.." operations" + } + }}) + end + else + msg:reply({ + embed = { + title = "Error:", + description = "```"..tostring(err).." ```", + color = discordia.Color.fromHex("#32cd32").value, + } + }) + end end - else - msg:reply({ - embed = { - title = "Error:", - description = "```"..tostring(err).." ```", - color = discordia.Color.fromHex("#32cd32").value, - } - }) - end - end }) plugin:add_command(c_brainfuck) c_befunge = command("befunge",{ - args = { - "string" - }, - exec = function(msg,args,opts) - local code = msg.content:match("```(.+)```") - if not code then - msg:reply("Invalid syntax") - return - end - local input = msg.content:match("```.+``` ?(.+)") or "" - local stdout = "" - local stderr = "" - befunge:init(code,{ - opcount = 10000, - handle_int_input = function() - local int = input:match("^%d+") - if not int then - return - end - input = input:gsub("^%d+","",1) - return tonumber(int) - end, - handle_input = function() - local char = input:sub(1,1) - if not char then - return - end - input = input:sub(2,-1) - return string.byte(char) - end, - handle_output = function(char) - stdout = stdout..char - end, - handle_warning = function(warn) - stderr = stderr.."[warning] "..warn.."\n" - end, - handle_error = function(error) - stderr = stderr.."[error] "..error.."\n" - befunge.interpreter_state = false + args = { + "string" + }, + exec = function(msg,args,opts) + local code = msg.content:match("```(.+)```") + if not code then + msg:reply("Invalid syntax") + return + end + local input = msg.content:match("```.+``` ?(.+)") or "" + local stdout = "" + local stderr = "" + befunge:init(code,{ + opcount = 10000, + handle_int_input = function() + local int = input:match("^%d+") + if not int then + return + end + input = input:gsub("^%d+","",1) + return tonumber(int) + end, + handle_input = function() + local char = input:sub(1,1) + if not char then + return + end + input = input:sub(2,-1) + return string.byte(char) + end, + handle_output = function(char) + stdout = stdout..char + end, + handle_warning = function(warn) + stderr = stderr.."[warning] "..warn.."\n" + end, + handle_error = function(error) + stderr = stderr.."[error] "..error.."\n" + befunge.interpreter_state = false + end + }) + local opcount = befunge:run() + if opts["o"] or opts["output-only"] then + msg:reply(tostring(stdout):gsub("@","\\@")) + else + msg:reply({embed = { + title = "Result: ", + color = discordia.Color.fromHex("#32cd32").value, + fields = { + {name = "out",value = "```"..stdout:gsub("`","\\`").." ```"}, + {name = "err",value = "```"..stderr.." ```"} + }, + footer = { + text = "Finished in "..opcount.." operations" + } + }}) + end end - }) - local opcount = befunge:run() - if opts["o"] or opts["output-only"] then - msg:reply(tostring(stdout):gsub("@","\\@")) - else - msg:reply({embed = { - title = "Result: ", - color = discordia.Color.fromHex("#32cd32").value, - fields = { - {name = "out",value = "```"..stdout:gsub("`","\\`").." ```"}, - {name = "err",value = "```"..stderr.." ```"} - }, - footer = { - text = "Finished in "..opcount.." operations" - } - }}) - end - end }) plugin:add_command(c_befunge) -local helpdb = import(plugin_path:sub(3,-1).."help") -plugin:for_all_commands(function(command) - command:set_help(helpdb[command.name]) -end) - +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/help/help.lua b/plugins/help/help.lua new file mode 100644 index 0000000..b99f90b --- /dev/null +++ b/plugins/help/help.lua @@ -0,0 +1,11 @@ +return { + ["help"] = {embed={ + title = "View help embeds for commands and plugins", + description = "To specify if it's a plugin or a command, simply add the option accordingly", + fields = { + {name = "Usage:",value = "help [ or --plugin ]"}, + {name = "Perms:",value = "any"}, + {name = "Options:",value = "--plugin"} + } + }} +} diff --git a/plugins/help/init.lua b/plugins/help/init.lua index b3cd82b..6fdcf7e 100644 --- a/plugins/help/init.lua +++ b/plugins/help/init.lua @@ -1,97 +1,48 @@ local pluginc = import("classes.plugin") local command = import("classes.command") local plugin = pluginc("help") -math.randomseed(os.time()+os.clock()) -local help_message -local function randomize_stuff() - local chance = math.random(1,100) - if chance < 10 then - help_message = [[ -This button here, builds Teleporters. This button, builds Dispensers. -And this little button makes them enemy sum-bitches wish they'd never been born! - ---the inspiration behind this bot's design ]] - elseif chance >= 10 and chance < 90 then - help_message = [[ -This plugin provides the help command, which can view help messages for plugins and commands - ]] - else - help_message = [[ -see the invisible -do the impossible -row row -fight da powah - ]] - end -end - -local function count(tab) - local count = 0 - for k,v in pairs(tab) do - count = count+1 - end - return count -end - -local function concatenate_keys(tab) - local key_list = {} - for k,v in pairs(tab) do - table.insert(key_list,k) - end - return "``"..table.concat(key_list,"``,\n``").."``" -end +local color = discordia.Color.fromHex local help_command = command("help",{ - help = {embed={ - title = "View help embeds for commands and plugins", - description = "To specify if it's a plugin or a command, simply add the option accordingly", - fields = { - {name = "Usage:",value = "help [ or --plugin ]"}, - {name = "Perms:",value = "any"}, - {name = "Options:",value = "--plugin"} - } - }}, exec = function(msg,args,opts) - randomize_stuff() - local embed = { - color = discordia.Color.fromHex("32b3bc").value - } - if args[1] then - if count(opts) < 1 then - if command_handler:get_command(args[1]) then - local command = command_handler:get_command(args[1]) - embed = command:get_help().embed - else - embed.description = "No such command" - end - elseif (opts["plugin"]) then - --[[ if plugin_data["plugins"] [args[1] ] then - embed.title = "Plugin ``"..args[1].."``:" - embed.description = plugin_data["plugins"] [args[1] ]["_help"] - embed.fields = {{ - name = "Commands:", - value ="``"..table.concat(plugin_data["plugins"] [args[1] ],"``,\n``").."``" - }} - else - embed.description = "No such plugin" - end - --]] - embed.title = "Not yet implemented" - embed.description = "Check again later" + local embed = { + color = color("32b3bc").value + } + if args[1] then + if not opts["plugin"] then + if command_handler:get_command(args[1]) then + local command = command_handler:get_command(args[1]) + embed = command:get_help().embed + else + embed.description = "No such command: "..args[1] + embed.color = color("990000").value + end + else + local meta = command_handler:get_metadata() + local comms = meta.plugins[args[1]] + if not comms then + embed.description = "Unable to find plugin: "..args[1] + embed.color = color("990000").value + else + embed.title = "Plugin ``"..args[1].."``" + embed.description = "``"..table.concat(comms,"``,``").."``" + end + end + else + local meta = command_handler:get_metadata() + embed.title = "512mb.org commands:" + embed.description = "use ``help `` to view help messages. (type ``help help`` for more info)" + embed.fields = {} + for name,category in pairs(meta.categories) do + table.insert(embed.fields,{ + name = name, + value = "``"..table.concat(category,"``,``").."``" + }) + end end - else - embed.title = "512mb.org commands:" - embed.description = "use ``help `` to view help messages. (type ``help help`` for more info)" - embed.fields = {} - for k,v in pairs(command_handler:get_commands_metadata().plugins) do - table.insert(embed.fields,{ - name = k, - value = "``"..table.concat(v,"``, ``").."``" - }) - end - end - msg:reply({embed = embed}) + msg:reply({embed = embed}) end, - }) +}) plugin:add_command(help_command) +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/meta/init.lua b/plugins/meta/init.lua index cff0447..b15809a 100644 --- a/plugins/meta/init.lua +++ b/plugins/meta/init.lua @@ -4,13 +4,14 @@ local last_message_arrived = discordia.Stopwatch() local unixToString = import("unixToString") local command = import("classes.command") local plugin = import("classes.plugin")("meta") +local purify = import("purify") if not config.aliases then - config.aliases = {} + config.aliases = {} end client:on("messageCreate",function(msg) - last_message_arrived:reset() - last_message_arrived:start() + last_message_arrived:reset() + last_message_arrived:start() end) local prefix @@ -21,185 +22,153 @@ for k,v in pairs(command_handler:get_prefixes()) do end local function add_alias(name,comm,prefix,description) - if (not aliases[name]) then - print("[ALIAS] Adding alias \""..name.."\" for \""..comm.."\"") - config.aliases[name] = {comm = comm,prefix = prefix} - aliases[name] = command(name,{ - help = "Alias for ``"..comm.."``", - usage = ((prefix and globals.prefix) or "")..name, - exec = function(msg,args2,opts) - print("[ALIAS] Triggerting alias "..tostring(comm).." with args \""..tostring(msg.content).."\"") - local str = msg.content:gsub("^%S+ ?","") - aftersub = comm:gsub("%.%.%.",str or "") - aftersub = aftersub:gsub("%$prefix",prefix or "&") - local status,args = require("air").parse(str) - for k,v in pairs(args) do - aftersub = aftersub:gsub("([^\\])%$"..k,"%1"..v) - end - command_handler:handle(fake_message(msg,{ - content = aftersub - })) - end, - options = { - prefix = prefix, - custom = true - } - }) - plugin:add_command(aliases[name]) - return true - else - return false - end + if (not aliases[name]) then + print("[ALIAS] Adding alias \""..name.."\" for \""..comm.."\"") + config.aliases[name] = {comm = comm,prefix = prefix} + aliases[name] = command(name,{ + help = "Alias for ``"..comm.."``", + usage = ((prefix and globals.prefix) or "")..name, + exec = function(msg,args2,opts) + print("[ALIAS] Triggerting alias "..tostring(comm).." with args \""..tostring(msg.content).."\"") + local str = msg.content:gsub("^%S+ ?","") + aftersub = comm:gsub("%.%.%.",str or "") + aftersub = aftersub:gsub("%$prefix",prefix or "&") + local status,args = require("air").parse(str) + for k,v in pairs(args) do + aftersub = aftersub:gsub("([^\\])%$"..k,"%1"..v) + end + command_handler:handle(fake_message(msg,{ + content = aftersub + })) + end, + options = { + prefix = prefix, + custom = true + } + }) + plugin:add_command(aliases[name]) + return true + else + return false + end end local function remove_alias(name) - if config.aliases[name] then - config.aliases[name] = nil - plugin:remove_command(aliases[name]) - aliases[name] = nil - return true - else - return false - end -end - -local function purify_strings(msg,input) - local text = input - while text:match("<@(%D*)(%d*)>") do - local obj,id = text:match("<@(%D*)(%d*)>") - local substitution = "" - if obj:match("!") then - local member = msg.guild:getMember(id) - if member then - substitution = "@"..member.name - end - elseif obj:match("&") then - local role = msg.guild:getRole(id) - if role then - substitution = "@"..role.name - end + if config.aliases[name] then + config.aliases[name] = nil + plugin:remove_command(aliases[name]) + aliases[name] = nil + return true + else + return false end - if substitution == "" then - substitution = "<\\@"..obj..id..">" - end - text = text:gsub("<@(%D*)"..id..">",substitution) - end - text = text:gsub("@everyone","") - text = text:gsub("@here","") - return text end for k,v in pairs(config.aliases) do - commdata = v - if type(v) == "string" then --legacy format conversion - commdata = {comm = v, prefix = false} - end - add_alias(k,commdata.comm,commdata.prefix) + commdata = v + if type(v) == "string" then --legacy format conversion + commdata = {comm = v, prefix = false} + end + add_alias(k,commdata.comm,commdata.prefix) end local prefix = command("prefix",{ - help = "Set prefix", - usage = "prefix [(add | remove | list (default)) []]", - users = { - [client.owner.id] = 1 - }, - roles = { - ["747042157185073182"] = 1 - }, - perms = { - "administrator" - }, - exec = function(msg,args,opts) - local function list_prefixes(msg) - local prefixes = "" - for k,v in pairs(command_handler:get_prefixes()) do - prefixes = prefixes..v.."\n" - end - msg:reply({embed = { - title = "Prefixes for this server", - description = prefixes - }}) - end - if args[1] then - if args[1] == "add" and args[2] then - command_handler:add_prefix(args[2]) - msg:reply("Added "..args[2].." as a prefix") - elseif args[1] == "remove" and args[2] then - local status,err = command_handler:remove_prefix(args[2]) - if status then - msg:reply("Removed the "..args[2].." prefix") - else - msg:reply(err) + help = "Set prefix", + usage = "prefix [(add | remove | list (default)) []]", + perms = { + "administrator" + }, + exec = function(msg,args,opts) + local function list_prefixes(msg) + local prefixes = "" + for k,v in pairs(command_handler:get_prefixes()) do + prefixes = prefixes..v.."\n" + end + msg:reply({embed = { + title = "Prefixes for this server", + description = prefixes + }}) + end + if args[1] then + if args[1] == "add" and args[2] then + command_handler:add_prefix(args[2]) + msg:reply("Added "..args[2].." as a prefix") + elseif args[1] == "remove" and args[2] then + local status,err = command_handler:remove_prefix(args[2]) + if status then + msg:reply("Removed the "..args[2].." prefix") + else + msg:reply(err) + end + elseif args[1] == "list" then + list_prefixes(msg) + else + msg:reply("Syntax error") + end + else + list_prefixes(msg) end - elseif args[1] == "list" then - list_prefixes(msg) - else - msg:reply("Syntax error") - end - else - list_prefixes(msg) end - end }) plugin:add_command(prefix) local c_alias = command("alias", { - args = { - "string","string" - }, - perms = { - "administrator" - }, - exec = function(msg,args,opts) - if add_alias(args[1],args[2],(opts["prefix"] or opts["p"]),opts["description"]) then - msg:reply("Bound ``"..args[1].."`` as an alias to ``"..args[2].."``") - else - msg:reply("``"..args[1].."`` is already bound") + args = { + "string","string" + }, + perms = { + "administrator" + }, + exec = function(msg,args,opts) + if add_alias(args[1],args[2],(opts["prefix"] or opts["p"]),opts["description"]) then + msg:reply("Bound ``"..args[1].."`` as an alias to ``"..args[2].."``") + else + msg:reply("``"..args[1].."`` is already bound") + end end - end }) plugin:add_command(c_alias) local c_unalias = command("unalias", { - args = { - "string" - }, - perms = { - "administrator" - }, - exec = function(msg,args,opts) - if remove_alias(args[1]) then - msg:reply("Removed the ``"..args[1].."`` alias") - else - msg:reply("No such alias") + args = { + "string" + }, + perms = { + "administrator" + }, + exec = function(msg,args,opts) + if remove_alias(args[1]) then + msg:reply("Removed the ``"..args[1].."`` alias") + else + msg:reply("No such alias") + end end - end }) plugin:add_command(c_unalias) local c_aliases = command("aliases", { - exec = function(msg,args,opts) + exec = function(msg,args,opts) msg:reply({embed = { - title = "Aliases for this server", - fields = (function() - local fields = {} - for k,v in pairs(config.aliases) do - table.insert(fields,{name = ((v["prefix"] and prefix) or "")..k,value = v["comm"]}) - end - return fields - end)() + title = "Aliases for this server", + fields = (function() + local fields = {} + for k,v in pairs(config.aliases) do + table.insert(fields,{name = ((v["prefix"] and prefix) or "")..k,value = v["comm"]}) + end + return fields + end)() }}) - end + end }) plugin:add_command(c_aliases) local c_ping = command("ping", { - exec = function(msg,args,opts) + exec = function(msg,args,opts) local before = msg:getDate() local reply = msg:reply("Pong!") if not reply then - log("ERROR","Couldn't send the ping reply for some reason") - return + log("ERROR","Couldn't send the ping reply for some reason") + return end local after = reply:getDate() local latency = (after:toMilliseconds() - before:toMilliseconds()) @@ -207,82 +176,82 @@ local c_ping = command("ping", { local uptime = discordia.Date():toSeconds() - server.uptime:toSeconds() local processing = (last_message_arrived:getTime():toMilliseconds()) msg:reply({embed = { - title = "Stats:", - fields = { - {name = "Latency",value = tostring(math.floor(latency)).."ms"}, - {name = "Processing time",value = tostring(math.floor(processing)).."ms"}, - {name = "Uptime",value = tostring(unixToString(uptime))} - } + title = "Stats:", + fields = { + {name = "Latency",value = tostring(math.floor(latency)).."ms"}, + {name = "Processing time",value = tostring(math.floor(processing)).."ms"}, + {name = "Uptime",value = tostring(unixToString(uptime))} + } }}) - end + end }) plugin:add_command(c_ping) local c_about = command("about", { - exec = function(msg,args,opts) + exec = function(msg,args,opts) local rand = math.random local author = client:getUser("245973168257368076") msg:reply({embed = { - title = "About 512mb.org bot", - thumbnail = { - url = client.user:getAvatarURL() - }, - color = discordia.Color.fromRGB(rand(50,200),rand(50,200),rand(50,200)).value, - description = "512mb.org is an open-source bot written in Lua. It is based on a beta rewrite version of the Suppa-Bot.", - fields = { - {name = "Source Code: ",value = "https://github.com/512mb-xyz/512mb.org-bot"}, - {name = "Author: ",value = author.tag}, - {name = "Invite: ",value = "Not available yet"} - }, - footer = { - text = "For any information regarding the bot, contact yessiest on 512mb.org discord." - } + title = "About 512mb.org bot", + thumbnail = { + url = client.user:getAvatarURL() + }, + color = discordia.Color.fromRGB(rand(50,200),rand(50,200),rand(50,200)).value, + description = "512mb.org is an open-source bot written in Lua. It is based on a beta rewrite version of the Suppa-Bot.", + fields = { + {name = "Source Code: ",value = "https://github.com/512mb-xyz/512mb.org-bot"}, + {name = "Author: ",value = author.tag}, + {name = "Invite: ",value = "Not available yet"} + }, + footer = { + text = "For any information regarding the bot, contact yessiest on 512mb.org discord." + } }}) - end + end }) plugin:add_command(c_about) local c_server = command("server", { - exec = function(msg,args,opts) + exec = function(msg,args,opts) msg:reply({embed = { - thumbnail = { - url = msg.guild.iconURL - }, - title = msg.guild.name, - description = msg.guild.description, - fields = { - {name = "Members",value = msg.guild.totalMemberCount}, - {name = "Owner",value = (msg.guild.owner and msg.guild.owner.user.tag..":"..msg.guild.owner.user.id) or msg.guild.ownerId}, - {name = "Created At",value = os.date("!%c",msg.guild.createdAt).." (UTC+0)"}, - {name = "Text Channels",value = msg.guild.textChannels:count()}, - {name = "Voice Channels",value = msg.guild.voiceChannels:count()} - } + thumbnail = { + url = msg.guild.iconURL + }, + title = msg.guild.name, + description = msg.guild.description, + fields = { + {name = "Members",value = msg.guild.totalMemberCount}, + {name = "Owner",value = (msg.guild.owner and msg.guild.owner.user.tag..":"..msg.guild.owner.user.id) or msg.guild.ownerId}, + {name = "Created At",value = os.date("!%c",msg.guild.createdAt).." (UTC+0)"}, + {name = "Text Channels",value = msg.guild.textChannels:count()}, + {name = "Voice Channels",value = msg.guild.voiceChannels:count()} + } }}) - end, + end, }) plugin:add_command(c_server) local c_user = command("user", { - exec = function(msg,args,opts) + exec = function(msg,args,opts) local member = msg.guild:getMember((args[1] or ""):match("%d+")) or msg.guild:getMember(msg.author.id) local roles = "" for k,v in pairs(member.roles) do - roles = roles..v.mentionString.."\n" + roles = roles..v.mentionString.."\n" end msg:reply({embed = { - title = member.user.tag..":"..member.user.id, - thumbnail = { - url = member.user:getAvatarURL() - }, - fields = { - {name = "Profile Created At",value = os.date("!%c",member.user.createdAt).." (UTC+0)"}, - {name = "Joined At",value = os.date("!%c",discordia.Date.fromISO(member.joinedAt):toSeconds()).." (UTC+0)",inline = true}, - {name = "Boosting",value = ((member.premiumSince and "Since "..member.premiumSince) or "No"),inline = true}, - {name = "Highest Role",value = member.highestRole.mentionString,inline = true}, - {name = "Roles",value = roles,inline = true} - } + title = member.user.tag..":"..member.user.id, + thumbnail = { + url = member.user:getAvatarURL() + }, + fields = { + {name = "Profile Created At",value = os.date("!%c",member.user.createdAt).." (UTC+0)"}, + {name = "Joined At",value = os.date("!%c",discordia.Date.fromISO(member.joinedAt):toSeconds()).." (UTC+0)",inline = true}, + {name = "Boosting",value = ((member.premiumSince and "Since "..member.premiumSince) or "No"),inline = true}, + {name = "Highest Role",value = member.highestRole.mentionString,inline = true}, + {name = "Roles",value = roles,inline = true} + } }}) - end, + end, }) plugin:add_command(c_user) @@ -291,10 +260,7 @@ local c_speak = command("speak", { "string" }, exec = function(msg,args,opts) - local text = purify_strings(msg, table.concat(args," ")) - if opts["unescape"] or opts["u"] then - text = text:gsub("\\","") - end + local text = purify.purify_pings(msg, table.concat(args," ")) msg:reply(text) msg:delete() end, @@ -302,32 +268,26 @@ local c_speak = command("speak", { plugin:add_command(c_speak) local c_adminSpeak = command("adminSpeak", { - args = { - "string" - }, - exec = function(msg,args,opts) - local text = table.concat(args," ") - if opts["unescape"] or opts["u"] then - text = text:gsub("\\","") - end - msg:reply(text) - msg:delete() - end, - perms = { - "mentionEveryone" - } + args = { + "string" + }, + exec = function(msg,args,opts) + local text = table.concat(args," ") + msg:reply(text) + msg:delete() + end, + perms = { + "mentionEveryone" + } }) plugin:add_command(c_adminSpeak) local c_echo = command("echo",{ args = { - "string" + "string" }, exec = function(msg,args,opts) - local text = purify_strings(msg, table.concat(args," ")) - if opts["unescape"] or opts["u"] then - text = text:gsub("\\","") - end + local text = purify.purify_pings(msg, table.concat(args," ")) msg:reply(text) end, }) @@ -335,29 +295,20 @@ plugin:add_command(c_echo) local c_pingself = command("pingself",{ args = { - "string" + "string" }, exec = function(msg,args,opts) - local text = purify_strings(msg, table.concat(args," ")) - if opts["unescape"] or opts["u"] then - text = text:gsub("\\","") - end + local text = purify.purify_pings(msg, table.concat(args," ")) msg:reply("<@"..tostring(msg.member.id).."> "..text) end, }) plugin:add_command(c_pingself) plugin.removal_callback = function() - for k,v in pairs(config.aliases) do - remove_alias(k) - end + for k,v in pairs(config.aliases) do + remove_alias(k) + end end -local helpdb = import(plugin_path:sub(3,-1).."help") -plugin:for_all_commands(function(command) - if helpdb[command.name] then - command:set_help(helpdb[command.name]) - end -end) - +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/plugins/help.lua b/plugins/plugins/help.lua new file mode 100644 index 0000000..baab74a --- /dev/null +++ b/plugins/plugins/help.lua @@ -0,0 +1,32 @@ +local discordia = require('discordia') +return { + ["enable"] = {embed = { + title = "Enable plugin", + description = [[This command loads a plugin, +addng its commands to the command pool]], + fields = { + {name = "Usage:",value = "load "}, + {name = "Perms:",value = "Administrator, other (via ``rules --allow``)"} + }, + color = discordia.Color.fromHex("ff5100").value + }}, + ["disable"] = {embed = { + title = "Disable a loaded plugin", + description = [[This commands unloads a previously loaded plugin, +removing its commands from the command pool]], + fields = { + {name = "Usage:",value = "unload "}, + {name = "Perms:",value = "Administrator, other (via ``rules --allow``)"} + }, + color = discordia.Color.fromHex("ff5100").value + }}, + ["plugins"] = {embed = { + title = "View all known plugins", + description = [[This commmand prints info on loaded and unloaded plugins]], + fields = { + {name = "Usage:",value = "plugins"}, + {name = "Perms:",value = "Administrator, other (via ``rules --allow``)"} + }, + color = discordia.Color.fromHex("ff5100").value + }}, +} diff --git a/plugins/plugins/init.lua b/plugins/plugins/init.lua index 0e522c9..f382dfa 100644 --- a/plugins/plugins/init.lua +++ b/plugins/plugins/init.lua @@ -4,107 +4,80 @@ local plugin = plugin_c("pluginmanager") local utilities = require("table-utils") local generic_admin_template = { - args = {"string"}, - perms = { - "administrator" - }, + args = {"string"}, + perms = { + "administrator" + }, } local enable = command("enable",utilities.overwrite(generic_admin_template,{ - help = {embed = { - title = "Enable plugin", - description = [[This command loads a plugin, -adding its commands to the command pool]], - fields = { - {name = "Usage:",value = "load "}, - {name = "Perms:",value = "Administrator, other (via ``rules --allow``)"} - }, - color = discordia.Color.fromHex("ff5100").value - }}, exec = function(msg,args,opts) - local status,message = plugin_handler:load(args[1]) - local plugin_data = command_handler:get_commands_metadata().plugins - local embed = { - description = message, - color = discordia.Color.fromHex("ff5100").value, - } - if status then - embed.fields = { - {name = "New commands:",value = - table.concat(plugin_data[args[1]] or {},", ").." " - } + local status,message = plugin_handler:load(args[1]) + local plugin_data = command_handler:get_metadata().plugins + local embed = { + description = message, + color = discordia.Color.fromHex("ff5100").value, } - end - msg:reply({embed = embed}) + if status then + embed.fields = { + {name = "New commands:",value = + table.concat(plugin_data[args[1]] or {},", ").." " + } + } + end + msg:reply({embed = embed}) end })) plugin:add_command(enable) local disable = command("disable",utilities.overwrite(generic_admin_template,{ - help = {embed = { - title = "Disable a loaded plugin", - description = [[This commands unloads a previously loaded plugin, -removing its commands from the command pool]], - fields = { - {name = "Usage:",value = "unload "}, - {name = "Perms:",value = "Administrator, other (via ``rules --allow``)"} - }, - color = discordia.Color.fromHex("ff5100").value - }}, exec = function(msg,args,opts) - local plugin_data = command_handler:get_commands_metadata().plugins - if not (args[1] == "plugins") then - local status,message = plugin_handler:unload(args[1]) - local embed = { - description = message, - color = discordia.Color.fromHex("ff5100").value, - } - if status then - embed.fields = { - {name = "Removed commands:",value = - table.concat(plugin_data[args[1]] or {},", ").." " + local plugin_data = command_handler:get_metadata().plugins + if not (args[1] == "plugins") then + local status,message = plugin_handler:unload(args[1]) + local embed = { + description = message, + color = discordia.Color.fromHex("ff5100").value, } - } + if status then + embed.fields = { + {name = "Removed commands:",value = + table.concat(plugin_data[args[1]] or {},", ").." " + } + } + end + msg:reply({embed = embed}) + else + msg:reply("TIME PARADOX") end - msg:reply({embed = embed}) - else - msg:reply("TIME PARADOX") - end end })) plugin:add_command(disable) local plugins = command("plugins",utilities.overwrite(generic_admin_template,{ - help = {embed = { - title = "View all known plugins", - description = [[This commmand prints info on loaded and unloaded plugins]], - fields = { - {name = "Usage:",value = "plugins"}, - {name = "Perms:",value = "Administrator, other (via ``rules --allow``)"} - } - }}, - args = {}, - exec = function(msg,args,opts) - local all_plugins = plugin_handler:list_loadable() - local unloaded_plugins = {} - local loaded_plugins = {} - for k,v in pairs(all_plugins) do - if not v.loaded then - table.insert(unloaded_plugins,k) - else - table.insert(loaded_plugins,k) + args = {}, + exec = function(msg,args,opts) + local all_plugins = plugin_handler:list_loadable() + local unloaded_plugins = {} + local loaded_plugins = {} + for k,v in pairs(all_plugins) do + if not v.loaded then + table.insert(unloaded_plugins,k) + else + table.insert(loaded_plugins,k) + end + end + if #unloaded_plugins == 0 then + table.insert(unloaded_plugins," ") + end + msg:reply({embed={ + color = discordia.Color.fromHex("ff5100").value, + fields = { + {name = "Loaded plugins",value = "``"..table.concat(loaded_plugins,"``,\n``").."``"}, + {name = "Unloaded plugins",value = "``"..table.concat(unloaded_plugins,"``,\n``").."``"} + } + }}) end - end - if #unloaded_plugins == 0 then - table.insert(unloaded_plugins," ") - end - msg:reply({embed={ - color = discordia.Color.fromHex("ff5100").value, - fields = { - {name = "Loaded plugins",value = "``"..table.concat(loaded_plugins,"``,\n``").."``"}, - {name = "Unloaded plugins",value = "``"..table.concat(unloaded_plugins,"``,\n``").."``"} - } - }}) - end })) plugin:add_command(plugins) +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/reactions/help.lua b/plugins/reactions/help.lua new file mode 100644 index 0000000..8b41659 --- /dev/null +++ b/plugins/reactions/help.lua @@ -0,0 +1,42 @@ +return { + ["pivot"] = {embed={ + title = "Select a pivot message to manipulate", + description = "Pivot is like a message selector which allows easy reaction manipulations", + fields = { + {name = "Usage: ",value = "pivot "}, + {name = "Perms: ",valeu = "Administartor"} + } + }}, + ["role-toggle"] = {embed={ + title = "Add a simple role switch to the pivot", + description = "Note: you cannot assign more than one role to a single reaction", + fields = { + {name = "Usage: ",value = "role-toggle "}, + {name = "Perms: ",value = "administrator"} + } + }}, + ["remove-reaction"] = {embed={ + title = "Remove a reaction from a pivot", + description = "If you don't specify a reaction to remove, the entire pivot for the message is removed automatically", + fields = { + {name = "Usage: ",value = "remove-reaction "}, + {name = "Perms: ",value = "Administrator"} + } + }}, + ["toggle"] = {embed={ + title = "Add a toggle that runs specific commands", + description = "Note: you cannot assign more than one action to a single reaction \n``$user`` gets replaced with the id of the user that interacted with the reaction.", + fields = { + {name = "Usage: ",value = "toggle "}, + {name = "Perms: ",value = "administrator"} + } + }}, + ["button"] = {embed={ + title = "Add a button that runs specific command when pressed", + description = "Note: you cannot assign more than one action to a single reaction \n``$user`` gets replaced with the id of the user that interacted with the reaction.", + fields = { + {name = "Usage: ",value = "button "}, + {name = "Perms: ",value = "administrator"} + } + }}, +} diff --git a/plugins/reactions/init.lua b/plugins/reactions/init.lua index 3afb9df..52ea596 100644 --- a/plugins/reactions/init.lua +++ b/plugins/reactions/init.lua @@ -7,334 +7,295 @@ local segment = {} segment.pivots = config local getEmoji = function(id) - local emoji = guild:getEmoji(id:match("(%d+)[^%d]*$")) - if emoji then - return emoji - else - return id - end + local emoji = guild:getEmoji(id:match("(%d+)[^%d]*$")) + if emoji then + return emoji + else + return id + end end local function count(tab) - local n = 0 - for k,v in pairs(tab) do - n = n + 1 - end - return n + local n = 0 + for k,v in pairs(tab) do + n = n + 1 + end + return n end local pivot = command("pivot",{ - help = {embed={ - title = "Select a pivot message to manipulate", - description = "Pivot is like a message selector which allows easy reaction manipulations", - fields = { - {name = "Usage: ",value = "pivot "}, - {name = "Perms: ",valeu = "Administartor"} - } - }}, - args = { - "messageLink" - }, - perms = { - "administrator" - }, - exec = function(msg,args,opts) - if segment.pivot and count(segment.pivot.buttons) == 0 then - print("[REACTIONS] Deleting pivot: "..tostring(segment.pivot.message)) - segment.pivots[segment.pivot.message] = nil - end - local message = args[1] - if not message then - msg:reply("Couldn't find message with id "..args[2]) - return false - end - if not segment.pivots[message.id] then - print("[REACTIONS] Creating pivot: "..tostring(message.id)) - segment.pivots[message.id] = {} - segment.pivots[message.id].message = message.id - segment.pivots[message.id].channel = message.channel.id - segment.pivots[message.id].buttons = {} - end - segment.pivot = segment.pivots[message.id] - return true - end - }) + args = { + "messageLink" + }, + perms = { + "administrator" + }, + exec = function(msg,args,opts) + if segment.pivot and count(segment.pivot.buttons) == 0 then + print("[REACTIONS] Deleting pivot: "..tostring(segment.pivot.message)) + segment.pivots[segment.pivot.message] = nil + end + local message = args[1] + if not message then + msg:reply("Couldn't find message with id "..args[2]) + return false + end + if not segment.pivots[message.id] then + print("[REACTIONS] Creating pivot: "..tostring(message.id)) + segment.pivots[message.id] = {} + segment.pivots[message.id].message = message.id + segment.pivots[message.id].channel = message.channel.id + segment.pivots[message.id].buttons = {} + end + segment.pivot = segment.pivots[message.id] + return true + end + }) plugin:add_command(pivot) local role_toggle = command("role-toggle",{ - help = {embed={ - title = "Add a simple role switch to the pivot", - description = "Note: you cannot assign more than one role to a single reaction", - fields = { - {name = "Usage: ",value = "role-toggle "}, - {name = "Perms: ",value = "administrator"} - } - }}, - args = { - "string", - "role", - }, - perms = { - "administrator" - }, - exec = function(msg,args,opts) - if not segment.pivot then - msg:reply("Pivot not selected. Use "..globals.prefix.."pivot to select it and then try again") - return false - end - local emoji = getEmoji(args[1]) - local channel = guild:getChannel(segment.pivot.channel) - if not channel then - msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") - return false - end - local message = channel:getMessage(segment.pivot.message) - if not message then - msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") - return false - end - print("[REACTIONS] Adding role-toggle listener") - local grabEmoji = function(reaction) - segment.pivot.buttons[tostring(reaction.emojiId or reaction.emojiName)] = { - type = "role-toggler", - role = tostring(args[2].id) - } - end - message:removeReaction(emoji,client.user.id) - client:once("reactionAdd",grabEmoji) - if not message:addReaction(emoji) then - client:removeListener("reactionAdd",grabEmoji) - msg:reply("Couldn't add reaction - emoji might be invalid") - return false - else - return true - end - end - }) + args = { + "string", + "role", + }, + perms = { + "administrator" + }, + exec = function(msg,args,opts) + if not segment.pivot then + msg:reply("Pivot not selected. Use "..globals.prefix.."pivot to select it and then try again") + return false + end + local emoji = getEmoji(args[1]) + local channel = guild:getChannel(segment.pivot.channel) + if not channel then + msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") + return false + end + local message = channel:getMessage(segment.pivot.message) + if not message then + msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") + return false + end + print("[REACTIONS] Adding role-toggle listener") + local grabEmoji = function(reaction) + segment.pivot.buttons[tostring(reaction.emojiId or reaction.emojiName)] = { + type = "role-toggler", + role = tostring(args[2].id) + } + end + message:removeReaction(emoji,client.user.id) + client:once("reactionAdd",grabEmoji) + if not message:addReaction(emoji) then + client:removeListener("reactionAdd",grabEmoji) + msg:reply("Couldn't add reaction - emoji might be invalid") + return false + else + return true + end + end + }) plugin:add_command(role_toggle) local remove_reaction = command("remove-reaction",{ - help = {embed={ - title = "Remove a reaction from a pivot", - description = "If you don't specify a reaction to remove, the entire pivot for the message is removed automatically", - fields = { - {name = "Usage: ",value = "remove-reaction "}, - {name = "Perms: ",value = "Administrator"} - } - }}, - perms = { - "administrator" - }, - exec = function(msg,args,opts) - local channel = guild:getChannel(segment.pivot.channel) - if not channel then - msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") - return false - end - local message = channel:getMessage(segment.pivot.message) - if not message then - msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") - return false - end - print("[REACTIONS] Removing reaction listener") - if args[1] then - local emoji = getEmoji(args[1]) - message:removeReaction(emoji,client.user.id) - segment.pivot.buttons[((type(emoji) == "table") and emoji.id) or emoji] = nil - return true - else - message:clearReactions() - segment.pivots[tostring(message.id)] = nil - segment.pivot = nil - return true - end - end - }) + perms = { + "administrator" + }, + exec = function(msg,args,opts) + local channel = guild:getChannel(segment.pivot.channel) + if not channel then + msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") + return false + end + local message = channel:getMessage(segment.pivot.message) + if not message then + msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") + return false + end + print("[REACTIONS] Removing reaction listener") + if args[1] then + local emoji = getEmoji(args[1]) + message:removeReaction(emoji,client.user.id) + segment.pivot.buttons[((type(emoji) == "table") and emoji.id) or emoji] = nil + return true + else + message:clearReactions() + segment.pivots[tostring(message.id)] = nil + segment.pivot = nil + return true + end + end + }) plugin:add_command(remove_reaction) local toggle = command("toggle",{ - help = {embed={ - title = "Add a toggle that runs specific commands", - description = "Note: you cannot assign more than one action to a single reaction \n``$user`` gets replaced with the id of the user that interacted with the reaction.", - fields = { - {name = "Usage: ",value = "toggle "}, - {name = "Perms: ",value = "administrator"} - } - }}, - args = { - "string", - "string", - "string", - }, - perms = { - "administrator" - }, - exec = function(msg,args,opts) - if not segment.pivot then - msg:reply("Pivot not selected. Use "..globals.prefix.."pivot to select it and then try again") - return false - end - local emoji = getEmoji(args[1]) - local channel = guild:getChannel(segment.pivot.channel) - if not channel then - msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") - return false - end - local message = channel:getMessage(segment.pivot.message) - if not message then - msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") - return false - end - print("[REACTIONS] Adding toggle listener") - local grabEmoji = function(reaction) - segment.pivot.buttons[tostring(reaction.emojiId or reaction.emojiName)] = { - type = "toggler", - on = args[2], - off = args[3], - } - end - message:removeReaction(emoji,client.user.id) - client:once("reactionAdd",grabEmoji) - if not message:addReaction(emoji) then - client:removeListener("reactionAdd",grabEmoji) - msg:reply("Couldn't add reaction - emoji might be invalid") - return false - else - return true - end - end - }) + args = { + "string", + "string", + "string", + }, + perms = { + "administrator" + }, + exec = function(msg,args,opts) + if not segment.pivot then + msg:reply("Pivot not selected. Use "..globals.prefix.."pivot to select it and then try again") + return false + end + local emoji = getEmoji(args[1]) + local channel = guild:getChannel(segment.pivot.channel) + if not channel then + msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") + return false + end + local message = channel:getMessage(segment.pivot.message) + if not message then + msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") + return false + end + print("[REACTIONS] Adding toggle listener") + local grabEmoji = function(reaction) + segment.pivot.buttons[tostring(reaction.emojiId or reaction.emojiName)] = { + type = "toggler", + on = args[2], + off = args[3], + } + end + message:removeReaction(emoji,client.user.id) + client:once("reactionAdd",grabEmoji) + if not message:addReaction(emoji) then + client:removeListener("reactionAdd",grabEmoji) + msg:reply("Couldn't add reaction - emoji might be invalid") + return false + else + return true + end + end + }) plugin:add_command(toggle) local button = command("button",{ - help = {embed={ - title = "Add a button that runs specific command when pressed", - description = "Note: you cannot assign more than one action to a single reaction \n``$user`` gets replaced with the id of the user that interacted with the reaction.", - fields = { - {name = "Usage: ",value = "button "}, - {name = "Perms: ",value = "administrator"} - } - }}, - args = { - "string", - "string", - }, - perms = { - "administrator" - }, - exec = function(msg,args,opts) - if not segment.pivot then - msg:reply("Pivot not selected. Use "..globals.prefix.."pivot to select it and then try again") - return false - end - local emoji = getEmoji(args[1]) - local channel = guild:getChannel(segment.pivot.channel) - if not channel then - msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") - return false - end - local message = channel:getMessage(segment.pivot.message) - if not message then - msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") - return false - end - print("[REACTIONS] Adding button listener") - local grabEmoji = function(reaction) - segment.pivot.buttons[tostring(reaction.emojiId or reaction.emojiName)] = { - type = "button", - on = args[2], - } - end - message:removeReaction(emoji,client.user.id) - client:once("reactionAdd",grabEmoji) - if not message:addReaction(emoji) then - client:removeListener("reactionAdd",grabEmoji) - msg:reply("Couldn't add reaction - emoji might be invalid") - return false - else - return true - end - end - }) + args = { + "string", + "string", + }, + perms = { + "administrator" + }, + exec = function(msg,args,opts) + if not segment.pivot then + msg:reply("Pivot not selected. Use "..globals.prefix.."pivot to select it and then try again") + return false + end + local emoji = getEmoji(args[1]) + local channel = guild:getChannel(segment.pivot.channel) + if not channel then + msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") + return false + end + local message = channel:getMessage(segment.pivot.message) + if not message then + msg:reply("Something went horribly wrong, but it's not your fault. This incident has been (hopefully) reported") + return false + end + print("[REACTIONS] Adding button listener") + local grabEmoji = function(reaction) + segment.pivot.buttons[tostring(reaction.emojiId or reaction.emojiName)] = { + type = "button", + on = args[2], + } + end + message:removeReaction(emoji,client.user.id) + client:once("reactionAdd",grabEmoji) + if not message:addReaction(emoji) then + client:removeListener("reactionAdd",grabEmoji) + msg:reply("Couldn't add reaction - emoji might be invalid") + return false + else + return true + end + end + }) plugin:add_command(button) local buttonOn = function(message,hash,userID) - if not message then - log("ERROR","Attempted to find a deleted message") - return - end - if segment.pivots[tostring(message.id)] and userID ~= client.user.id then - local current_pivot = segment.pivots[tostring(message.id)] - if current_pivot.buttons[tostring(hash)] then - local current_button = current_pivot.buttons[tostring(hash)] - local new_content - if current_button.on then - new_content = current_button.on:gsub("%$user",userID) - end - if current_button.type == "role-toggler" then - guild:getMember(userID):addRole(current_button.role) - end - if current_button.type == "toggler" then - command_handler:handle(fake_message(message,{ - delete = function() end, - content = new_content - })) - end - if current_button.type == "button" then - command_handler:handle(fake_message(message,{ - delete = function() end, - content = new_content - })) - end + if not message then + log("ERROR","Attempted to find a deleted message") + return + end + if segment.pivots[tostring(message.id)] and userID ~= client.user.id then + local current_pivot = segment.pivots[tostring(message.id)] + if current_pivot.buttons[tostring(hash)] then + local current_button = current_pivot.buttons[tostring(hash)] + local new_content + if current_button.on then + new_content = current_button.on:gsub("%$user",userID) + end + if current_button.type == "role-toggler" then + guild:getMember(userID):addRole(current_button.role) + end + if current_button.type == "toggler" then + command_handler:handle(fake_message(message,{ + delete = function() end, + content = new_content + })) + end + if current_button.type == "button" then + command_handler:handle(fake_message(message,{ + delete = function() end, + content = new_content + })) + end + end end - end end local buttonOff = function(message,hash,userID) - if not message then - log("ERROR","Attempted to find a deleted message") - return - end - if segment.pivots[tostring(message.id)] and userID ~= client.user.id then - local current_pivot = segment.pivots[tostring(message.id)] - if current_pivot.buttons[tostring(hash)] then - local current_button = current_pivot.buttons[tostring(hash)] - local new_content - if current_button.off then - new_content = current_button.off:gsub("%$user",userID) - end - if current_button.type == "role-toggler" then - guild:getMember(userID):removeRole(current_button.role) - end - if current_button.type == "toggler" then - command_handler:handle(fake_message(message,{ - delete = function() end, - content = new_content - })) - end + if not message then + log("ERROR","Attempted to find a deleted message") + return + end + if segment.pivots[tostring(message.id)] and userID ~= client.user.id then + local current_pivot = segment.pivots[tostring(message.id)] + if current_pivot.buttons[tostring(hash)] then + local current_button = current_pivot.buttons[tostring(hash)] + local new_content + if current_button.off then + new_content = current_button.off:gsub("%$user",userID) + end + if current_button.type == "role-toggler" then + guild:getMember(userID):removeRole(current_button.role) + end + if current_button.type == "toggler" then + command_handler:handle(fake_message(message,{ + delete = function() end, + content = new_content + })) + end + end end - end end events:on("reactionAdd",function(reaction,userID) - local message = reaction.message - local hash = tostring(reaction.emojiId or reaction.emojiName) - buttonOn(message,hash,userID) + local message = reaction.message + local hash = tostring(reaction.emojiId or reaction.emojiName) + buttonOn(message,hash,userID) end) events:on("reactionRemove",function(reaction,userID) - local message = reaction.message - local hash = tostring(reaction.emojiId or reaction.emojiName) - buttonOff(message,hash,userID) + local message = reaction.message + local hash = tostring(reaction.emojiId or reaction.emojiName) + buttonOff(message,hash,userID) end) events:on("reactionAddUncached",function(channelId,messageId,hash,userId) - local message = client:getChannel(channelId):getMessage(messageId) - local hash = tostring(hash) - buttonOn(message,hash,userId) + local message = client:getChannel(channelId):getMessage(messageId) + local hash = tostring(hash) + buttonOn(message,hash,userId) end) events:on("reactionRemoveUncached",function(channelId,messageId,hash,userId) - local message = client:getChannel(channelId):getMessage(messageId) - local hash = tostring(hash) - buttonOff(message,hash,userId) + local message = client:getChannel(channelId):getMessage(messageId) + local hash = tostring(hash) + buttonOff(message,hash,userId) end) +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/roledefaults/help.lua b/plugins/roledefaults/help.lua new file mode 100644 index 0000000..75d714e --- /dev/null +++ b/plugins/roledefaults/help.lua @@ -0,0 +1,5 @@ +return { + ["droleadd"] = "Add a default role to assign for new users", + ["droledel"] = "Remove a role from the list of default roles", + ["drolelist"] = "List all default roles", +} diff --git a/plugins/roledefaults/init.lua b/plugins/roledefaults/init.lua index cdf3d67..263e5c8 100644 --- a/plugins/roledefaults/init.lua +++ b/plugins/roledefaults/init.lua @@ -9,19 +9,17 @@ client:on("memberJoin",function(member) end) local droleadd = command("droleadd",{ - help = "Add a default role to assign for new users", - usage = "droleadd ", - perms = {"administrator"}, - args = { - "role" - }, - exec = function(msg,args,opts) - table.insert(config.default_roles,args[1].id) - msg:reply("Added role "..args[1].name.." to default roles list") - end, + usage = "droleadd ", + perms = {"administrator"}, + args = { + "role" + }, + exec = function(msg,args,opts) + table.insert(config.default_roles,args[1].id) + msg:reply("Added role "..args[1].name.." to default roles list") + end, }) local droledel = command("droledel",{ - help = "Remove a role from the list of default roles", usage = "droledel ", perms = {"administrator"}, args = { @@ -37,7 +35,6 @@ local droledel = command("droledel",{ end }) local drolelist = command("drolelist", { - help = "List all default roles", usage = "drolelist", perms = {"administrator"}, exec = function(msg,args,opts) @@ -56,5 +53,6 @@ local drolelist = command("drolelist", { plugin:add_command(droleadd) plugin:add_command(droledel) plugin:add_command(drolelist) +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/security/help.lua b/plugins/security/help.lua new file mode 100644 index 0000000..23419f7 --- /dev/null +++ b/plugins/security/help.lua @@ -0,0 +1,46 @@ +return { + ["grant-role"] = {embed={ + title = "Grant a role to the user", + description = "If is not provided, the caller is assumed as the argument.", + fields = { + {name = "Usage:",value = "grant-role []"}, + {name = "Perms:",value = "administrator"}, + {name = "Options:",value = "-q - quiet (don't print the result)"} + } + }}, + ["revoke-role"] = {embed={ + title = "Revoke a role from the user", + description = "If is not provided, the caller is assumed as the argument.", + fields = { + {name = "Usage:",value = "revoke-role []"}, + {name = "Perms:",value = "administrator"}, + {name = "Options:",value = "-q - quiet (don't print the result)"} + } + }}, + ["warn"] = {embed={ + title = "Warn a user", + description = "nuff said.", + fields = { + {name = "Usage:",value = "warn "}, + {name = "Perms:",value = "kickMembers"}, + } + }}, + ["infractions"] = { embed = { + title = "List user infractions", + description = "Infractions include kicks, bans, mutes and warnings.", + fields = { + {name = "Usage: ", value = "infractions []"}, + {name = "Perms: ", value = "kickMembers"}, + {name = "Options: ", value = "--type=(warn default,ban,kick)"} + } + }}, + ["purge"] = { embed = { + title = "Purge a number of messages", + description = "nuff said.", + fields = { + {name = "Usage: ", value = "purge "}, + {name = "Perms: ", value = "manageMessages"}, + {name = "Options: ", value = "`--regex (regex)` - match content against regex; \n`--user (user)` - match user against id/name; \n`-w` - match webhook messages"} + } + }}, +} diff --git a/plugins/security/init.lua b/plugins/security/init.lua index 0585e13..8bc9c06 100644 --- a/plugins/security/init.lua +++ b/plugins/security/init.lua @@ -17,15 +17,6 @@ CREATE TABLE infractions(id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, desc T end local grantrole = command("grant-role",{ - help = {embed={ - title = "Grant a role to the user", - description = "If is not provided, the caller is assumed as the argument.", - fields = { - {name = "Usage:",value = "grant-role []"}, - {name = "Perms:",value = "administrator"}, - {name = "Options:",value = "-q - quiet (don't print the result)"} - } - }}, perms = { "administrator" }, @@ -41,15 +32,6 @@ local grantrole = command("grant-role",{ plugin:add_command(grantrole) local revokerole = command("revoke-role",{ - help = {embed={ - title = "Revoke a role from the user", - description = "If is not provided, the caller is assumed as the argument.", - fields = { - {name = "Usage:",value = "revoke-role []"}, - {name = "Perms:",value = "administrator"}, - {name = "Options:",value = "-q - quiet (don't print the result)"} - } - }}, perms = { "administrator" }, @@ -65,14 +47,6 @@ local revokerole = command("revoke-role",{ plugin:add_command(revokerole) local warn = command("warn",{ - help = {embed={ - title = "Warn a user", - description = "nuff said.", - fields = { - {name = "Usage:",value = "warn "}, - {name = "Perms:",value = "kickMembers"}, - } - }}, perms = { "kickMembers" }, @@ -99,15 +73,6 @@ local warn = command("warn",{ plugin:add_command(warn) local infractions = command("infractions", { - help = { embed = { - title = "List user infractions", - description = "Infractions include kicks, bans, mutes and warnings.", - fields = { - {name = "Usage: ", value = "infractions []"}, - {name = "Perms: ", value = "kickMembers"}, - {name = "Options: ", value = "--type=(warn default,ban,kick)"} - } - }}, perms = { "kickMembers" }, @@ -150,15 +115,6 @@ local infractions = command("infractions", { plugin:add_command(infractions) local purge = command("purge",{ - help = { embed = { - title = "Purge a number of messages", - description = "nuff said.", - fields = { - {name = "Usage: ", value = "purge "}, - {name = "Perms: ", value = "manageMessages"}, - {name = "Options: ", value = "`--regex (regex)` - match content against regex; \n`--user (user)` - match user against id/name; \n`-w` - match webhook messages"} - } - }}, perms = { "manageMessages" }, @@ -210,5 +166,5 @@ local purge = command("purge",{ end }) plugin:add_command(purge) - +plugin:load_helpdb(plugin_path.."help.lua") return plugin diff --git a/plugins/tools/help.lua b/plugins/tools/help.lua new file mode 100644 index 0000000..c0b5850 --- /dev/null +++ b/plugins/tools/help.lua @@ -0,0 +1,37 @@ +return { + ["dice"] = "Simulates a dice throw, prints the value of each die", + ["cards"] = "Draw a specific amount of playing cards and display them", + ["calculate"] = {embed={ + title = "Calculate an expression", + description = "Calculates maths using libqalculate. https://qalculate.github.io/ for more info", + fields = { + {name = "Usage",value = [[calculate ""]]}, + {name = "Perms: ",value = "All"}, + {name = "Options",value = "`-e` - exact mode"} + } + }}, + ["pfp"] = "Show the profile picture of a user, or if none is specified, of yourself", + ["markpov"] = { embed = { + title = "Generate some text using markov chains", + description = "Generates text using the markov chain rule applied to a predefined set of words", + fields = { + {name = "Usage: ", value = "markov "}, + {name = "Options: ", value = [[ +--preseteset> - Select a text preset. Currently available: +``defaul- Generated from a wikipedia page on markov chains +``freud`The largest one, generated from a page on Sigmund Freud +``reddit Generated from reddit comments +``travist`` - Generated from transcript of a video by PlasticPills on travis scott burger +]] }, + {name = "Perms: ", value = "any"} + } + }}, + ["embed"] = {embed={ + title = "Convert JSON objects into embeds", + description = "If you've worked with discord.js before, this might be simple. If you haven't, then check out https://github.com/yessiest/SuppaBot/wiki/Embeds", + fields = { + {name = "Usage",value = [[embed {code}]]}, + {name = "Perms: ",value = "All"}, + } + }}, +} diff --git a/plugins/tools/init.lua b/plugins/tools/init.lua index b3572e1..3c11ce8 100644 --- a/plugins/tools/init.lua +++ b/plugins/tools/init.lua @@ -28,152 +28,127 @@ function to_bit_string(num) end local flip = command("flip",{ - help = "Flips a coin, obv.", - usage = "flip", - exec = function(msg,args,opts) - local coin = math.random(1,100)%2 - if coin > 0 then - msg:reply("Heads") - else - msg:reply("Tails") - end - end, + help = "Flips a coin, obv.", + usage = "flip", + exec = function(msg,args,opts) + local coin = math.random(1,100)%2 + if coin > 0 then + msg:reply("Heads") + else + msg:reply("Tails") + end + end, }) plugin:add_command(flip) local dice = command("dice",{ - help = "Simulates a dice throw, prints the value of each die", - usage = "dice <2d6,d30,d20+4,etc>", - exec = function(msg,args,opts) - local out = {embed = { - fields = {}, - footer = { - text = 0 - } - }} - for I = 1,#args do - local v = args[I] - for J = 1,(v:match("(%d+)d%d+") or 1) do - local value = math.random(1,tonumber(v:match("d(%d+)"))) - if v:find("d%d+[%+%-]%d+") then - if v:match("d%d+([%+%-])") == "+" then - value = value + tonumber(v:match("d%d+[%+%-](%d+)")) - else - value = value - tonumber(v:match("d%d+[%+%-](%d+)")) - end - end - out.embed.fields[#out.embed.fields+1] = {name = "d"..v:match("d(%d+)"),value = value, inline = true} - out.embed.footer.text = out.embed.footer.text+value - if #out.embed.fields >= 25 then - break - end + usage = "dice <2d6,d30,d20+4,etc>", + exec = function(msg,args,opts) + local out = {embed = { + fields = {}, + footer = { + text = 0 + } + }} + for I = 1,#args do + local v = args[I] + for J = 1,(v:match("(%d+)d%d+") or 1) do + local value = math.random(1,tonumber(v:match("d(%d+)"))) + if v:find("d%d+[%+%-]%d+") then + if v:match("d%d+([%+%-])") == "+" then + value = value + tonumber(v:match("d%d+[%+%-](%d+)")) + else + value = value - tonumber(v:match("d%d+[%+%-](%d+)")) + end + end + out.embed.fields[#out.embed.fields+1] = {name = "d"..v:match("d(%d+)"),value = value, inline = true} + out.embed.footer.text = out.embed.footer.text+value + if #out.embed.fields >= 25 then + break end - if #out.embed.fields >= 25 then - break - end - end - out.embed.footer.text = "Total: "..out.embed.footer.text - msg:reply(out) - end, + end + if #out.embed.fields >= 25 then + break + end + end + out.embed.footer.text = "Total: "..out.embed.footer.text + msg:reply(out) + end, }) plugin:add_command(dice) local cards = command("cards",{ - help = "Draw a specific amount of playing cards and display them", - usage = "cards ", - args = {"number"}, - exec = function(msg,args,opts) - local out = {embed = { - fields = {} - }} - local random = math.random - for I = 1,(args[1] < 25 and args[1]) or 25 do - local suits = {"spades","clubs","diamonds","hearts"} - local values = { - "A","1","2","3","4","5", - "6","7","8","9","J","Q","K" - } - out.embed.fields[I] = {name = "card", value = " :"..suits[random(1,4)]..":"..values[random(1,11)].." ",inline = true} - end - msg:reply(out) - end, + usage = "cards ", + args = {"number"}, + exec = function(msg,args,opts) + local out = {embed = { + fields = {} + }} + local random = math.random + for I = 1,(args[1] < 25 and args[1]) or 25 do + local suits = {"spades","clubs","diamonds","hearts"} + local values = { + "A","1","2","3","4","5", + "6","7","8","9","J","Q","K" + } + out.embed.fields[I] = {name = "card", value = " :"..suits[random(1,4)]..":"..values[random(1,11)].." ",inline = true} + end + msg:reply(out) + end, }) plugin:add_command(cards) local calculate = command("calculate",{ - help = "Calculates maths using libqalculate. https://qalculate.github.io/ for more info", - usage = [[ -calculate "" -``-e`` - exact mode - ]], - args = { - "string" - }, - exec = function(msg,args,opts) - msg:reply(qalculator.qalc(args[1],opts["e"])) - end, + args = { + "string" + }, + exec = function(msg,args,opts) + msg:reply(qalculator.qalc(args[1],opts["e"])) + end, }) plugin:add_command(calculate) local pfp = command("pfp",{ - help = "Show the profile picture of a user, or if none is specified, of yourself", - usage = "pfp ", - exec = function(msg,args,opts) - local user = client:getUser((args[1] or ""):match("%d+")) - if user then - msg:reply(user:getAvatarURL().."?size=2048") - else - msg:reply(msg.author:getAvatarURL().."?size=2048") - end - end, + exec = function(msg,args,opts) + local user = client:getUser((args[1] or ""):match("%d+")) + if user then + msg:reply(user:getAvatarURL().."?size=2048") + else + msg:reply(msg.author:getAvatarURL().."?size=2048") + end + end, }) plugin:add_command(pfp) local markov = command("markov",{ - help = { embed = { - title = "Generate some text using markov chains", - description = "Generates text using the markov chain rule applied to a predefined set of words", - fields = { - {name = "Usage: ", value = "markov "}, - {name = "Options: ", value = [[ ---preset= - Select a text preset. Currently available: -``default`` - Generated from a wikipedia page on markov chains -``freud`` - The largest one, generated from a page on Sigmund Freud -``reddit`` - Generated from reddit comments -``travisscott`` - Generated from transcript of a video by PlasticPills on travis scott burger -]] }, - {name = "Perms: ", value = "any"} - } - }}, - exec = function(msg,args,opts) - local preset,code,err = import("file").readJSON("./resources/"..(opts["preset"] or "default"):match("%w+")..".json",{system_failed = true}) - if preset.system_failed then - msg:reply("No such preset") - return - end - markov_instance:load_state(preset) - local output = markov_instance:run("The",100) - msg:reply(output) + exec = function(msg,args,opts) + local preset,code,err = import("file").readJSON("./resources/"..(opts["preset"] or "default"):match("%w+")..".json",{system_failed = true}) + if preset.system_failed then + msg:reply("No such preset") + return end + markov_instance:load_state(preset) + local output = markov_instance:run("The",100) + msg:reply(output) + end }) plugin:add_command(markov) local embed = command("embed",{ - help = "Convert JSON objects into embeds", - usage = "If you've worked with discord.js before, this might be simple. If you haven't, then check out https://github.com/yessiest/SuppaBot/wiki/Embeds", - args = { - "string" - }, - exec = function(msg,args,opts) - local embed = msg.content:match("{.+}") - if not embed then - msg:reply("Invalid embed object") - return - end - local embed_obj,code,err = import("json").decode(embed) - if not embed_obj then - msg:reply("Error while decoding JSON object: "..tostring(err)) - return - end - if pcall(discordia.Color.fromHex,embed_obj.color) then - embed_obj.color = discordia.Color.fromHex(embed_obj.color).value - end - msg:reply({embed = embed_obj}) + args = { + "string" + }, + exec = function(msg,args,opts) + local embed = msg.content:match("{.+}") + if not embed then + msg:reply("Invalid embed object") + return end + local embed_obj,code,err = import("json").decode(embed) + if not embed_obj then + msg:reply("Error while decoding JSON object: "..tostring(err)) + return + end + if pcall(discordia.Color.fromHex,embed_obj.color) then + embed_obj.color = discordia.Color.fromHex(embed_obj.color).value + end + msg:reply({embed = embed_obj}) + end }) plugin:add_command(embed) +plugin:load_helpdb(plugin_path.."help.lua") return plugin