-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.lua
executable file
·53 lines (43 loc) · 1.19 KB
/
channel.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
local ChannelType = require "channel_type"
local json = require "json"
Channel = {
client = nil,
guild = nil,
id = nil,
type = nil,
name = nil,
topic = nil,
nsfw = nil,
parent = nil
}
function Channel:create(o)
setmetatable(o, {__index = Channel})
return o
end
function Channel:send(options)
local acceptableTypes = {
[ChannelType.DM] = true,
[ChannelType.GROUP_DM] = true,
[ChannelType.GUILD_ANNOUNCEMENT] = true,
[ChannelType.GUILD_TEXT] = true,
[ChannelType.PRIVATE_THREAD] = true,
[ChannelType.PUBLIC_THREAD] = true
}
print(json.encode(self))
print(self.type)
print(acceptableTypes[self.type])
if acceptableTypes[self.type] ~= true then
error("Tried to send message in non-text channel")
return
end
local content = options["content"]
local embeds = options["embeds"]
for i, embed in pairs(embeds) do
embeds[i] = embed:toJSON()
end
self.client:post(string.format("/channels/%s/messages", self.id), {}, {
content = content,
embeds = embeds
})
end
return Channel