Added retries for failed cron events and updated calculate command
This commit is contained in:
parent
4cf14a6bed
commit
52e25268aa
|
@ -1 +1 @@
|
||||||
Subproject commit 23fcea17c2eb380b6a6b1ba848d5bc7ebdc38b05
|
Subproject commit e68aa525e06d8025a2976d2f93d03ad7a4f81807
|
|
@ -13,32 +13,59 @@ local events = {
|
||||||
event = {}
|
event = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
local exec = function(v,command)
|
sync_emitter:on("executeCommand",function(v,command,tried)
|
||||||
local channel = client:getChannel(v.channel)
|
local channel = client:getChannel(v.channel)
|
||||||
if not channel then
|
if not channel then
|
||||||
log("ERROR","Unable to retrieve event channel: "..tostring(v.channel))
|
log("ERROR","Unable to retrieve event channel: "..tostring(v.channel))
|
||||||
log("ERROR","Failed event: "..command)
|
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
|
return
|
||||||
|
else
|
||||||
|
log("ERROR","Tried 2 times to run the event and failed.")
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local msg = channel:getMessage(v.id)
|
local msg = channel:getMessage(v.id)
|
||||||
if not msg then
|
if not msg then
|
||||||
log("ERROR","Unable to retrieve event message: "..tostring(v.id))
|
log("ERROR","Unable to retrieve event message: "..tostring(v.id))
|
||||||
log("ERROR","Failed event: "..command)
|
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
|
return
|
||||||
|
else
|
||||||
|
log("ERROR","Tried 2 times to run the event and failed.")
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--forcefully caching the goddamn member
|
--forcefully caching the goddamn member
|
||||||
local member = msg.guild:getMember(v.user)
|
local member = msg.guild:getMember(v.user)
|
||||||
if not member then
|
if not member then
|
||||||
log("ERROR","Unable to retrieve event creator: "..tostring(v.user))
|
log("ERROR","Unable to retrieve event creator: "..tostring(v.user))
|
||||||
log("ERROR","Failed event: "..command)
|
log("ERROR","Failed event: "..command)
|
||||||
|
if not tried then
|
||||||
|
log("INFO","Retrying...")
|
||||||
|
timer.setTimeout(2000,function()
|
||||||
|
sync_emitter:emit("executeCommand",v,command,true)
|
||||||
|
end)
|
||||||
return
|
return
|
||||||
|
else
|
||||||
|
log("ERROR","Tried 2 times to run the event and failed.")
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
command_handler:handle(fake_message(msg,{
|
command_handler:handle(fake_message(msg,{
|
||||||
delete = function() end,
|
delete = function() end,
|
||||||
member = member,
|
member = member,
|
||||||
content = command
|
content = command
|
||||||
}),1)
|
}),1)
|
||||||
end
|
end)
|
||||||
|
|
||||||
if not config.events then
|
if not config.events then
|
||||||
config.events = {
|
config.events = {
|
||||||
|
@ -328,7 +355,7 @@ timer:on("min",function()
|
||||||
for k,v in pairs(events.timer) do
|
for k,v in pairs(events.timer) do
|
||||||
local status,command = v.comm(os.date("*t"))
|
local status,command = v.comm(os.date("*t"))
|
||||||
if status then
|
if status then
|
||||||
exec(v,command)
|
sync_emitter:emit("executeCommand",v,command)
|
||||||
if v.type == "onetime" then
|
if v.type == "onetime" then
|
||||||
events.timer[k] = nil
|
events.timer[k] = nil
|
||||||
config.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({
|
local eventfunc = load(data,"event loader: "..plugin_path.."/events.lua",nil,setmetatable({
|
||||||
id = id,
|
id = id,
|
||||||
event_emitter = event_emitter,
|
event_emitter = event_emitter,
|
||||||
exec = exec,
|
exec = function(v,command)
|
||||||
|
sync_emitter:emit("executeCommand",v,command)
|
||||||
|
end,
|
||||||
events = events,
|
events = events,
|
||||||
config = config,
|
config = config,
|
||||||
discordia = discordia
|
discordia = discordia
|
||||||
|
|
|
@ -7,7 +7,12 @@ return {
|
||||||
fields = {
|
fields = {
|
||||||
{name = "Usage",value = [[calculate "<expression>"]]},
|
{name = "Usage",value = [[calculate "<expression>"]]},
|
||||||
{name = "Perms: ",value = "All"},
|
{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",
|
["pfp"] = "Show the profile picture of a user, or if none is specified, of yourself",
|
||||||
|
|
|
@ -104,7 +104,30 @@ local calculate = command("calculate",{
|
||||||
"string"
|
"string"
|
||||||
},
|
},
|
||||||
exec = function(msg,args,opts)
|
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,
|
end,
|
||||||
})
|
})
|
||||||
plugin:add_command(calculate)
|
plugin:add_command(calculate)
|
||||||
|
|
Loading…
Reference in New Issue