This commit is contained in:
Yessiest 2022-05-20 21:52:22 +04:00
parent 3dd57d3bdc
commit 38c9e580b9
12 changed files with 645 additions and 738 deletions

View File

@ -11,15 +11,15 @@ function command_acl:check_group(roles)
local highest_role = nil
local highest_role_status = nil
for k,v in pairs(roles) do
if self.group_rules[v.id] then
if self.group_rules[tostring(v.id)] then
found = true
if not highest_role then
highest_role = v
highest_role_status = self.group_rules[v.id]
highest_role_status = self.group_rules[tostring(v.id)]
end
if v.position > highest_role.position then
highest_role = v
highest_role_status = self.group_rules[v.id]
highest_role_status = self.group_rules[tostring(v.id)]
end
end
end

View File

@ -7,6 +7,7 @@ local command = class("Command")
local acl = import("classes.command-acl")
local discordia = import("discordia")
function command:__init(name,callback)
assert(name:match("^[-_%w]+$"),"Name can only contain alphanumeric characters, underscores or dashes")
self.rules = acl()
self.name = name
self.timer = discordia.Date():toMilliseconds()
@ -14,8 +15,7 @@ function command:__init(name,callback)
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 and if regex isn't enabled, check for prefix at the start. if not, don't check for prefix
regex = false, --check if the message matches this regular expression (should be a string)
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
}
@ -35,12 +35,8 @@ function command:__init(name,callback)
self.rules:set_group_rule(k,v)
end
end
if callback.perms then
self.rules:set_perm_rules(callback.perms)
end
if callback.help then
self:set_help(callback.help,callback.usage)
end
callback.perms = callback.perms and self.rules:set_perm_rules(callback.perms)
callback.help = callback.help and self:set_help(callback.help,callback.usage)
elseif type(callback) == "function" then
self.callback = callback
end
@ -61,10 +57,7 @@ function command:generate_help(description,usage)
else
backup_usage_str = "not defined"
end
local permissions = table.concat(self.rules:export_snapshot()["perms"] or {},"\n")
if permissions == "" then
permissions = "All"
end
local permissions = table.concat(self.rules:export_snapshot()["perms"] or {"All"},"\n")
self.help = {embed = {
title = "Help for ``"..self.name.."``",
description = description,
@ -77,12 +70,12 @@ function command:generate_help(description,usage)
end
--set the help message to be sent
function command:set_help(obj,usage)
if type(obj) == "string" then
self:generate_help(obj,usage)
elseif type(obj) == "table" then
if type(obj) == "table" then
self.help = obj
else
error("Type "..type(obj).." cannot be set as a help message")
self:generate_help(obj,
(type(usage) == "string" and usage)
or "No description provided.")
end
return self
end
@ -106,13 +99,13 @@ function command:check_permissions(message)
end
if discordia.Date():toMilliseconds()-self.options.timeout < self.timer then
if self.timeout_callback then
self.timeout_callback(fn)
self.timeout_callback(message)
return false
end
end
self.timer = discordia.Date():toMilliseconds()
if self.rules:check_user(message.author.id) then
local found,allow = self.rules:check_user(message.author.id)
if self.rules:check_user(tostring(message.author.id)) then
local found,allow = self.rules:check_user(tostring(message.author.id))
return allow
end
if self.rules:check_group(message.member.roles) then
@ -131,13 +124,8 @@ function command:exec(message,args,opts)
if self.decorator then
self.callback = self.decorator(self.callback)
end
local content
if self.options.regex then
content = message.content
else
local strstart,strend = message.content:find(self.name,1,true)
content = message.content:sub(strend+1,-1)
end
if self:check_permissions(message) then
if self.options.typing_decorator then
message.channel:broadcastTyping()
@ -147,23 +135,19 @@ function command:exec(message,args,opts)
local callst,status,response = pcall(self.callback,message,args,opts)
if callst then
if type(status) == "boolean" then
if status then
message:addReaction("")
else
message:addReaction("")
message:addReaction((status and "") or "")
end
return
end
else
message:addReaction("⚠️")
message:reply("An internal error occured: "..status)
return
end
else
message:addReaction("")
message:reply(err)
return
end
else
message:addReaction("")
end
end
--add decorators for the callback
function command:set_decorator(fn)

View File

@ -1,12 +0,0 @@
local interface = {}
interface.wrapper = function(client,guild_id)
local new_i = {}
new_i.message = {}
new_i.message.get = function(channel,id)
local new_m = {}
local message = client.getMessage(id)
local new_m.content = message.content
local new_m.created_at = message.createdAt
local new_m.attachments = {}
for k,v in pairs(message.attachments) do
table.insert(new_m

View File

@ -1,90 +0,0 @@
local RPC_server = import("classes.RPC-server")
local class = import("classes.baseclass")
local monitor = class("Monitor")
--we only generate proxies as far as 1 object deep.
--to provide seamlessness, metamethods that request object proxies from their
--pointers may be used on the client side
--pointers here mean tables that contain the __id and __type properties.
--they do not hold any info on the object besides its class name and id
--a lookup table of all classes that we do not ignore. we exclude client and containers
--because they might break the sandboxing. we *do not* want that.
local allowed_types = {
["guild"] = true,
["member"] = true,
["emoji"] = true,
["message"] = true,
["channel"] = true,
["role"] = true,
["user"] = true,
["invite"] = true,
["guildtextchannel"] = true,
["textchannel"] = true,
["iterable"] = true,
["cache"] = true,
["arrayiterable"] = true,
["filteretediterable"] = true,
["secondarycache"] = true,
["weakcache"] = true,
["tableiterable"] = true,
}
--a lookup table of classes that can be explicitly converted to arrays.
local iterable_types = {
["iterable"] = true,
["cache"] = true,
["arrayiterable"] = true,
["filteretediterable"] = true,
["secondarycache"] = true,
["weakcache"] = true,
["tableiterable"] = true,
}
local comprehend_object = function(object)
local output
if (type(object) == "table") and (object.__class) then
--our object is an instance of a class
local class = object.__class.__name:lower()
if allowed_types[class] and (not iterable_types[class]) then
--our object can only be pointed to
output = {__id = object[k].id, __type = class}
else
--our object can be converted to an array
end
else
--our object is either an atomic data type, a string or a table.
end
end
local create_proxy = function(object)
local output = {}
for k,v in pairs(getmetatable(object).__getters) do
end
end
local proto_api = {
msg = {
get = function(channel,id)
channel:getMessage(id)
end,
},
guild = {
},
member = {
},
channel = {
}
}
function monitor:__init(guild,options)
assert(guild,"No guild provided")
assert(options,"No options provided (arg 2)")

View File

@ -7,4 +7,29 @@ local save = command("save",{
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
},
exec = function(msg)
msg:reply([[o no he's hot]])
end
})
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)
return plugin