Added some more commands to cron

This commit is contained in:
Yessiest 2022-05-18 02:05:53 +04:00
parent 14e859fd45
commit 121e1ec6d1
1 changed files with 132 additions and 51 deletions

View File

@ -40,7 +40,7 @@ local create_event = function(msg,cronjob,create_entry)
msg:reply(functype)
return false
end
local hash = md5.sumhexa(arg):sub(1,16)
local hash = md5.sumhexa(msg.author.id..arg)
if functype == "directive" then
local event_name = arg:match("^@(%w+)")
if not events.event[event_name] then events.event[event_name] = {} end
@ -80,6 +80,73 @@ local create_event = function(msg,cronjob,create_entry)
return true
end
local get_user_events = function(author_id,page)
local uevents = {}
local uhashes = {}
local upto = 5*page
for k,v in pairs(config.events.timer) do
if v.user == tostring(author_id) then
table.insert(uevents,v)
table.insert(uhashes,k)
end
if #events == upto then
break
end
end
local stop = false
for _,evtype in pairs(config.events.event) do
for k,v in pairs(evtype) do
if v.user == tostring(author_id) then
table.insert(uevents,v)
table.insert(uhashes,k)
end
if #events == upto then
stop = true
break
end
end
if stop then
break
end
end
return uevents,uhashes
end
local function compids(id1,id2)
id1 = tostring(id1)
id2 = tostring(id2)
if id2:match("^%w+%*") then
local partid = id2:match("%w+")
return (id1:match("^"..partid.."%w*$") ~= nil)
else
return id1 == id2
end
end
local remove_user_event = function(user_id,id)
for k,v in pairs(config.events.timer) do
print(v.user,tostring(user_id))
print(k,id,compids(k,id))
if compids(k,id) and (v.user == tostring(user_id)) then
config.events.timer[k] = nil
events.timer[k] = nil
return true
end
end
for evname,evtype in pairs(config.events.event) do
for k,v in pairs(evtype) do
print(v.user,tostring(user_id))
print(k,id,compids(k,id))
if compids(k,id) and (v.user == tostring(user_id)) then
config.events.event[evname][k] = nil
events.event[evname][k] = nil
return true
end
end
end
return false
end
-- load timer events
for k,v in pairs(config.events.timer) do
local channel = client:getChannel(v.channel)
@ -165,38 +232,10 @@ local events_comm = command("events",{
{name = "Perms:",value = "any"},
}
}},
args = {
"number"
},
exec = function(msg,args,opts)
local uevents = {}
local uhashes = {}
local upto = 5*args[1]
for k,v in pairs(config.events.timer) do
if v.user == tostring(msg.author.id) then
table.insert(uevents,v)
table.insert(uhashes,k)
end
if #events == upto then
break
end
end
local stop = false
for _,evtype in pairs(config.events.event) do
for k,v in pairs(evtype) do
if v.user == tostring(msg.author.id) then
table.insert(uevents,v)
table.insert(uhashes,k)
end
if #events == upto then
stop = true
break
end
end
if stop then
break
end
end
args[1] = tonumber(args[1]) or 1
local upto = args[1]*5
local uevents,uhashes = get_user_events(msg.author.id,args[1])
local message = {embed = {
title = "Your events: ",
description = "",
@ -208,13 +247,50 @@ local events_comm = command("events",{
if not uhashes[I] then
break
end
message.embed.description = message.embed.description.."["..uhashes[I].."] `"..uevents[I].comm.."`\n"
message.embed.description = message.embed.description.."["..uhashes[I].."]:\n`"..uevents[I].comm.."`\n"
end
msg:reply(message)
end
})
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"
},
exec = function(msg,args,opts)
args[2] = tonumber(args[2]) or 1
local upto = args[2]*5
local uevents,uhashes = get_user_events(args[1].id,args[2])
local message = {embed = {
title = "Events (for user "..args[1].name.."): ",
description = "",
footer = {
text = "Events "..tostring(upto-4).." - "..tostring(upto)
}
}}
for I = upto-4,upto do
if not uhashes[I] then
break
end
message.embed.description = message.embed.description.."["..uhashes[I].."]:\n`"..uevents[I].comm.."`\n"
end
msg:reply(message)
end
})
plugin:add_command(user_events_comm)
local remove_event= command("remove-event",{
help = {embed={
title = "Remove an event",
@ -228,28 +304,33 @@ local remove_event= command("remove-event",{
"string"
},
exec = function(msg,args,opts)
for k,v in pairs(config.events.timer) do
if (k == args[1]) and (v.user == tostring(msg.author.id)) then
config.events.timer[k] = nil
events.timer[k] = nil
return true
end
end
for evname,evtype in pairs(config.events.event) do
for k,v in pairs(evtype) do
if (k == args[1]) and (v.user == tostring(msg.author.id)) then
config.events.event[evname][k] = nil
events.event[evname][k] = nil
return true
end
end
end
msg:reply("Not found")
return false
return remove_user_event(msg.author.id,args[1])
end
})
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"
},
perms = {
"administrator"
},
exec = function(msg,args,opts)
return remove_user_event(args[1].id,args[2])
end
})
plugin:add_command(remove_user_event_c)
local timer = discordia.Clock()
timer:on("min",function()
for k,v in pairs(events.timer) do