Compare commits
No commits in common. "3dd57d3bdc222b2ad644b7af84613049e7453145" and "435ca7de9def8ce30a85d1ad0814535305e399a0" have entirely different histories.
3dd57d3bdc
...
435ca7de9d
|
@ -1,126 +0,0 @@
|
||||||
local replace = function(text,args)
|
|
||||||
local text = text
|
|
||||||
for k,v in pairs(args) do
|
|
||||||
text = text:gsub(k,v)
|
|
||||||
end
|
|
||||||
return text
|
|
||||||
end
|
|
||||||
|
|
||||||
local trigger = function(evtbl,args,vars)
|
|
||||||
for k,v in pairs(events.event[evtbl] or {}) do
|
|
||||||
local status,command = v.comm(args)
|
|
||||||
if status then
|
|
||||||
exec(v,replace(command,vars))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local triggerOnce = function(evname,args,vars)
|
|
||||||
for k,v in pairs(events.event[evname] or {}) do
|
|
||||||
local status,command = v.comm(args)
|
|
||||||
if status then
|
|
||||||
exec(v,replace(command,vars))
|
|
||||||
events.event[evname][k] = nil
|
|
||||||
config.events.event[evname][k] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
client:on("messageCreate",function(msg)
|
|
||||||
if (not msg.guild) or (tostring(msg.guild.id) ~= tostring(id)) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local content = msg.content
|
|
||||||
local user = msg.author.id
|
|
||||||
local channelid = msg.channel.id
|
|
||||||
local args = {
|
|
||||||
["%$USER"] = user,
|
|
||||||
["%$USERNAME"] = msg.author.name,
|
|
||||||
["%$CHANNEL"] = channelid,
|
|
||||||
["%$CONTENT"] = msg.content
|
|
||||||
}
|
|
||||||
-- @message: content, userId, channelId, $USER, $USERNAME, $CHANNEL, $CONTENT
|
|
||||||
trigger("message",{content,user,channelid},args)
|
|
||||||
-- @messageOnce: content, userId, channelId, $USER, $USERNAME, $CHANNEL, $CONTENT
|
|
||||||
triggerOnce("messageOnce",{content,user,channelid},args)
|
|
||||||
end)
|
|
||||||
|
|
||||||
client:on("userBan",function(user,guild)
|
|
||||||
if tostring(guild.id) ~= tostring(id) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
args = {
|
|
||||||
["%$USER"] = user.id,
|
|
||||||
["%$USERNAME"] = user.name
|
|
||||||
}
|
|
||||||
-- @ban: userId, $USER, $USERNAME
|
|
||||||
trigger("ban",{user.id},args)
|
|
||||||
-- @banOnce: userId, $USER, $USERNAME
|
|
||||||
triggerOnce("banOnce",{user.id},args)
|
|
||||||
end)
|
|
||||||
|
|
||||||
client:on("userUnban",function(user,guild)
|
|
||||||
if tostring(guild.id) ~= tostring(id) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
args = {
|
|
||||||
["%$USER"] = user.id,
|
|
||||||
["%$USERNAME"] = user.name
|
|
||||||
}
|
|
||||||
-- @unban: userId, $USER, $USERNAME
|
|
||||||
trigger("unban",{user.id},args)
|
|
||||||
-- @unbanOnce: userId, $USER, $USERNAME
|
|
||||||
triggerOnce("unbanOnce",{user.id},args)
|
|
||||||
end)
|
|
||||||
|
|
||||||
client:on("memberJoin", function(member)
|
|
||||||
if tostring(member.guild.id) ~= tostring(id) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
args = {
|
|
||||||
["%$USER"] = member.id,
|
|
||||||
["%$USERNAME"] = member.name,
|
|
||||||
["%$AGE"] = member.user.createdAt,
|
|
||||||
["%$DISCRIM"] = member.user.discriminator,
|
|
||||||
["%$TAG"] = member.user.tag
|
|
||||||
}
|
|
||||||
-- @join: userid, username, age, $USER, $USERNAME, $AGE, $DISCRIM, $TAG
|
|
||||||
trigger("join",{
|
|
||||||
member.id,
|
|
||||||
member.name,
|
|
||||||
member.user.createdAt
|
|
||||||
},args)
|
|
||||||
-- @joinOnce: userid, username, age, $USER, $USERNAME, $AGE, $DISCRIM, $TAG
|
|
||||||
triggerOnce("joinOnce",{
|
|
||||||
member.id,
|
|
||||||
member.name,
|
|
||||||
member.user.createdAt
|
|
||||||
},args)
|
|
||||||
end)
|
|
||||||
|
|
||||||
client:on("memberLeave", function(member)
|
|
||||||
if tostring(member.guild.id) ~= tostring(id) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
args = {
|
|
||||||
["%$USER"] = member.id,
|
|
||||||
["%$USERNAME"] = member.name,
|
|
||||||
["%$AGE"] = member.user.createdAt,
|
|
||||||
["%$DISCRIM"] = member.user.discriminator,
|
|
||||||
["%$TAG"] = member.user.tag,
|
|
||||||
["%$GUILDTIME"] = member.joinedAt,
|
|
||||||
["%$ROLE"] = member.highestRole.name,
|
|
||||||
}
|
|
||||||
--@leave: userid, username, role, $USER, $USERNAME, $AGE, $DISCRIM, $TAG, $GUILDTIME, $ROLE
|
|
||||||
trigger("leave",{
|
|
||||||
member.id,
|
|
||||||
member.name,
|
|
||||||
member.highestRole.name,
|
|
||||||
},args)
|
|
||||||
--@leave: userid, username, role, $USER, $USERNAME, $AGE, $DISCRIM, $TAG, $GUILDTIME, $ROLE
|
|
||||||
triggerOnce("leaveOnce",{
|
|
||||||
member.id,
|
|
||||||
member.name,
|
|
||||||
member.highestRole.name,
|
|
||||||
},args)
|
|
||||||
end)
|
|
|
@ -12,16 +12,12 @@ local events = {
|
||||||
local exec = function(v,command)
|
local exec = function(v,command)
|
||||||
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 timer channel: "..tostring(v.channel))
|
||||||
return
|
return
|
||||||
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 timer message: "..tostring(v.id))
|
||||||
return
|
|
||||||
end
|
|
||||||
if not msg.member then
|
|
||||||
log("ERROR","Unable to retrieve event creator: "..tostring(v.user.id))
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
command_handler:handle(fake_message(msg,{
|
command_handler:handle(fake_message(msg,{
|
||||||
|
@ -81,7 +77,7 @@ local create_event = function(msg,cronjob,create_entry)
|
||||||
type = functype
|
type = functype
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
return true,hash
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_user_events = function(author_id,page)
|
local get_user_events = function(author_id,page)
|
||||||
|
@ -153,14 +149,7 @@ for k,v in pairs(config.events.timer) do
|
||||||
if channel then
|
if channel then
|
||||||
local message = channel:getMessage(v.id)
|
local message = channel:getMessage(v.id)
|
||||||
if message then
|
if message then
|
||||||
local status,hash = create_event(message,v.comm,true)
|
create_event(message,v.comm,true)
|
||||||
--orphan events with mismatching hashes
|
|
||||||
if status and (hash ~= k) then
|
|
||||||
log("WARNING", "Hash mismatch, orpahning event.")
|
|
||||||
events.timer[k] = nil
|
|
||||||
config.events.timer[k] = nil
|
|
||||||
create_event(message,v.comm)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
log("ERROR","No message with id "..v.id)
|
log("ERROR","No message with id "..v.id)
|
||||||
end
|
end
|
||||||
|
@ -177,14 +166,7 @@ for _,evtype in pairs(config.events.event) do
|
||||||
if channel then
|
if channel then
|
||||||
local message = channel:getMessage(v.id)
|
local message = channel:getMessage(v.id)
|
||||||
if message then
|
if message then
|
||||||
local status,hash = create_event(message,v.comm,true)
|
create_event(message,v.comm,true)
|
||||||
--orphan events with mismatching hashes
|
|
||||||
if status and (hash ~= k) then
|
|
||||||
log("WARNING", "Hash mismatch, orpahning event.")
|
|
||||||
events.event[_][k] = nil
|
|
||||||
config.events.event[_][k] = nil
|
|
||||||
create_event(message,v.comm)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
log("ERROR","No message with id "..v.id)
|
log("ERROR","No message with id "..v.id)
|
||||||
end
|
end
|
||||||
|
@ -359,18 +341,28 @@ timer:on("min",function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--load events file
|
client:on("messageCreate",function(msg)
|
||||||
local fhandler = io.open("./plugins/cron/events.lua","r")
|
if (not msg.guild) or (tostring(msg.guild.id) ~= tostring(id)) then
|
||||||
local data = fhandler:read("*a")
|
return
|
||||||
fhandler:close()
|
end
|
||||||
local eventfunc = load(data,"event loader: ./plugins/cron/events.lua",nil,setmetatable({
|
local content = msg.content
|
||||||
id = id,
|
local user = msg.author.id
|
||||||
client = client,
|
local channelid = msg.channel.id
|
||||||
exec = exec,
|
for k,v in pairs(events.event.message or {}) do
|
||||||
events = events,
|
local status,command = v.comm({content,user,channelid})
|
||||||
config = config
|
if status then
|
||||||
},{__index = _G}))
|
exec(v,command)
|
||||||
eventfunc()
|
end
|
||||||
|
end
|
||||||
|
for k,v in pairs(events.event.messageOnce or {}) do
|
||||||
|
local status,command = v.comm({content,user,channelid})
|
||||||
|
if status then
|
||||||
|
exec(v,command)
|
||||||
|
events.event.messageOnce[k] = nil
|
||||||
|
config.events.event.messageOnce[k] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
timer:start(true)
|
timer:start(true)
|
||||||
return plugin
|
return plugin
|
||||||
|
|
Loading…
Reference in New Issue