Browse Source

Added retries for failed cron events and updated calculate command

main
Yessiest 2 years ago
parent
commit
52e25268aa
  1. 2
      libraries/luaqalc
  2. 47
      plugins/cron/init.lua
  3. 7
      plugins/tools/help.lua
  4. 25
      plugins/tools/init.lua

2
libraries/luaqalc

@ -1 +1 @@
Subproject commit 23fcea17c2eb380b6a6b1ba848d5bc7ebdc38b05
Subproject commit e68aa525e06d8025a2976d2f93d03ad7a4f81807

47
plugins/cron/init.lua

@ -13,32 +13,59 @@ local events = {
event = {}
}
local exec = function(v,command)
sync_emitter:on("executeCommand",function(v,command,tried)
local channel = client:getChannel(v.channel)
if not channel then
log("ERROR","Unable to retrieve event channel: "..tostring(v.channel))
log("ERROR","Failed event: "..command)
return
log("ERROR","Failed event: "..command.."\nChannel Object: "..tostring(channel))
if not tried then
log("INFO","Retrying...")
timer.setTimeout(2000,function()
sync_emitter:emit("executeCommand",v,command,true)
end)
return
else
log("ERROR","Tried 2 times to run the event and failed.")
return
end
end
local msg = channel:getMessage(v.id)
if not msg then
log("ERROR","Unable to retrieve event message: "..tostring(v.id))
log("ERROR","Failed event: "..command)
return
log("ERROR","Failed event: "..command.."\nMessage object: "..tostring(msg).."\nChannel: "..tostring(channel.id))
if not tried then
log("INFO","Retrying...")
timer.setTimeout(2000,function()
sync_emitter:emit("executeCommand",v,command,true)
end)
return
else
log("ERROR","Tried 2 times to run the event and failed.")
return
end
end
--forcefully caching the goddamn member
local member = msg.guild:getMember(v.user)
if not member then
log("ERROR","Unable to retrieve event creator: "..tostring(v.user))
log("ERROR","Failed event: "..command)
return
if not tried then
log("INFO","Retrying...")
timer.setTimeout(2000,function()
sync_emitter:emit("executeCommand",v,command,true)
end)
return
else
log("ERROR","Tried 2 times to run the event and failed.")
return
end
end
command_handler:handle(fake_message(msg,{
delete = function() end,
member = member,
content = command
}),1)
end
end)
if not config.events then
config.events = {
@ -328,7 +355,7 @@ timer:on("min",function()
for k,v in pairs(events.timer) do
local status,command = v.comm(os.date("*t"))
if status then
exec(v,command)
sync_emitter:emit("executeCommand",v,command)
if v.type == "onetime" then
events.timer[k] = nil
config.events.timer[k] = nil
@ -344,7 +371,9 @@ fhandler:close()
local eventfunc = load(data,"event loader: "..plugin_path.."/events.lua",nil,setmetatable({
id = id,
event_emitter = event_emitter,
exec = exec,
exec = function(v,command)
sync_emitter:emit("executeCommand",v,command)
end,
events = events,
config = config,
discordia = discordia

7
plugins/tools/help.lua

@ -7,7 +7,12 @@ return {
fields = {
{name = "Usage",value = [[calculate "<expression>"]]},
{name = "Perms: ",value = "All"},
{name = "Options",value = "`-e` - exact mode"}
{name = "Options",value = [[
`-e` - exact mode (try to be as exact as possible)
`-i` - interval mode (imprecise numbers will be calculated using variance formula)
`-f` - factorize mode (factorize result, default behaviour is to expand result)
`-o` - output only (don't show embed and messages)
]]}
}
}},
["pfp"] = "Show the profile picture of a user, or if none is specified, of yourself",

25
plugins/tools/init.lua

@ -104,7 +104,30 @@ local calculate = command("calculate",{
"string"
},
exec = function(msg,args,opts)
msg:reply(qalculator.qalc(table.concat(args," "),opts["e"]))
local e,i,f = opts["e"],opts["i"],opts["f"]
local result = {embed = {
title = "Result",
fields = {
{name = "Value: ",value = nil},
},
footer = {
text = "Powered by libqalculate"
},
color = discordia.Color.fromHex("7A365F").value
}}
local value,err = qalculator.qalc(table.concat(args," "),e,i,f)
result.embed.fields[1].value = "```"..value.."```"
if opts["o"] then
msg:reply(value)
return
end
if #err > 0 then
result.embed.fields[2] = {
name = "Messages: ",
value = "```"..table.concat(err,"\n").."```"
}
end
msg:reply(result)
end,
})
plugin:add_command(calculate)

Loading…
Cancel
Save