-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.lua
2135 lines (1974 loc) · 134 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--Create modules to organize code [DM commands, text channels, voice channels, global functions]
-- Text Channels
--Remove users from exclusive queue if they leave the server so time is accurate (currently waits until they're next to remove them)
--Command for statistics like messages/day, deleted/accepted ratio, count highscore, ect.
--Random event that allows you to react to 5 messages
--Use multiple suggest abilities for a longer word (20 default, +5 each ability?)
--A boss battle channel where it's all the users in the server against the channel, perhaps win an ability at the end, win gear or moves?
--A channel where you can inflict something either on the person above or below
--Fix the bot sometimes crashing but not sending a crash message on reboot
--Fix deleted messages counting towards the multi-message bypass
-- Voice Channels
--Implement way to play audio through direct link (May have to wait for Discordia 3.0)
--Do not load songs while player is paused so you can scrub through songs without a load delay
--Make speak channel reaction more obvious that it opts you in
--Make music channel controls be more obvious, perhaps an info button (maybe not necessary?)
--Fix the entire bot stalling during song download
--Fix bot "Voice connection not initialized before VOICE_SERVER_UPDATE", causing songs to download but not play
--Fix "broken pipe" error appearing in output when skipping a song ("Not possible" says someone when I asked)
--Fix first song sometimes being the last played song instead of the newly loaded one (Unknown cause)
-- Dependencies
local Discordia = require("discordia")
local Client = Discordia.Client()
local Enum = Discordia.enums
local Permissions = Discordia.Permissions()
local Json = require("json")
local Coro = require("coro-http")
local Storage = require("NewStorage")
-- Config
local DevMode = false
local BotToken = io.open("token","r"):read("*a")
local ServerId = "669338665956409374"
local OwnerId = "143172810221551616"
local SaveInterval = 5 --Minutes between bot data being saved, excluding newword selection
local SpamM, SpamS = 3, 5 --Messages/Second for Spam filter
local NewW, NewU = 3, 2 --New Random / User Suggested Words
local CountUpdate = 2 --Minutes between count message updating
local QueueInterval = 8 --Hours between admitting new user to #exclusive-channel
local ResizeMax, ResizeBias = 1000, 5
local ChannelPerms = {["type"]=Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages,Enum.permission.sendMessages),
["fuck-vowels"]=Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages,Enum.permission.sendMessages),
["fuck-everything"]=Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages,Enum.permission.sendMessages),
["message-counting"]=Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages,Enum.permission.sendMessages),
["images"]=Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages,Enum.permission.sendMessages,Enum.permission.attachFiles),
["speak"]=Permissions.fromMany(Enum.permission.readMessages,Enum.permission.connect,Enum.permission.speak,Enum.permission.useVoiceActivity)}
local StartingData = {["CheckUses"]=0,["Inventory"]={},["State"]="Normal"}
-- Variables
local storagedata = Storage:getData()
if storagedata == nil then -- If no data was loaded, populate storagedata with default values
storagedata = {
["WhitelistedWords"]={}, --{ "word1", ... }
["SuggestedWords"]={}, --{ {"userid", "word"}, ... }
["CountChannel"]={}, --{ ["Prestige"]=level, ["CountMessage"]=messageid ["Count"]=nextlength, ["LastUser"]=userid, ["Counters"]={ {UserId, Count}, ... }, ["FailedUser"]=userid, ["LastMessage"]=messageid }
["PlayerData"]={}, --{ ["UserId"]=StartingDataConfig, ... }
["WordCount"]={}, --{ {word, #ofuses}, ...}
["LastSaved"]={}, --{ timesaved, closedproperly?, silentrestart? }
["CheckUsers"]={}, --{ "userid", ... }
["ExclusiveChannel"]={}, --{ ["AdmitTime"] = timeadmitted, ["Serving"] = userid, ["Queue"] = {"userid", ... }, ["Served"] = served, ["UniqueServed"] = {userid, ...} }
["ResizeChannel"]={} --{ width, height }
}
end
local spamdata = {} --{ ["UserId"]={messagetime, ... }, ... } --Spam Detection
local commanduse = {} --{ ["UserId"]="command", ... } --Bypass ability
local lastmessage = {} --{ ["UserId"]="lastmessage", ... } --Multiple message bypass filter
local suggestbuffer = {} --{ "userid", ... } --Suggestion 60 second change
local images = {} --{ "artlink", ... } --Indexed art links
local interactedusers = {} --{ "userid", ... } --Fix mute + response before restart
-- Global Functions
local function dump(o) --Debug function for printing tables
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
print(s .. '} ')
else
return tostring(o)
end
end
local function round(num, numDecimalPlaces) --Number rounding
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
local timer = require("timer") --Wait a certain amount of seconds
local function wait(seconds)
timer.sleep(seconds*1000)
end
local function split(text) --Split all words (separated by spaces) into a table of words
local words = {}
for word in text:gmatch("%S+") do table.insert(words, word) end
return words
end
local function listItems(table,andbool) --Turns a table of strings into one string with commas and "and"s
local string = ""
if #table == 1 then
return table[1]
elseif andbool and #table == 2 then
return table[1].." and "..table[2]
end
for i, item in pairs(table) do
if andbool and i == #table then
string = string.."and "..item.."--"
else
string = string..item..", "
end
end
return string.sub(string,1,-3)
end
local function convertSeconds(seconds,desired) --Turns seconds into a readable string
local time, unit = 0, "seconds"
if not desired then
if seconds <= 60 then
time, unit = seconds, "second"
elseif seconds <= 3600 then
time, unit = round(seconds/60), "minute"
elseif seconds <= 86400 then
if round((seconds - math.floor(seconds/3600)*3600)/60) == 0 then
return math.floor(seconds/3600).." hour"..(math.floor(seconds/3600) == 1 and "" or "s").." "..round((seconds - math.floor(seconds/3600)*3600)/60).." minute"..(round((seconds - math.floor(seconds/3600)*3600)/60) == 1 and "" or "s")
else
return round(seconds/3600).." hour"..(round(seconds/3600) == 1 and "" or "s")
end
else
if round((seconds - math.floor(seconds/86400)*86400)/3600) == 0 then
return round(seconds/86400).." day"..(round(seconds/86400) == 1 and "" or "s")
else
return math.floor(seconds/86400).." day"..(math.floor(seconds/86400) == 1 and "" or "s").." "..round((seconds - math.floor(seconds/86400)*86400)/3600).." hour"..(round((seconds - math.floor(seconds/86400)*86400)/3600) == 1 and "" or "s")
end
end
elseif desired == "minutes" then
time, unit = round(seconds/60), "minute"
elseif desired == "hours" then
time, unit = round(seconds/3600,1), "hour"
elseif desired == "days" then
time, unit = round(seconds/86400,1), "day"
end
return time.." "..unit..(time == 1 and "" or "s")
end
local function inTable(table,item) --Check if an item is in a table
for i, thing in pairs(table) do
if item == thing then
return i
end
end
return false
end
local function isEmoji(string) --Check if a string would be formatted as an emoji in Discord
local words = {}
for word in string:gmatch("[^<]+") do table.insert(words, "<"..word) end
for i, word in pairs(words) do
local approved = false
for i, emoji in pairs(Server.emojis) do
if "<:"..emoji.hash..">" == word or "<a:"..emoji.hash..">" == word then
approved = true
break
end
end
if not approved then
return false
end
end
return true
end
-- Bot Functions
local function send(reciever,text,embedinfo) --Send a formatted DM/message, embedinfo formatted ["Title"] ["Color"] ["Text"] ["Image"] ["FooterImage"] ["FooterText"]
local channel = reciever
if type(reciever) == "string" then --if given userid, get DM
channel = Client:getUser(reciever):getPrivateChannel()
end
if embedinfo == nil then
return channel:send(text)
else
embedinfo["Color"] = embedinfo["Color"] or {0,255,255}
return channel:send{content=text,embed={title=embedinfo["Title"],color=Discordia.Color.fromRGB(embedinfo["Color"][1],embedinfo["Color"][2],embedinfo["Color"][3]).value,description=embedinfo["Text"],image={url=embedinfo["ImageUrl"]},footer={icon_url=embedinfo["FooterImage"],text=embedinfo["FooterText"]}}}
end
end
local function edit(message,text,embedinfo) --Edit a sent message, same embedinfo
if embedinfo == nil then
message:update(message)
else
embedinfo["Color"] = embedinfo["Color"] or {0,255,255}
message:update{content=text,embed={title=embedinfo["Title"],color=Discordia.Color.fromRGB(embedinfo["Color"][1],embedinfo["Color"][2],embedinfo["Color"][3]).value,description=embedinfo["Text"],image={url=embedinfo["ImageUrl"]},footer={icon_url=embedinfo["FooterImage"],text=embedinfo["FooterText"]},fields=((embedinfo["Inline1Name"] and embedinfo["Inline1Text"]) and {{name=embedinfo["Inline1Name"],value=embedinfo["Inline1Text"],inline=true},{name=embedinfo["Inline2Name"],value=embedinfo["Inline2Text"],inline=true}})}}
end
end
local function editembed(message,text,embedinfo) --Edit an embed, preserve all parts of message except the ones provided
if embedinfo["Color"] then
embedinfo["Color"] = Discordia.Color.fromRGB(embedinfo["Color"][1],embedinfo["Color"][2],embedinfo["Color"][3]).value
end
message:update{content=(text or message.content),embed={title=(embedinfo["Title"] or message.embed.title),color=(embedinfo["Color"] or message.embed.color),description=(embedinfo["Text"] or message.embed.description),image={url=(embedinfo["ImageUrl"] or (message.embed.image and message.embed.image.url))},footer={icon_url=(embedinfo["FooterImage"] or (message.embed.footer and message.embed.footer.icon_url)),text=(embedinfo["FooterText"] or message.embed.footer and message.embed.footer.text)},fields=((embedinfo["Inline1Name"] or embedinfo["Inline1Text"] or embedinfo["Inline2Name"] or embedinfo["Inline2Text"] or message.embed.fields) and {{name=(embedinfo["Inline1Name"] or message.embed.fields[1].name),value=(embedinfo["Inline1Text"] or message.embed.fields[1].value),inline=true},{name=(embedinfo["Inline2Name"] or message.embed.fields[2].name),value=(embedinfo["Inline2Text"] or message.embed.fields[2].value),inline=true}})}}
end
local function getResponse(channel,timeout) --Wait (timeout) seconds for a response in (channel)
local response = false
if channel.type == Enum.channelType.private then
table.insert(interactedusers,channel.recipient.id)
storagedata["PlayerData"][channel.recipient.id]["State"] = "Command"
end
if timeout ~= nil then
timeout = timeout*1000
end
Client:waitFor("messageCreate",timeout,function(message)
if message.channel == channel and not message.author.bot then
response = message.content
return true
end
end)
if channel.type == Enum.channelType.private then
table.remove(interactedusers,inTable(interactedusers,channel.recipient.id))
storagedata["PlayerData"][channel.recipient.id]["State"] = "Normal"
end
return response
end
local function updatePerms(userid,channels,permtype) --Update a user/everyone's perms for channels
local role
if userid == "everyone" then --get @everyone role if string is "everyone"
role = Server.defaultRole
else
role = Server:getMember(userid)
end
local function setRolePerms(channel)
local RolePerms = channel:getPermissionOverwriteFor(role)
local PermObject
if permtype == "on" then
if userid ~= "everyone" then
RolePerms:delete()
return
else
PermObject = ChannelPerms[channel.name]
end
elseif permtype == "off" then
PermObject = Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages)
if userid ~= "everyone" then
RolePerms:denyPermissions(Enum.permission.sendMessages)
return
end
elseif permtype == "talk" then
PermObject = Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages,Enum.permission.sendMessages)
elseif permtype == "images" then
PermObject = Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages,Enum.permission.sendMessages,Enum.permission.attachFiles)
elseif permtype == "noaccess" then
RolePerms:denyPermissions(Enum.permission.readMessages)
return
elseif permtype == "read" then
PermObject = Permissions.fromMany(Enum.permission.readMessageHistory,Enum.permission.readMessages)
elseif permtype == "clear" then
RolePerms:delete()
return
end
RolePerms:setAllowedPermissions(PermObject)
end
if type(channels) == "table" then --if given a table of channels, change perms for all of them
for i, channel in pairs(channels) do
setRolePerms(Channels[channel])
end
else
setRolePerms(Channels[channels])
end
end
local function ping(pingtype) --Ghost ping those who have opted into (pingtype) through the reactions
local PingReactions = Channels["help"]:getMessage("719779244586172458").reactions
local ReactionName, pingstring, PingUsers
if pingtype == "important" then
ReactionName, pingstring = "1️⃣", "[Important]"
elseif pingtype == "majorupdate" then
ReactionName, pingstring = "2️⃣", "[Major Update]"
elseif pingtype == "majorpoll" then
ReactionName, pingstring = "3️⃣", "[Major Poll]"
elseif pingtype == "minorupdate" then
ReactionName, pingstring = "4️⃣", "[Minor Update]"
elseif pingtype == "minorpoll" then
ReactionName, pingstring = "5️⃣", "[Minor Poll]"
elseif pingtype == "testing" then
ReactionName, pingstring = "🛠️", "[Testing]"
end
local OnlineOnlyUsers
for i, reaction in pairs(PingReactions) do
if reaction.emojiName == ReactionName then
PingUsers = reaction:getUsers() --"You must call this method again to guarantee that the objects are up to date."
PingUsers = reaction:getUsers()
end
if reaction.emojiName == "🟢" then --green circle reaction
OnlineOnlyUsers = reaction:getUsers()
OnlineOnlyUsers = reaction:getUsers()
end
end
for i, user in pairs(PingUsers) do
local onlineonly = false
for v, onlineuser in pairs(OnlineOnlyUsers) do
if onlineuser == user then
onlineonly = true
if Server:getMember(user.id) ~= nil then
if Server:getMember(user.id).status == "online" then
pingstring = pingstring.." <@"..user.id..">"
end
end
break
end
end
if not onlineonly then
pingstring = pingstring.." <@"..user.id..">"
end
end
local message = send(Channels["important"],pingstring)
wait(2)
message:delete()
end
local function spamSensor(userid,message) --Log that a user has talked, mute if talking too fast
if spamdata[userid] == nil then
spamdata[userid] = {os.time()}
return
end
local temp = {}
for i, time in pairs(spamdata[userid]) do
if (time + SpamS) > os.time() then
table.insert(temp,time)
end
end
spamdata[userid] = temp
table.insert(spamdata[userid],os.time())
if #spamdata[userid] > SpamM then
spamdata[userid] = "Muted"
table.insert(interactedusers,userid)
message:delete()
updatePerms(userid,{"type","fuck-vowels","fuck-everything","message-counting","images","speak"},"off")
send(userid,"Yikes, just got a complaint from the higher-ups:",{["Title"]="Muted for 60 seconds",["Color"]={255,0,0},["Text"]="You've sent more than "..SpamM.." messages in the past "..SpamS.." seconds.\n\nYou have exceeded the message limit. You are now muted for **60 seconds**."})
wait(60)
table.remove(interactedusers,inTable(interactedusers,userid))
spamdata[userid] = {}
updatePerms(userid,{"type","fuck-vowels","fuck-everything","message-counting","images","speak"},"on")
send(userid,"Okay, those 60 seconds are up. Be more careful next time.",{["Title"]="Unmuted",["Color"]={0,255,0},["Text"]="You have been unmuted and are allowed to type again."})
return true
end
return false
end
local function newWords() --Whitelist new words
local wordsneeded = NewW
local newwordtext = ""
local newrandomwords = {}
while wordsneeded ~= 0 do
local randomwords
local success, err = pcall(function()
local _, body = Coro.request("GET","https://random-word-api.herokuapp.com/word?number=100")
randomwords = Json.decode(body)
end)
if success then
for i, word in pairs(randomwords) do
if wordsneeded == 0 then
break
end
if not inTable(storagedata["WhitelistedWords"],word) then
wordsneeded = wordsneeded - 1
table.insert(storagedata["WhitelistedWords"],word)
table.insert(newrandomwords,"**"..word.."**")
end
end
newwordtext = listItems(newrandomwords,true).." were randomly selected and whitelisted."
else
wordsneeded = 0
newwordtext = "Random words couldn't be selected due to an API error."
end
end
local totalsubmissions = #storagedata["SuggestedWords"]
if totalsubmissions == 0 then
send(Channels["type"],"Damn, no suggestions?",{["Title"]="New Words",["Color"]={0,255,255},["Text"]="New words have been added to the whitelist.\n\n"..newwordtext.."\nNo user suggestions were collected, so none were whitelisted."})
elseif totalsubmissions == 1 then
table.insert(storagedata["WhitelistedWords"],storagedata["SuggestedWords"][1][2])
print(storagedata["SuggestedWords"][1][1].." whitelisted "..storagedata["SuggestedWords"][1][2])
send(Channels["type"],"Huh, only one submission.",{["Title"]="New Words",["Color"]={0,255,255},["Text"]="New words have been added to the whitelist.\n\n"..newwordtext.."\n**"..storagedata["SuggestedWords"][1][2].."** was the only submission."})
else
local num1 = math.random(1,totalsubmissions) -- Select the first word to be whitelisted
local word1 = storagedata["SuggestedWords"][num1][2]
print(storagedata["SuggestedWords"][num1][1].." whitelisted "..word1)
table.insert(storagedata["WhitelistedWords"],word1)
for i = #storagedata["SuggestedWords"], 1, -1 do -- Remove word from list of suggested words
if storagedata["SuggestedWords"][i][2] == word1 then
table.remove(storagedata["SuggestedWords"],i)
end
end
if NewU == 1 then
send(Channels["type"],"Here's the new words:",{["Title"]="New Words",["Color"]={0,255,255},["Text"]="New words have been added to the whitelist.\n\n"..newwordtext.."\n**"..word1.."** was selected from "..totalsubmissions.." submissions."})
elseif #storagedata["SuggestedWords"] == 0 then
send(Channels["type"],"Dang, a unanimous decision? That never happens.",{["Title"]="New Words",["Color"]={0,255,255},["Text"]="New words have been added to the whitelist.\n\n"..newwordtext.."\n**"..word1.."** was unanimously selected from "..totalsubmissions.." submissions."})
else
local newwhitelistedwords = {"**"..word1.."**"} -- Array of new whitelisted words, used for message
while #storagedata["SuggestedWords"] > 0 and #newwhitelistedwords ~= NewU do -- Whitelist remaining words and add them to the array
local num2 = math.random(1,#storagedata["SuggestedWords"])
local word2 = storagedata["SuggestedWords"][num2][2] -- Find a new word to be whitelisted
print(storagedata["SuggestedWords"][num2][1].." whitelisted "..word2)
table.insert(storagedata["WhitelistedWords"],word2) -- Adds word to whitelisted words and the new whitelisted words array
table.insert(newwhitelistedwords,"**"..word2.."**")
for i = #storagedata["SuggestedWords"], 1, -1 do -- Prevents word from being whitelisted multiple times
if storagedata["SuggestedWords"][i][2] == word2 then
table.remove(storagedata["SuggestedWords"],i)
end
end
end
if #newwhitelistedwords < NewU then -- Less than max amount was whitelisted
if #newwhitelistedwords ~= totalsubmissions then -- Less than max whitelisted, but some words were the same
send(Channels["type"],"Huh, looks like there were some identical submissions.",{["Title"]="New Words",["Color"]={0,255,255},["Text"]="New words have been added to the whitelist.\n\n"..newwordtext.."\n"..listItems(newwhitelistedwords,true).." were selected from "..totalsubmissions.." submissions."})
else
send(Channels["type"],"Darn, missed the chance for "..(NewU-#newwhitelistedwords).." word"..((NewU-#newwhitelistedwords) == 1 and "" or "s").." to be whitelisted.",{["Title"]="New Words",["Color"]={0,255,255},["Text"]="New words have been added to the whitelist.\n\n"..newwordtext.."\n"..listItems(newwhitelistedwords,true).." were the only submissions."})
end
else -- Max amount of words whitelisted
send(Channels["type"],"Here's the new words:",{["Title"]="New Words",["Color"]={0,255,255},["Text"]="New words have been added to the whitelist.\n\n"..newwordtext.."\n"..listItems(newwhitelistedwords,true).." were selected from "..totalsubmissions.." submissions."})
end
end
end
table.sort(storagedata["WhitelistedWords"])
storagedata["SuggestedWords"] = {}
end
local function randomEvent() --Calulate chance/perform a random event
local chance = math.random(1,1000)/10
local randomword = storagedata["WhitelistedWords"][math.random(1,#storagedata["WhitelistedWords"])]
if chance <= 1 then
send(Channels["type"],"Oooh, this one is a spicy ability.",{["Title"]="[1%] Event",["Color"]={0,255,255},["Text"]="A random event has appeared- these have a chance to appear every hour, according to their likelihood percentage.\n\nThe next person to say **"..randomword.."** will receive one message bypass."})
local collected = Client:waitFor("messageCreate",600*1000,function(message)
if message.channel == Channels["type"] and not message.author.bot then
if string.lower(message.content) == randomword then
table.insert(storagedata["PlayerData"][message.author.id]["Inventory"],"bypass")
send(Channels["type"],"The power is in your hands now.",{["Title"]="Event Ended",["Color"]={0,255,255},["Text"]="**"..message.author.username.."** collected the bypass ability.\n\nCheck your `inventory` to use it."})
return true
end
end
end)
if not collected then
send(Channels["type"],"Damn, there goes that bypass.",{["Title"]="Event Ended",["Color"]={0,255,255},["Text"]="No one collected the ability within 10 minutes."})
end
elseif chance <= 5 then
send(Channels["type"],"An automatically whitelisted word? Nice.",{["Title"]="[4%] Event",["Color"]={0,255,255},["Text"]="A random event has appeared- these have a chance to appear every hour, according to their likelihood percentage.\n\nThe next person to say **"..randomword.."** will be able to automatically whitelist a word."})
local collected = Client:waitFor("messageCreate",600*1000,function(message)
if message.channel == Channels["type"] and not message.author.bot then
if string.lower(message.content) == randomword then
table.insert(storagedata["PlayerData"][message.author.id]["Inventory"],"suggest")
send(Channels["type"],"Use that thing wisely.",{["Title"]="Event Ended",["Color"]={0,255,255},["Text"]="**"..message.author.username.."** collected the whitelist ability.\n\nCheck your `inventory` to use it."})
return true
end
end
end)
if not collected then
send(Channels["type"],"No one claimed it? Tough luck.",{["Title"]="Event Ended",["Color"]={0,255,255},["Text"]="No one collected the ability within 10 minutes."})
end
end
end
local function updateQueue()
if #storagedata["ExclusiveChannel"]["Queue"] > 0 then
edit(Channels["exclusive-queue"]:getLastMessage(),"",{["Title"]="Exclusive Queue",["Text"]="Welcome to the Exclusive Queue.\n\nHere you can sign up to gain access to the highly coveted <#784586406768934982>. Only one person is allowed in every "..QueueInterval.." hours.\n\nIn Queue: "..(#storagedata["ExclusiveChannel"]["Queue"]).." user"..(#storagedata["ExclusiveChannel"]["Queue"] == 1 and "" or "s").."\nCurrent Wait: **"..convertSeconds(storagedata["ExclusiveChannel"]["AdmitTime"] - os.time() + ((#storagedata["ExclusiveChannel"]["Queue"])*(QueueInterval*3600)) + (3600 - os.time()%3600)).."**\n\n🔑 to enter the queue.",["FooterText"]="Proudly served "..#storagedata["ExclusiveChannel"]["UniqueServed"].." individual"..(#storagedata["ExclusiveChannel"]["UniqueServed"] == 1 and "" or "s").." a total of "..storagedata["ExclusiveChannel"]["Served"].." time"..(storagedata["ExclusiveChannel"]["Served"] == 1 and "" or "s").."."})
else
edit(Channels["exclusive-queue"]:getLastMessage(),"",{["Title"]="Exclusive Queue",["Text"]="Welcome to the Exclusive Queue.\n\nHere you can sign up to gain access to the highly coveted <#784586406768934982>. Only one person is allowed in every "..QueueInterval.." hours.\n\nIn Queue: 0 users\nCurrent Wait: **"..convertSeconds(storagedata["ExclusiveChannel"]["AdmitTime"] - os.time() + (3600 - os.time()%3600)).."**\n\n🔑 to enter the queue.",["FooterText"]="Proudly served "..#storagedata["ExclusiveChannel"]["UniqueServed"].." individual"..(#storagedata["ExclusiveChannel"]["UniqueServed"] == 1 and "" or "s").." a total of "..storagedata["ExclusiveChannel"]["Served"].." time"..(storagedata["ExclusiveChannel"]["Served"] == 1 and "" or "s").."."})
end
end
local function admitNewUser() --Admit a new user to #exclusive-channel
storagedata["ExclusiveChannel"]["AdmitTime"] = os.time()+((QueueInterval*3600)-os.time()%(QueueInterval*3600))
if storagedata["ExclusiveChannel"]["Serving"] then
updatePerms(storagedata["ExclusiveChannel"]["Serving"],"exclusive-channel","clear")
storagedata["ExclusiveChannel"]["Served"] = storagedata["ExclusiveChannel"]["Served"] + 1
if not inTable(storagedata["ExclusiveChannel"]["UniqueServed"],storagedata["ExclusiveChannel"]["Serving"]) then
table.insert(storagedata["ExclusiveChannel"]["UniqueServed"],storagedata["ExclusiveChannel"]["Serving"])
end
storagedata["ExclusiveChannel"]["Serving"] = nil
end
if #storagedata["ExclusiveChannel"]["Queue"] > 0 then
while storagedata["ExclusiveChannel"]["Serving"] == nil and #storagedata["ExclusiveChannel"]["Queue"] > 0 do
if Server:getMember(storagedata["ExclusiveChannel"]["Queue"][1]) then
storagedata["ExclusiveChannel"]["Serving"] = storagedata["ExclusiveChannel"]["Queue"][1]
updatePerms(storagedata["ExclusiveChannel"]["Queue"][1],"exclusive-channel","images")
send(Channels["exclusive-channel"],"<@"..storagedata["ExclusiveChannel"]["Queue"][1]..">",{["Title"]="Exclusive Queue",["Text"]="<@"..storagedata["ExclusiveChannel"]["Queue"][1]..">, it is now your turn in the channel.\n\nYour "..QueueInterval.." hours start now."})
end
table.remove(storagedata["ExclusiveChannel"]["Queue"],1)
end
end
end
local wordpicktime
local function timeUntilChoice() --Gives amount of time until word selection as readable string
local minutesuntil = (wordpicktime - os.time())/60
if minutesuntil > 60 then
return round(minutesuntil/60,1).." hours"
end
return round(minutesuntil).." minutes"
end
-- Loops
coroutine.wrap(function() --Word selection loop, also resets check uses
local hourspassed = 0
while true do
wordpicktime = os.time()+(21600-(os.time()%21600))
local timeleft = wordpicktime - os.time()
print(timeleft.." - "..timeUntilChoice())
if timeleft > 10800 then
wait(timeleft - 10800)
send(Channels["type"],"Three more hours until new words are selected.")
wait(7200)
send(Channels["type"],"There is one hour left until the new words are selected, maybe `suggest` something if you haven't?")
wait(3000)
send(Channels["type"],"Ten more minutes are left until the new word selection, make sure you've suggested something.")
elseif timeleft > 3600 then
wait(timeleft - 3600)
send(Channels["type"],"There is one hour left until the new words are selected, maybe `suggest` something if you haven't?")
wait(3000)
send(Channels["type"],"Ten more minutes are left until the new word selection, make sure you've suggested something.")
elseif timeleft > 600 then
wait(timeleft - 600)
send(Channels["type"],"Ten more minutes are left until the new word selection, make sure you've suggested something.")
end
wait(3600-(os.time()%3600))
newWords()
hourspassed = hourspassed + 6
if hourspassed == 24 then
hourspassed = 0
for i, userid in pairs(storagedata["CheckUsers"]) do
storagedata["PlayerData"][userid]["CheckUses"] = 0
end
storagedata["CheckUsers"] = {}
end
end
end)()
coroutine.wrap(function() --Random selection loop
wait(3600-(os.time()%3600))
while true do
local checktime = math.random(1,5)*10
wait(checktime*60)
coroutine.wrap(randomEvent)()
wait(3600-(os.time()%3600))
end
end)()
coroutine.wrap(function() --Save data loop, checks for internet outage
if not DevMode then
local internetwasdown = false
while true do
wait(SaveInterval*60)
local internettest
if Channels ~= nil then
internettest = Channels["important"]:getLastMessage()
else
internettest = nil
end
if internettest == nil and internetwasdown then
print("Internet connection is still compromised.")
elseif internettest == nil then
print("Internet connection compromised.")
internetwasdown = true
Storage:save(storagedata)
else
internetwasdown = false
storagedata["LastSaved"][1] = os.time()
Storage:save(storagedata)
end
end
end
end)()
coroutine.wrap(function() --Count update message loop
while true do
wait((CountUpdate*60)-os.time()%(CountUpdate*60))
if Channels ~= nil then
local neednewmessage = false
if storagedata["CountChannel"]["CountMessage"] ~= nil and Channels["message-counting"] ~= nil then
local updatemessage = Channels["message-counting"]:getMessage(storagedata["CountChannel"]["CountMessage"])
if updatemessage ~= nil then
if updatemessage ~= Channels["message-counting"]:getLastMessage() or not string.match(updatemessage.content,"**"..storagedata["CountChannel"]["Count"].."**") then
updatemessage:delete()
neednewmessage = true
end
else
neednewmessage = true
end
else
neednewmessage = true
end
if neednewmessage then
if storagedata["CountChannel"]["Count"] == 1 then
storagedata["CountChannel"]["CountMessage"] = send(Channels["message-counting"],"_ _\nTo start the counting, the next message should be **1** character long.").id
else
local progressbar = ""
for i=1, math.floor(storagedata["CountChannel"]["Count"]-1)/200 do
progressbar = progressbar.."▰"
end
for i=1, 10-math.floor(storagedata["CountChannel"]["Count"]-1)/200 do
progressbar = progressbar.."▱"
end
local deletenotice = ""
if storagedata["CountChannel"]["LastMessage"] ~= "0" then
if Channels["message-counting"]:getMessage(storagedata["CountChannel"]["LastMessage"]) == nil then
deletenotice = "\n\n**Notice:** The last counter deleted their message. Use the `count` command to verify your message length."
end
end
local message = send(Channels["message-counting"],"The next message should be **"..storagedata["CountChannel"]["Count"].."** characters long.\n\nProgress to 2000:\n"..progressbar.." "..round((storagedata["CountChannel"]["Count"]-1)/20,2).."%"..deletenotice)
if message then storagedata["CountChannel"]["CountMessage"] = message.id end
end
end
end
end
end)()
coroutine.wrap(function() --Queue update message loop and Resize channel loop
if not storagedata["ExclusiveChannel"]["AdmitTime"] then
storagedata["ExclusiveChannel"]["AdmitTime"] = os.time()+((QueueInterval*3600)-(os.time()%(QueueInterval*3600)))
end
while true do
wait(3600-(os.time()%3600))
if (os.time() + 60) > storagedata["ExclusiveChannel"]["AdmitTime"] then
admitNewUser()
end
updateQueue()
storagedata["ResizeChannel"] = {math.floor(1 + (ResizeMax - 1)*(math.random()^ResizeBias)),math.floor(1 + (ResizeMax - 1)*(math.random()^ResizeBias))}
Channels["resized-images"]:setTopic(storagedata["ResizeChannel"][1].." x "..storagedata["ResizeChannel"][2])
end
end)()
-- Listeners
Client:on("ready", function()
Server = Client:getGuild(ServerId)
--Gets all server channels in Channels[channelname] format
Channels = {}
for i, channel in pairs(Server.textChannels) do
Channels[channel.name] = channel
end
for i, channel in pairs(Server.voiceChannels) do
Channels[channel.name] = channel
end
if storagedata["LastSaved"][2] == false then
if os.time()-storagedata["LastSaved"][1] > 600 then
send(Channels["type"],"The bot lost internet connection sometime between "..os.date("%I:%M:%S %p", storagedata["LastSaved"][1]).." and "..os.date("%I:%M:%S %p", storagedata["LastSaved"][1]+(SaveInterval*60)).." PDT. Save data was not affected.\n\nIf you've performed any actions between then and now, the bot may not have responded.\n\n<@"..OwnerId..">")
else
send(Channels["type"],"The bot has crashed. Save data between "..os.date("%I:%M:%S %p", storagedata["LastSaved"][1]).." and "..os.date("%I:%M:%S %p").." PDT was lost.\n\nIf you've performed any actions between then, you will have to do them again.\n\n<@"..OwnerId..">")
end
else
if storagedata["LastSaved"][3] == false then
send(Channels["type"],"Restart successful.")
end
storagedata["LastSaved"][2] = false
storagedata["LastSaved"][3] = false
end
local queuemessage = Channels["exclusive-queue"]:getLastMessage()
if storagedata["ExclusiveChannel"]["AdmitTime"] < os.time() then
storagedata["ExclusiveChannel"]["AdmitTime"] = os.time()+((QueueInterval*3600)-2*(os.time()%(QueueInterval*3600)))
admitNewUser()
end
updateQueue()
Client:on("reactionAdd",function(reaction,id)
if not Client:getUser(id).bot and reaction.message == queuemessage then
reaction:delete(id)
if id == storagedata["ExclusiveChannel"]["Serving"] or inTable(storagedata["ExclusiveChannel"]["Queue"],id) then
return
end
table.insert(storagedata["ExclusiveChannel"]["Queue"],id)
if not storagedata["ExclusiveChannel"]["Serving"] and #storagedata["ExclusiveChannel"]["Queue"] == 0 then
send(id,"Looks like you're the only person in line, no one even has access to the channel right now.",{["Title"]="Exclusive Channel",["Text"]="You have been put into the queue and are now **#1** in line. You will be admitted in **"..convertSeconds(storagedata["ExclusiveChannel"]["AdmitTime"] - os.time()).."**.\n\nUse the `queue` command to check your place in line."})
elseif #storagedata["ExclusiveChannel"]["Queue"] == 1 then
send(id,"Nice, it looks like you're first in line!",{["Title"]="Exclusive Channel",["Text"]="You have been put into the queue and are now **#"..(#storagedata["ExclusiveChannel"]["Queue"]).."** in line. You will be admitted in **"..convertSeconds(storagedata["ExclusiveChannel"]["AdmitTime"] - os.time() + ((#storagedata["ExclusiveChannel"]["Queue"])*(QueueInterval*3600))).."**.\n\nUse the `queue` command to check your place in line."})
elseif #storagedata["ExclusiveChannel"]["Queue"] >= 14 then
send(id,"Ouch. That's a long time. Surely it's worth it though?",{["Title"]="Exclusive Channel",["Text"]="You have been put into the queue and are now **#"..(#storagedata["ExclusiveChannel"]["Queue"]).."** in line. You will be admitted in **"..convertSeconds(storagedata["ExclusiveChannel"]["AdmitTime"] - os.time() + ((#storagedata["ExclusiveChannel"]["Queue"])*(QueueInterval*3600))).."**.\n\nUse the `queue` command to check your place in line."})
elseif #storagedata["ExclusiveChannel"]["Queue"] >= 6 then
send(id,"That's a decent wait, but at least you're in.",{["Title"]="Exclusive Channel",["Text"]="You have been put into the queue and are now **#"..(#storagedata["ExclusiveChannel"]["Queue"]).."** in line. You will be admitted in **"..convertSeconds(storagedata["ExclusiveChannel"]["AdmitTime"] - os.time() + ((#storagedata["ExclusiveChannel"]["Queue"])*(QueueInterval*3600))).."**.\n\nUse the `queue` command to check your place in line."})
else
send(id,"Alright, you're in the queue now.",{["Title"]="Exclusive Channel",["Text"]="You have been put into the queue and are now **#"..(#storagedata["ExclusiveChannel"]["Queue"]).."** in line. You will be admitted in **"..convertSeconds(storagedata["ExclusiveChannel"]["AdmitTime"] - os.time() + ((#storagedata["ExclusiveChannel"]["Queue"])*(QueueInterval*3600))).."**.\n\nUse the `queue` command to check your place in line."})
end
updateQueue()
end
end)
queuemessage:addReaction("🔑")
local speakers = {}
local status = "Nothing"
local speakcontrols = Channels["voice-controls"]:getFirstMessage()
if speakcontrols then
speakcontrols:clearReactions()
edit(speakcontrols,"",{["Title"]="Speak Channel",["Color"]={150,75,0},["Text"]="The voice channel is currently inactive.\n\nJoin to activate its functionality."})
else
speakcontrols = send(Channels["voice-controls"],"",{["Title"]="Speak Channel",["Color"]={0,100,100},["Text"]="The voice channel is currently inactive.\n\nJoin to activate its functionality."})
end
local playlists = {{"https://www.youtube.com/playlist?list=PLIF2opf2-1PpNtDL54NYzTflxwrpi_yfz","Happy Pokémon Music","Sukadia"},{"https://www.youtube.com/playlist?list=PLIF2opf2-1PrQE8OMQWDM3JFsMNumrucL","Pokémon Jamming Music","Sukadia"},{"https://www.youtube.com/playlist?list=PLkDIan7sXW2ilCdIvS22xX2FNAn_YuoDO","Best Future Funk","Sound Station"},{"https://www.youtube.com/playlist?list=PLOzDu-MXXLliO9fBNZOQTBDddoA3FzZUo","Lofi Hip Hop","the bootleg boy"},{"https://www.youtube.com/playlist?list=PLIF2opf2-1PqVOqEkAQo2g4LBgluEqTHU","Orchestral Pokémon Song Remakes","Sukadia"},{"https://www.youtube.com/playlist?list=PLxRnoC2v5tvg_xHK_roMyAStXDF-TRh2K","The Best of Retro Video Game Music","Specter227"},{"https://www.youtube.com/playlist?list=PLIF2opf2-1PqucHD3AbZkNSC0FUKTOLnl","OG Music Channel Playlist","Sukadia"}}
local musiccontrols = Channels["voice-controls"]:getLastMessage()
local connection = Channels["music"]:join()
local controller, page, songnum, videoqueue, songsubmittal
if musiccontrols and musiccontrols ~= speakcontrols then
musiccontrols:clearReactions()
edit(musiccontrols,"",{["Title"]="Music Channel",["Color"]={100,0,100},["Text"]="The music channel is currently inactive.\n\nJoin to activate its functionality."})
else
musiccontrols = send(Channels["voice-controls"],"",{["Title"]="Music Channel",["Color"]={100,0,100},["Text"]="The music channel is currently inactive.\n\nJoin to activate its functionality."})
end
updatePerms("everyone","voice-controls","read")
Client:on("voiceChannelJoin",function(member,channel)
if channel == Channels["speak"] then
local voicemembers = Channels["speak"].connectedMembers
member:mute()
if #voicemembers == 1 then
editembed(speakcontrols,nil,{["Color"]={0,150,150},["Text"]="Voice channel started.\n\nWelcome! If you intend to talk, please react to this message."})
speakcontrols:addReaction("🟦")
local function speakReaction(reaction,id)
if not Client:getUser(id).bot and reaction.message == speakcontrols then
local thismember
for i, member in pairs(voicemembers) do
if member.user.id == id then
thismember = member
break
end
end
if not thismember then
reaction:delete(id)
return
end
table.insert(speakers,thismember)
if status == "Nothing" then
if #voicemembers == 1 then
editembed(speakcontrols,nil,{["Color"]={0,150,150},["Text"]="\n\nYou are the only one in the voice channel currently. The process will start once someone else joins."})
else
status = "Waiting"
editembed(speakcontrols,nil,{["Color"]={200,100,0},["Text"]="Talking will begin at the start of a new minute.\n\n**"..#speakers.."** out of **"..#voicemembers.."** will have allocated speaking time.\n\nIf you'd like to speak, react to this message."})
wait(60-(os.time()%60))
while #speakers >= 1 and #Channels["speak"].connectedMembers >= 2 do
status = "Talking"
local currentspeakers = {table.unpack(speakers)}
local timeperperson = 50/#currentspeakers
local string = "Here's the order and timestamps in which everyone will talk:\n\n"
for i, member in pairs(currentspeakers) do
string = string..i..". [00:"..round((timeperperson*(i - 1)) + 10,1).."] "..member.name.."\n"
end
editembed(speakcontrols,nil,{["Color"]={0,255,255},["Text"]=string})
wait(10-(os.time()%10))
for i, member in pairs(currentspeakers) do
local waittime = os.time() + timeperperson
if member.voiceChannel ~= nil then
member:unmute()
end
local string = ""
if inTable(Channels["speak"].connectedMembers,member) then
string = "**"..member.name.."**, you have ~"..round(timeperperson).." seconds to speak.\n\n"
else
string = "**"..member.name.."** has left, so everyone will sit ~"..round(timeperperson).." seconds in silence.\n\n"
end
for v, member in pairs(currentspeakers) do
local online = false
for i, connected in pairs(Channels["speak"].connectedMembers) do
if connected == member then
online = true
break
end
end
if online and v == i then
string = string..v..". **[00:"..round((timeperperson*(v - 1)) + 10,1).."] - "..member.name.."**\n"
elseif v == i then
string = string..v..". ~~**[00:"..round((timeperperson*(v - 1)) + 10,1).."] - "..member.name.."**~~\n"
elseif online then
string = string..v..". [00:"..round((timeperperson*(v - 1)) + 10,1).."] - "..member.name.."\n"
else
string = string..v..". ~~[00:"..round((timeperperson*(v - 1)) + 10,1).."] - "..member.name.."~~\n"
end
end
editembed(speakcontrols,nil,{["Color"]={0,255,255},["Text"]=string})
wait(waittime - os.time())
if member.voiceChannel ~= nil then
member:mute()
end
end
end
status = "Nothing"
if #speakers == 0 and #Channels["speak"].connectedMembers >= 2 then
editembed(speakcontrols,nil,{["Color"]={0,150,150},["Text"]="\n\nNo one is current queued to speak. For the process to begin, there must be at least one speaker."})
elseif #Channels["speak"].connectedMembers == 1 then
editembed(speakcontrols,nil,{["Color"]={0,150,150},["Text"]="\n\nYou are the only one left in the voice channel. The process will start again if someone else joins."})
else
speakcontrols:clearReactions()
editembed(speakcontrols,nil,{["Color"]={0,100,100},["Text"]="The voice channel is currently inactive.\n\nJoin to activate its functionality."})
end
end
elseif status == "Waiting" then
editembed(speakcontrols,nil,{["Color"]={0,200,200},["Text"]="Talking will begin at the start of a new minute.\n\n**"..#speakers.."** out of **"..#voicemembers.."** will have allocated speaking time.\n\nIf you'd like to speak, react to this message."})
end
end
end
local function speakReactionRemove(reaction, id)
if reaction.message == speakcontrols then
for i, member in pairs(speakers) do
if member.user.id == id then
table.remove(speakers,i)
break
end
end
if #speakers == 0 then
editembed(speakcontrols,nil,{["Color"]={0,150,150},["Text"]="\n\nNo one is current queued to speak. For the process to begin, there must be at least one speaker."})
elseif status == "Waiting" then
editembed(speakcontrols,nil,{["Color"]={0,200,200},["Text"]="Talking will begin at the start of a new minute.\n\n**"..#speakers.."** out of **"..#voicemembers.."** will have allocated speaking time.\n\nIf you'd like to speak, react to this message."})
end
end
end
Client:removeListener("reactionAdd",speakReaction)
Client:removeListener("reactionRemove",speakReactionRemove)
Client:on("reactionAdd",speakReaction)
Client:on("reactionRemove",speakReactionRemove)
elseif #voicemembers > 1 and #speakers ~= 0 then
editembed(speakcontrols,nil,{["Color"]={0,200,200},["Text"]="Talking will begin at the start of a new minute.\n\n**"..#speakers.."** out of **"..#voicemembers.."** will have allocated speaking time.\n\nIf you'd like to speak, react to this message."})
end
end
if channel == Channels["music"] then
if #Channels["music"].connectedMembers == 2 then
local function playlistSearch(pagenum)
page = pagenum
songnum = 0
local numberemojis = {"1️⃣","2️⃣","3️⃣","4️⃣"}
local string = ""
for i=1,4 do
if playlists[i+(pagenum*4)-4] then
string = string..numberemojis[i].." **"..playlists[i+(pagenum*4)-4][2].."**\nby "..playlists[i+(pagenum*4)-4][3].."\n\n"
end
end
edit(musiccontrols,"",{["Title"]="Music Channel",["Color"]={150,0,150},["Text"]=string.."⏯️ Use your own playlist/video",["FooterImage"]=controller.user.avatarURL,["FooterText"]=controller.name.." is the controller."})
end
local function playSong(video) -- Plays a song, and downloads the next song if one is given
local process = io.popen("youtube-dl -f \"bestaudio[ext=m4a]\" --restrict-filenames -o \"/tmp/currentsong.m4a\" https://www.youtube.com/watch?v="..video["url"].." 2>&1") -- Save audio of YouTube video to /tmp/currentsong.m4a, this is because /tmp is usually a ramdisk and we want to minimize SD card writes
process:read("*a") -- Output is read just to make sure the command has completed before progressing
io.close(process)
local timeduration = math.floor(video["duration"]/60)..":"..(math.floor(video["duration"]%60) < 10 and "0" or "")..math.floor(video["duration"]%60)
editembed(musiccontrols,nil,{["Color"]={255,0,255},["Inline1Text"]="`Song "..songnum.." / "..#videoqueue.."`\n**["..video["title"].."](https://www.youtube.com/watch?v="..video["url"]..")**\nDuration: "..timeduration.."\n\n\n\n1️⃣ to quit"})
connection:playFFmpeg("/tmp/currentsong.m4a")
wait(0.1)
os.remove("/tmp/currentsong.m4a")
end
local function startQueue(url)
page = "Playing"
coroutine.wrap(function()
local file
local isplaylist = string.find(url,"playlist")
if isplaylist then
editembed(musiccontrols,nil,{["Color"]={200,0,200},["Text"]="Loading Playlist..\n_ _"})
file = io.popen("youtube-dl -j -q --geo-bypass --restrict-filenames --playlist-random --flat-playlist \""..url.."\" 2>&1") --2>&1 brings output from stderr to stdout
else
editembed(musiccontrols,nil,{["Color"]={200,0,200},["Text"]="Loading Video..\n_ _"})
file = io.popen("youtube-dl -j -q --get-url --get-title --get-duration \""..url.."\" 2>&1") --2>&1 brings output from stderr to stdout
end
local success = pcall(function()
if isplaylist then
videoqueue = Json.decode("["..string.gsub(file:read("*a"),"\n",",").."]")
else
videoqueue = {Json.decode("["..string.gsub(file:read("*a"),"\n",",").."]")}
end
end)
local deletedreason
if success then
for i=#videoqueue, 1, -1 do --Remove deleted and long videos
if videoqueue[i]["title"] == "[Deleted video]" then
deletedreason = "Deleted"
table.remove(videoqueue,i)
elseif videoqueue[i]["duration"] > 600 then
deletedreason = "TooLong"
table.remove(videoqueue,i)
end
end
else
if isplaylist then
editembed(musiccontrols,nil,{["Color"]={200,0,200},["Text"]="Error loading playlist | Invalid Link"})
else
editembed(musiccontrols,nil,{["Color"]={200,0,200},["Text"]="Error loading video | Invalid Link"})
end
wait(3)
playlistSearch(1)
return
end
if #videoqueue == 0 then
if isplaylist then
editembed(musiccontrols,nil,{["Color"]={200,0,200},["Text"]="Error loading playlist | All videos were deleted or over 10 minutes long"})
elseif not isplaylist and deletedreason == "Deleted" then
editembed(musiccontrols,nil,{["Color"]={200,0,200},["Text"]="Error loading video | Video was deleted"})
elseif not isplaylist and deletedreason == "TooLong" then
editembed(musiccontrols,nil,{["Color"]={200,0,200},["Text"]="Error loading video | Video was over 10 minutes long"})
end
wait(3)
playlistSearch(1)
return
end
local playlistnum = 0
for i, playlist in pairs(playlists) do
if playlist[1] == url then
playlistnum = i
end
end
songnum = 1
while songnum <= #videoqueue and songnum ~= 0 do
local video = videoqueue[songnum]
editembed(musiccontrols,nil,{["Color"]={255,0,255},["Text"]="Playlist:\n**"..(playlistnum == 0 and "Personal Link" or playlists[playlistnum][2]).."**",["Inline1Name"]="__Currently Playing__",["Inline1Text"]="`Song "..songnum.." / "..#videoqueue.."`\n**"..video["title"].."**\n\nLoading..\n\n\n1️⃣ to quit",["Inline2Name"]="__In Queue__",["Inline2Text"]=(videoqueue[songnum+1] and (songnum+1)..". "..videoqueue[songnum+1]["title"] or "").."\n\n"..(videoqueue[songnum+2] and (songnum+2)..". "..videoqueue[songnum+2]["title"] or "").."\n\n"..(videoqueue[songnum+3] and (songnum+3)..". "..videoqueue[songnum+3]["title"] or "").."\n\n"..(videoqueue[songnum+4] and (songnum+4)..". "..videoqueue[songnum+4]["title"] or "")})
playSong(video)
songnum = songnum + 1
end
if #Channels["music"].connectedMembers ~= 1 then
playlistSearch(1)
end
end)()
end
controller = member
edit(musiccontrols,"",{["Title"]="Music Channel",["Color"]={150,0,150},["Text"]="Waiting for buttons..",["FooterImage"]=controller.user.avatarURL,["FooterText"]=controller.name.." is the controller."})
local reactionemojis = {"1️⃣","2️⃣","3️⃣","4️⃣","⏪","⏯️","⏩"}
for i, reaction in pairs(reactionemojis) do
if #Channels["music"].connectedMembers ~= 1 then
musiccontrols:addReaction(reaction)
else
return
end
end
playlistSearch(1)
local function musicReaction(reaction,id)
local user = Client:getUser(id)
if not user.bot and reaction.message == musiccontrols then
if controller.user.id ~= id then
reaction:delete(id)
return
end
if page ~= "Playing" and page ~= "Paused" and page ~= "WaitingLink" then
if reaction.emojiName == "1️⃣" and (page ~= math.ceil(#playlists/4)+1 or page ~= playlists[(page*4)-3]) then
if page < math.ceil(#playlists/4)+1 then
startQueue(playlists[(page*4)-3][1])
elseif not songsubmittal then
songsubmittal = true
editembed(musiccontrols,"",{["Text"]="1️⃣ **Song Submittal**\nAny users in the voice channel can send a link to add to the queue.\n\n"..(songsubmittal and "✅ Enabled" or "❌ Disabled").."\n\n2️⃣\n\n\n\n\n\n_ _"})
updatePerms("everyone","voice-controls","talk")
local function newLinkSubmittal(message)
if message.channel == Channels["voice-controls"] and not message.author.bot then
local response = message.content
local user = message.author
message:delete()
coroutine.wrap(function()
local _, stringend = string.find(response,"youtube%.com/playlist%?list=")
local _, stringend2 = string.find(response,"youtube%.com/watch%?v=")
if stringend then
local videourl = "https://www.youtube.com/playlist?list="..string.sub(response,stringend+1,-1)