This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
64 lines (48 loc) · 1.68 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
_G.config = require('loadconfig')
---@type discordia
_G.discordia = require('discordia')
_G.p = require('pretty-print-discordia').prettyPrint
_G.bot = discordia.Client{logFile=config.bools.noLogFile and '' or 'bot.log', cacheAllMembers = true}
_G.tles = require("tles")
_G.e = tles.emoji.index
local patts = tles.patts
local dofile = require("dofile")
local l = require("lpeg")
local gprefix = config.prefix
local cmdPatt = patts.s^0 * l.C(patts.w^1) * patts.s^0 * l.C(l.P(1)^0)
local function detectCommand(message)
local content = message.content
if tles.startswith(content, gprefix) then
local command, trail = l.match(cmdPatt, content, #gprefix+1)
if command then
return command:lower(), trail ~= '' and trail or nil
end
end
return nil
end
local function runCommand(path, message, ...)
local ok, err = pcall(dofile, './cmds/'..path)
if ok then ok, err = pcall(err, message, ...) end
if not ok then
message:reply("command failed, reason: "..err)
end
end
local function canReply(message)
local user = message.author
return (message.type == 0 and user ~= user.client.user)
end
bot:on('ready', function()
print('Logged in as '.. bot.user.username)
_G.starttime = os.time()
end)
bot:on('messageCreate', function(message)
if not canReply(message) then return end
local command, trail = detectCommand(message)
if not command then return end
if command == 'gjrng' or command == 'ask' or command == 'uptime' or command == 'thumbsup' or command == 'saxophone' or command == 'emojipack' or command == 'exec' then
runCommand(command,message,trail)
end
end)
--repl
if config.bools.webserver then tles.keepAlive.start() end
bot:run('Bot '..(config.token))