-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.lua
More file actions
110 lines (100 loc) · 2.92 KB
/
bot.lua
File metadata and controls
110 lines (100 loc) · 2.92 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
local discordia = require('discordia')
local timer = require('timer')
local client = discordia.Client()
client:enableIntents(discordia.enums.gatewayIntent.messageContent)
client:on('ready', function()
print('Logged in as '.. client.user.username)
end)
local function parseCommand(input)
local commandTable = {}
for word in string.gmatch(input, '([^,%s]+)') do
table.insert(commandTable, word)
end
return table.remove(commandTable, 1), commandTable
end
function table.Shuffle( t )
local n = #t
for i = 1, n - 1 do
local j = math.random( i, n )
t[ i ], t[ j ] = t[ j ], t[ i ]
end
end
local function GetMedia(attachments)
local tab = {}
for k1, v1 in ipairs(attachments) do
for k2, v2 in pairs(v1) do
if type(v2) == "string" and string.sub(v2, 1, 40) == "https://media.discordapp.net/attachments" then
tab[#tab + 1] = v2
end
end
end
return tab
end
client:on('messageCreate', function(message)
local command, args = parseCommand(message.content)
local isAdmin = message.member:getPermissions():has(0x0000000000000008)
local guild = message.guild
if command == "!add_avatars" and isAdmin then
local count = 0
if not guild._avatars_tab then
guild._avatars_tab = {}
end
for k,v in ipairs(args) do
guild._avatars_tab[#guild._avatars_tab + 1] = v
end
count = count + #args
local attachments = message.attachments
if attachments then
local media = GetMedia(attachments)
for k,v in ipairs(media) do
guild._avatars_tab[#guild._avatars_tab + 1] = v
end
count = count + #media
end
if count > 1 then
message.channel:send('Avatars has been added!')
elseif count == 1 then
message.channel:send('Avatar has been added!')
else
message.channel:send('Avatars hasnt been added!')
end
end
if command == "!add_nicks" and isAdmin then
if not guild._nicks_tab then
guild._nicks_tab = {}
end
for k,v in ipairs(args) do
guild._nicks_tab[#guild._nicks_tab + 1] = v
end
if #args > 1 then
message.channel:send('Nicknames has been added!')
elseif #args == 1 then
message.channel:send('Nickname has been added!')
else
message.channel:send('Nicknames hast been added!')
end
end
if command == "!clear" and isAdmin then
guild._avatars_tab = {}
guild._nicks_tab = {}
message.channel:send('Tables has been cleared')
end
if command == "!show" and isAdmin then
if not (guild._avatars_tab or guild._nicks_tab) then message.channel:send('Not enough avatars or nicknames') return end
table.Shuffle(guild._avatars_tab)
for k,v in ipairs(guild._nicks_tab) do
timer.sleep(1000)
local avatar = guild._avatars_tab[k] or "No Avatar!!!"
message.channel:send(string.upper(v).."\n"..avatar)
end
end
if command == "!help" then
message.channel:send([[
!add_avatars - add avatars
!add_nicks - add nicknames(Example: !add_nicks Mike, Nick, Jonny)
!clear - clear nicknames and avatars table
!show - start roulette
]])
end
end)
client:run('Bot TOKEN')