Added luaqalc library
This commit is contained in:
parent
f8e856d3ae
commit
0c463f9340
|
@ -2,3 +2,4 @@
|
|||
/servers
|
||||
/discordia.log
|
||||
/gateway.json
|
||||
*.so
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
[submodule "libraries/libraries/luaqalc"]
|
||||
path = libraries/libraries/luaqalc
|
||||
url = https://512mb.org/git/Yessiest/luaqalculator
|
||||
[submodule "libraries/luaqalc"]
|
||||
path = libraries/luaqalc
|
||||
url = https://512mb.org/git/Yessiest/luaqalculator
|
33
bot.lua
33
bot.lua
|
@ -13,21 +13,6 @@ local servers = {}
|
|||
local server = import("classes.server-handler")
|
||||
client:on("ready",function()
|
||||
print("starting test")
|
||||
if not servers["766606858667950091"] then
|
||||
servers["766606858667950091"] = server(client,client:getGuild("766606858667950091"),{
|
||||
path = os.getenv("HOME").."/bot-savedata/766606858667950091/",
|
||||
autosave_frequency = 20,
|
||||
default_plugins = {
|
||||
"meta",
|
||||
"help",
|
||||
"plugins",
|
||||
"esolang",
|
||||
"tools",
|
||||
"reactions",
|
||||
"roledefaults"
|
||||
}
|
||||
})
|
||||
end
|
||||
if not servers["640251445949759499"] then
|
||||
servers["640251445949759499"] = server(client,client:getGuild("640251445949759499"),{
|
||||
path = os.getenv("HOME").."/bot-savedata/640251445949759499/",
|
||||
|
@ -39,22 +24,8 @@ client:on("ready",function()
|
|||
"esolang",
|
||||
"tools",
|
||||
"reactions",
|
||||
"roledefaults"
|
||||
}
|
||||
})
|
||||
end
|
||||
if not servers["946474639364849704"] then
|
||||
servers["946474639364849704"] = server(client,client:getGuild("946474639364849704"),{
|
||||
path = os.getenv("HOME").."/bot-savedata/946474639364849704/",
|
||||
autosave_frequency = 20,
|
||||
default_plugins = {
|
||||
"meta",
|
||||
"help",
|
||||
"plugins",
|
||||
"esolang",
|
||||
"tools",
|
||||
"reactions",
|
||||
"roledefaults"
|
||||
"roledefaults",
|
||||
"security"
|
||||
}
|
||||
})
|
||||
end
|
||||
|
|
|
@ -127,7 +127,7 @@ function command:exec(message,args,opts)
|
|||
local exec = self.callback
|
||||
if not self.callback then
|
||||
error("Callback not set for command "..self.name)
|
||||
end
|
||||
end
|
||||
if self.decorator then
|
||||
self.callback = self.decorator(self.callback)
|
||||
end
|
||||
|
@ -139,12 +139,30 @@ function command:exec(message,args,opts)
|
|||
content = message.content:sub(strend+1,-1)
|
||||
end
|
||||
if self:check_permissions(message) then
|
||||
if self.options.typing_decorator then
|
||||
message.channel:broadcastTyping()
|
||||
end
|
||||
local status,args,opts,err = import("air").parse(content,self.args,message.client,message.guild.id)
|
||||
if status then
|
||||
self.callback(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("❌")
|
||||
end
|
||||
end
|
||||
else
|
||||
message:addReaction("⚠️")
|
||||
message:reply("An internal error occured: "..status)
|
||||
end
|
||||
else
|
||||
message:addReaction("❌")
|
||||
message:reply(err)
|
||||
end
|
||||
else
|
||||
message:addReaction("❌")
|
||||
end
|
||||
end
|
||||
--add decorators for the callback
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 5e1105631195255e8305fcaba6d37d167e9bd897
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 5e1105631195255e8305fcaba6d37d167e9bd897
|
|
@ -250,11 +250,11 @@ local c_server = command("server", {
|
|||
title = msg.guild.name,
|
||||
description = msg.guild.description,
|
||||
fields = {
|
||||
{name = "Members",value = msg.guild.totalMemberCount,inline = true},
|
||||
{name = "Owner",value = (msg.guild.owner and msg.guild.owner.user.tag..":"..msg.guild.owner.user.id),inline = true},
|
||||
{name = "Created At",value = os.date("!%c",msg.guild.createdAt).." (UTC+0)",inline = true},
|
||||
{name = "Text Channels",value = msg.guild.textChannels:count(),inline = true},
|
||||
{name = "Voice Channels",value = msg.guild.voiceChannels:count(),inline = true}
|
||||
{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,
|
||||
|
|
|
@ -46,7 +46,7 @@ local pivot = command("pivot",{
|
|||
local message = args[1]
|
||||
if not message then
|
||||
msg:reply("Couldn't find message with id "..args[2])
|
||||
return nil
|
||||
return false
|
||||
end
|
||||
if not segment.pivots[message.id] then
|
||||
print("[REACTIONS] Creating pivot: "..tostring(message.id))
|
||||
|
@ -56,7 +56,7 @@ local pivot = command("pivot",{
|
|||
segment.pivots[message.id].buttons = {}
|
||||
end
|
||||
segment.pivot = segment.pivots[message.id]
|
||||
msg:reply("Pivot message set to "..message.link)
|
||||
return true
|
||||
end
|
||||
})
|
||||
plugin:add_command(pivot)
|
||||
|
@ -80,18 +80,18 @@ local role_toggle = command("role-toggle",{
|
|||
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 nil
|
||||
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 nil
|
||||
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 nil
|
||||
return false
|
||||
end
|
||||
print("[REACTIONS] Adding role-toggle listener")
|
||||
local grabEmoji = function(reaction)
|
||||
|
@ -99,13 +99,15 @@ local role_toggle = command("role-toggle",{
|
|||
type = "role-toggler",
|
||||
role = tostring(args[2].id)
|
||||
}
|
||||
msg:reply("Role toggler added successfully")
|
||||
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
|
||||
})
|
||||
|
@ -126,24 +128,24 @@ local remove_reaction = command("remove-reaction",{
|
|||
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 nil
|
||||
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 nil
|
||||
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
|
||||
msg:reply("Action successfully removed")
|
||||
return true
|
||||
else
|
||||
message:clearReactions()
|
||||
segment.pivots[tostring(message.id)] = nil
|
||||
segment.pivot = nil
|
||||
msg:reply("Pivot successfully removed")
|
||||
return true
|
||||
end
|
||||
end
|
||||
})
|
||||
|
@ -168,18 +170,18 @@ local toggle = command("toggle",{
|
|||
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 nil
|
||||
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 nil
|
||||
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 nil
|
||||
return false
|
||||
end
|
||||
print("[REACTIONS] Adding toggle listener")
|
||||
local grabEmoji = function(reaction)
|
||||
|
@ -188,13 +190,15 @@ local toggle = command("toggle",{
|
|||
on = args[2],
|
||||
off = args[3],
|
||||
}
|
||||
msg:reply("Toggler added successfully")
|
||||
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
|
||||
})
|
||||
|
@ -218,18 +222,18 @@ local button = command("button",{
|
|||
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 nil
|
||||
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 nil
|
||||
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 nil
|
||||
return false
|
||||
end
|
||||
print("[REACTIONS] Adding button listener")
|
||||
local grabEmoji = function(reaction)
|
||||
|
@ -237,13 +241,15 @@ local button = command("button",{
|
|||
type = "button",
|
||||
on = args[2],
|
||||
}
|
||||
msg:reply("Button added successfully")
|
||||
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
|
||||
})
|
||||
|
@ -252,7 +258,7 @@ plugin:add_command(button)
|
|||
local buttonOn = function(message,hash,userID)
|
||||
if not message then
|
||||
log("ERROR","Attempted to find a deleted message")
|
||||
return
|
||||
return
|
||||
end
|
||||
if segment.pivots[tostring(message.id)] and userID ~= client.user.id then
|
||||
local current_pivot = segment.pivots[tostring(message.id)]
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
local pluginc = import("classes.plugin")
|
||||
local command = import("classes.command")
|
||||
local sql = import("sqlite3")
|
||||
local plugin = pluginc("help")
|
||||
|
||||
local db = sql.open(server.config_path.."sec.sqlite")
|
||||
|
||||
if not db:rowexec("SELECT name FROM sqlite_master WHERE type='table' AND name='infractions'") then
|
||||
db:exec [[
|
||||
CREATE TABLE infractions(id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, desc TEXT, action TEXT, timestamp INTEGER);
|
||||
]]
|
||||
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"
|
||||
},
|
||||
args = {
|
||||
"role"
|
||||
},
|
||||
exec = function(msg,args,opts)
|
||||
return ((args[2] and msg.guild:getMember(args[2])) or msg.member):addRole(args[1])
|
||||
end
|
||||
})
|
||||
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"
|
||||
},
|
||||
args = {
|
||||
"role"
|
||||
},
|
||||
exec = function(msg,args,opts)
|
||||
return ((args[2] and msg.guild:getMember(args[2])) or msg.member):removeRole(args[1])
|
||||
end
|
||||
})
|
||||
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 = "kick_members"},
|
||||
}
|
||||
}},
|
||||
perms = {
|
||||
"kick_members"
|
||||
},
|
||||
args = {
|
||||
"member",
|
||||
"string"
|
||||
},
|
||||
exec = function(msg,args,opts)
|
||||
local warnst = db:prepare("INSERT INTO infractions VALUES(NULL, ?,?,?, date())")
|
||||
warnst:reset():bind(tostring(args[1].id),args[2],"warn"):step()
|
||||
local countst = db:prepare("SELECT COUNT(*) FROM infractions WHERE user=?")
|
||||
local v = countst:reset():bind(tostring(args[1].id)):step()
|
||||
msg:reply({embed = {
|
||||
title = "User has been warned successfully",
|
||||
description = args[1].name.." has been given out a warning.",
|
||||
fields = {
|
||||
{ name = "Warning count: ", value = tostring(tonumber(v[1])) },
|
||||
{ name = "Reason: ", value = args[2] },
|
||||
{ name = "Timestamp: ", value = os.date("%a %b %e %H:%M:%S %Y",os.time(os.date("!*t"))) }
|
||||
},
|
||||
}})
|
||||
end
|
||||
})
|
||||
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> [<page>]"},
|
||||
{name = "Perms: ", value = "kick_members"},
|
||||
]]
|
||||
return plugin
|
|
@ -161,14 +161,21 @@ local pfp = command("pfp",{
|
|||
})
|
||||
plugin:add_command(pfp)
|
||||
local markov = command("markov",{
|
||||
help = "Generate some text using markov chains",
|
||||
usage = "markov <text to start with>",[[
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue