-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
68 lines (52 loc) · 1.83 KB
/
main.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
65
66
67
68
--[[=============================================--
-- main.lua
-- Main bot entrypoint
--
--
-- SPDX-License-Identifier: GPL-3.0-only
-- Author: Lyrthras
--=============================================]]--
local fs = require 'fs'
---@type discordia
local discordia = require 'discordia'
require 'discordia-llslash'
local client = discordia.Client()
local util = require 'util'
local c = require 'commands'
local slashCommands = c.slashCommands
local slashHandlers = c.handlers
--=============================================--
-- Discord listeners
client:on('ready', function()
client:info("Logged in as %s", client.user.username)
local sl, err = client:bulkOverwriteApplicationCommands(slashCommands)
if not sl then
util.sendErrorToOwner(client, "Slash commands registration error: " .. err)
return client:error("Slash commands registration error: %s", err)
end
client:info("Registered %d/%d global slash commands.", #slashCommands, #sl)
end)
client:on('slashCommand', function(intr)
local command = slashHandlers[intr.data.name]
if not command then
return client:warning("Unknown slash command received: '/%s'", intr.data.name)
end
local ok, err = xpcall(command, debug.traceback, intr)
if not ok then
util.sendErrorToOwner(client, err)
return client:error("Slash command '/%s' error: %s", intr.data.name, err)
end
end)
--=============================================--
-- Process listeners
process:on('sigint', function()
print("Ctrl-C interrupt received.")
process:exit()
end)
process:on('exit', function()
print("Quitting...")
end)
--=============================================--
-- Run the bot
local token = assert(fs.readFileSync('_token.txt'), "Missing token, place bot token into _token.txt")
client:run(('Bot %s'):format(token:gsub('%s+$', '')))