-
Notifications
You must be signed in to change notification settings - Fork 0
/
guild.lua
executable file
·52 lines (42 loc) · 1.05 KB
/
guild.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
local ChannelType = require "channel_type"
local Channel = require "channel"
Guild = {
unavailable = false,
client = nil,
id = nil,
name = nil,
owner = nil,
roles = {},
emojis = {},
channels = {}
}
function Guild:create(o)
setmetatable(o, {__index = Guild})
o:fetchChannels()
return o
end
function Guild:fetchChannels()
local response = self.client:get(string.format("/guilds/%s/channels", self.id))
for _, v in pairs(response) do
self.channels[v.id] = Channel:create {
client = self.client,
guild = self,
id = v.id,
name = v.name,
nsfw = v.nsfw,
parent = v.parent_id,
topic = v.topic,
type = v.type
}
end
for _, v in pairs(self.channels) do
local function loop()
if v.parent == nil then
return
end
v.parent = self.channels[v.parent]
end
loop()
end
end
return Guild