-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypereaders.lua
70 lines (59 loc) · 1.22 KB
/
Typereaders.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
69
70
local function messageTypeReader(id, msg)
local mes = nil
mes = msg.channel:getMessage(id)
if not mes and msg.guild then
for chan in msg.guild.textChannels:iter() do
local sudo = chan.messages:get(id)
if sudo then
mes = sudo
break
end
end
end
return mes
end
local function getId(str)
local val = str:match("%<[@#&]!?(%d+)%>")
if val then
str = val
end
return str
end
local function channelTypeReader(id, msg)
local chan = nil
id = getId(id)
chan = msg.client:getChannel(id)
return chan
end
local function guildTypeReader(id, msg)
return msg.client:getGuild(id)
end
local function memberTypeReader(id, msg)
local mem = nil
if msg.guild then
id = getId(id)
mem = msg.guild:getMember(id)
end
return mem
end
local function userTypeReader(id, msg)
local user = nil
id = getId(id)
msg.client:getUser(id)
return user
end
local function numberTypeReader(num)
return tonumber(num)
end
local function stringTypeReader(s)
return s
end
return {
message = messageTypeReader,
channel = channelTypeReader,
number = numberTypeReader,
string = stringTypeReader,
guild = guildTypeReader,
member = memberTypeReader,
user = userTypeReader,
}