Ain't afraid of no bed

This commit is contained in:
Yessiest 2022-05-21 01:21:23 +04:00
parent ca17b716ba
commit f9bb6824f3
25 changed files with 1078 additions and 1127 deletions

View File

@ -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
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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -28,6 +28,14 @@ utilities.shallowcopy = function(orig)
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)

50
plugins/cron/help.lua Normal file
View File

@ -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 <number><unit>, 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 <delayformat> <command>"},
{name = "Perms:",value = "any"},
}
}},
["events"] = {embed={
title = "View your running events",
description = "nuff said.",
fields = {
{name = "Usage:",value = "events <page>"},
{name = "Perms:",value = "any"},
}
}},
["user-events"] = {embed={
title = "View running events of a certain user",
description = "nuff said.",
fields = {
{name = "Usage:",value = "user-events <user> <page>"},
{name = "Perms:",value = "administrator"},
}
}},
["remove-event"] = {embed={
title = "Remove an event",
description = "nuff said.",
fields = {
{name = "Usage:",value = "remove-event <id>"},
{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 <user> <id>"},
{name = "Perms:",value = "administrator"},
}
}},
}

View File

@ -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 <number><unit>, 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 <delayformat> <command>"},
{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 <page>"},
{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 <user> <page>"},
{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 <id>"},
{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 <user> <id>"},
{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

6
plugins/debug/help.lua Normal file
View File

@ -0,0 +1,6 @@
return {
["save"] = "Force-save config data",
["error"] = "Force error",
["permerror"] = "Force permission error",
["return_error"] = "Force a return value error",
}

View File

@ -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

View File

@ -107,9 +107,5 @@ c_befunge = command("befunge",{
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

11
plugins/help/help.lua Normal file
View File

@ -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 [<command> or --plugin <plugin>]"},
{name = "Perms:",value = "any"},
{name = "Options:",value = "--plugin"}
}
}}
}

View File

@ -1,92 +1,42 @@
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 [<command> or --plugin <plugin>]"},
{name = "Perms:",value = "any"},
{name = "Options:",value = "--plugin"}
}
}},
exec = function(msg,args,opts)
randomize_stuff()
local embed = {
color = discordia.Color.fromHex("32b3bc").value
color = color("32b3bc").value
}
if args[1] then
if count(opts) < 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"
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"
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 <command>`` to view help messages. (type ``help help`` for more info)"
embed.fields = {}
for k,v in pairs(command_handler:get_commands_metadata().plugins) do
for name,category in pairs(meta.categories) do
table.insert(embed.fields,{
name = k,
value = "``"..table.concat(v,"``, ``").."``"
name = name,
value = "``"..table.concat(category,"``,``").."``"
})
end
end
@ -94,4 +44,5 @@ local help_command = command("help",{
end,
})
plugin:add_command(help_command)
plugin:load_helpdb(plugin_path.."help.lua")
return plugin

View File

@ -4,6 +4,7 @@ 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 = {}
end
@ -63,32 +64,6 @@ local function remove_alias(name)
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
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
@ -100,12 +75,6 @@ end
local prefix = command("prefix",{
help = "Set prefix",
usage = "prefix [(add | remove | list (default)) [<new prefix>]]",
users = {
[client.owner.id] = 1
},
roles = {
["747042157185073182"] = 1
},
perms = {
"administrator"
},
@ -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,
@ -307,9 +273,6 @@ local c_adminSpeak = command("adminSpeak", {
},
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,
@ -324,10 +287,7 @@ local c_echo = command("echo",{
"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,
})
@ -338,10 +298,7 @@ local c_pingself = command("pingself",{
"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,
})
@ -353,11 +310,5 @@ plugin.removal_callback = function()
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

32
plugins/plugins/help.lua Normal file
View File

@ -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 <plugin-name>"},
{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 <plugin-name>"},
{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
}},
}

View File

@ -11,19 +11,9 @@ local generic_admin_template = {
}
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 <plugin-name>"},
{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 plugin_data = command_handler:get_metadata().plugins
local embed = {
description = message,
color = discordia.Color.fromHex("ff5100").value,
@ -40,18 +30,8 @@ adding its commands to the command pool]],
}))
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 <plugin-name>"},
{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
local plugin_data = command_handler:get_metadata().plugins
if not (args[1] == "plugins") then
local status,message = plugin_handler:unload(args[1])
local embed = {
@ -73,14 +53,6 @@ removing its commands from the command pool]],
}))
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()
@ -106,5 +78,6 @@ local plugins = command("plugins",utilities.overwrite(generic_admin_template,{
end
}))
plugin:add_command(plugins)
plugin:load_helpdb(plugin_path.."help.lua")
return plugin

View File

@ -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 <message link>"},
{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 <emoji> <role ping or role id>"},
{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 <emoji>"},
{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 <emoji> <command-on> <command-off>"},
{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 <emoji> <command>"},
{name = "Perms: ",value = "administrator"}
}
}},
}

View File

@ -24,14 +24,6 @@ local function count(tab)
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 <message link>"},
{name = "Perms: ",valeu = "Administartor"}
}
}},
args = {
"messageLink"
},
@ -62,14 +54,6 @@ local pivot = command("pivot",{
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 <emoji> <role ping or role id>"},
{name = "Perms: ",value = "administrator"}
}
}},
args = {
"string",
"role",
@ -113,14 +97,6 @@ local role_toggle = command("role-toggle",{
})
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 <emoji>"},
{name = "Perms: ",value = "Administrator"}
}
}},
perms = {
"administrator"
},
@ -151,14 +127,6 @@ local remove_reaction = command("remove-reaction",{
})
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 <emoji> <command-on> <command-off>"},
{name = "Perms: ",value = "administrator"}
}
}},
args = {
"string",
"string",
@ -204,14 +172,6 @@ local toggle = command("toggle",{
})
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 <emoji> <command>"},
{name = "Perms: ",value = "administrator"}
}
}},
args = {
"string",
"string",
@ -337,4 +297,5 @@ events:on("reactionRemoveUncached",function(channelId,messageId,hash,userId)
buttonOff(message,hash,userId)
end)
plugin:load_helpdb(plugin_path.."help.lua")
return plugin

View File

@ -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",
}

View File

@ -9,7 +9,6 @@ client:on("memberJoin",function(member)
end)
local droleadd = command("droleadd",{
help = "Add a default role to assign for new users",
usage = "droleadd <role>",
perms = {"administrator"},
args = {
@ -21,7 +20,6 @@ local droleadd = command("droleadd",{
end,
})
local droledel = command("droledel",{
help = "Remove a role from the list of default roles",
usage = "droledel <role>",
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

46
plugins/security/help.lua Normal file
View File

@ -0,0 +1,46 @@
return {
["grant-role"] = {embed={
title = "Grant a role to the user",
description = "If <user> is not provided, the caller is assumed as the <user> argument.",
fields = {
{name = "Usage:",value = "grant-role <role id> [<user>]"},
{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 <user> is not provided, the caller is assumed as the <user> argument.",
fields = {
{name = "Usage:",value = "revoke-role <role id> [<user>]"},
{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 <user> <reason>"},
{name = "Perms:",value = "kickMembers"},
}
}},
["infractions"] = { embed = {
title = "List user infractions",
description = "Infractions include kicks, bans, mutes and warnings.",
fields = {
{name = "Usage: ", value = "infractions <user> [<startfrom>]"},
{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 <number>"},
{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"}
}
}},
}

View File

@ -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 <user> is not provided, the caller is assumed as the <user> argument.",
fields = {
{name = "Usage:",value = "grant-role <role id> [<user>]"},
{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 <user> is not provided, the caller is assumed as the <user> argument.",
fields = {
{name = "Usage:",value = "revoke-role <role id> [<user>]"},
{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 <user> <reason>"},
{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 <user> [<startfrom>]"},
{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 <number>"},
{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

37
plugins/tools/help.lua Normal file
View File

@ -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 "<expression>"]]},
{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 <text to start with>"},
{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"},
}
}},
}

View File

@ -41,7 +41,6 @@ local flip = command("flip",{
})
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 = {
@ -77,7 +76,6 @@ local dice = command("dice",{
})
plugin:add_command(dice)
local cards = command("cards",{
help = "Draw a specific amount of playing cards and display them",
usage = "cards <amount>",
args = {"number"},
exec = function(msg,args,opts)
@ -98,11 +96,6 @@ local cards = command("cards",{
})
plugin:add_command(cards)
local calculate = command("calculate",{
help = "Calculates maths using libqalculate. https://qalculate.github.io/ for more info",
usage = [[
calculate "<expression>"
``-e`` - exact mode
]],
args = {
"string"
},
@ -112,8 +105,6 @@ calculate "<expression>"
})
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 <user or none>",
exec = function(msg,args,opts)
local user = client:getUser((args[1] or ""):match("%d+"))
if user then
@ -125,21 +116,6 @@ local pfp = command("pfp",{
})
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 <text to start with>"},
{name = "Options: ", value = [[
--preset=<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
@ -153,8 +129,6 @@ local markov = command("markov",{
})
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"
},
@ -176,4 +150,5 @@ local embed = command("embed",{
end
})
plugin:add_command(embed)
plugin:load_helpdb(plugin_path.."help.lua")
return plugin