Compare commits

..

No commits in common. "435ca7de9def8ce30a85d1ad0814535305e399a0" and "14e859fd45281226ece45589ea35951b7f273349" have entirely different histories.

1 changed files with 53 additions and 133 deletions

View File

@ -40,7 +40,7 @@ local create_event = function(msg,cronjob,create_entry)
msg:reply(functype) msg:reply(functype)
return false return false
end end
local hash = md5.sumhexa(msg.author.id..arg) local hash = md5.sumhexa(arg):sub(1,16)
if functype == "directive" then if functype == "directive" then
local event_name = arg:match("^@(%w+)") local event_name = arg:match("^@(%w+)")
if not events.event[event_name] then events.event[event_name] = {} end if not events.event[event_name] then events.event[event_name] = {} end
@ -80,69 +80,6 @@ local create_event = function(msg,cronjob,create_entry)
return true return true
end 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
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
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 -- load timer events
for k,v in pairs(config.events.timer) do for k,v in pairs(config.events.timer) do
local channel = client:getChannel(v.channel) local channel = client:getChannel(v.channel)
@ -228,10 +165,38 @@ local events_comm = command("events",{
{name = "Perms:",value = "any"}, {name = "Perms:",value = "any"},
} }
}}, }},
args = {
"number"
},
exec = function(msg,args,opts) exec = function(msg,args,opts)
args[1] = tonumber(args[1]) or 1 local uevents = {}
local upto = args[1]*5 local uhashes = {}
local uevents,uhashes = get_user_events(msg.author.id,args[1]) 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
local message = {embed = { local message = {embed = {
title = "Your events: ", title = "Your events: ",
description = "", description = "",
@ -243,50 +208,13 @@ local events_comm = command("events",{
if not uhashes[I] then if not uhashes[I] then
break break
end end
message.embed.description = message.embed.description.."["..uhashes[I].."]:\n`"..uevents[I].comm.."`\n" message.embed.description = message.embed.description.."["..uhashes[I].."] `"..uevents[I].comm.."`\n"
end end
msg:reply(message) msg:reply(message)
end end
}) })
plugin:add_command(events_comm) 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",{ local remove_event= command("remove-event",{
help = {embed={ help = {embed={
title = "Remove an event", title = "Remove an event",
@ -300,33 +228,28 @@ local remove_event= command("remove-event",{
"string" "string"
}, },
exec = function(msg,args,opts) exec = function(msg,args,opts)
return remove_user_event(msg.author.id,args[1]) 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
end end
}) })
plugin:add_command(remove_event) 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() local timer = discordia.Clock()
timer:on("min",function() timer:on("min",function()
for k,v in pairs(events.timer) do for k,v in pairs(events.timer) do
@ -356,11 +279,8 @@ client:on("messageCreate",function(msg)
end end
for k,v in pairs(events.event.messageOnce or {}) do for k,v in pairs(events.event.messageOnce or {}) do
local status,command = v.comm({content,user,channelid}) local status,command = v.comm({content,user,channelid})
if status then events.event.messageOnce[k] = nil
exec(v,command) config.events.event.messageOnce[k] = nil
events.event.messageOnce[k] = nil
config.events.event.messageOnce[k] = nil
end
end end
end) end)