-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuper_bot.py
More file actions
executable file
Β·1671 lines (1398 loc) Β· 74 KB
/
super_bot.py
File metadata and controls
executable file
Β·1671 lines (1398 loc) Β· 74 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
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
#!/bin/python3 -u
import discord
import os
from dotenv import load_dotenv
from discord.ext import commands
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from OSRSBytes import Hiscores
import asyncio
from datetime import datetime
from datetime import date
import matplotlib.pyplot as plt
import numpy as np
import time
import re
from discord.utils import get
import random
import twitch
from OSRSBytes import Hiscores
from PIL import Image, ImageFont, ImageDraw
load_dotenv()
intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=intents)
helix = twitch.Helix(os.getenv('twitch_client'), os.getenv('twitch_secret'))
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
sheetclient = gspread.authorize(creds)
@client.event
async def on_ready():
print('super bot started on bot {0.user}'.format(client))
@client.command()
async def online(ctx):
if ctx.channel.id == int(os.getenv('channel')):
return
online_file = open("cc_online.log", "r")
online_users = ""
for rsn in online_file:
online_users = str(online_users + rsn.strip() + ", ")
if online_users:
await ctx.channel.send("Currently online in CC: ")
await ctx.channel.send(online_users)
else:
await ctx.channel.send("No users currently online in CC")
@client.listen()
async def on_message(message):
if message.channel.id == int(os.getenv('channel')):
return
content = message.content
if content.lower() == "!hello":
if message.author == client.user:
if message.channel.id == int(os.getenv('botchan')):
cc_chan = client.get_channel(int(os.getenv('channel')))
await cc_chan.send('*Hello!')
else:
await message.channel.send('Hello!')
else:
return
@client.listen()
async def on_message(message):
if message.author == client.user:
if message.channel.id == int(os.getenv('channel')):
content = str(message.content)
flag=0
user_ptrn = "@(.*?)@"
chan_ptrn = "#(.*?)#"
levl_ptrn = "] : (.*?) has reached"
drop_ptrn = "] : (.*?) received a drop"
qwst_ptrn = "] : (.*?) has completed a quest"
pets_ptrn = "] : (.*?) has a funny feeling like"
pkrs_ptrn = "] : (.*?) has been defeated by"
dpst_ptrn = "] : (.*?) has deposited"
wtdr_ptrn = "] : (.*?) has withdrawn"
user_ment = re.search(user_ptrn, content)
chan_ment = re.search(chan_ptrn, content)
levl_ment = re.search(levl_ptrn, content)
drop_ment = re.search(drop_ptrn, content)
qwst_ment = re.search(qwst_ptrn, content)
pets_ment = re.search(pets_ptrn, content)
pkrs_ment = re.search(pkrs_ptrn, content)
dpst_ment = re.search(dpst_ptrn, content)
wtdr_ment = re.search(wtdr_ptrn, content)
if user_ment:
user_name = user_ment.group(1)
for member in message.guild.members:
user_full = str("@" + user_name + "@")
name = member.name
if member.nick:
nick = member.nick
if nick.lower() == user_name.lower():
content = content.replace(user_full, str('<@' + str(member.id) + '>'))
flag=1
break
if name.lower() == user_name.lower():
content = content.replace(user_full, str('<@' + str(member.id) + '>'))
flag=1
break
if chan_ment:
chan_name = chan_ment.group(1)
for channel in message.guild.channels:
chan_full = str("#" + chan_name + "#")
name = channel.name
if name.lower() == chan_name.lower():
content = content.replace(chan_full, str('<#' + str(channel.id) + '>'))
flag = 1
break
cmd_cfg = open("ccbot_commands.cfg", "r")
bot_chan = client.get_channel(int(os.getenv('botchan')))
for cmd in cmd_cfg:
content_l = content.lower()
cmd_ment = content_l.find(str("!" + cmd.strip()))
if cmd_ment > 0:
await bot_chan.send(str("!" + cmd.strip()))
cmd_cfg.close()
if flag:
await message.channel.send(content)
await message.delete()
else:
if levl_ment:
levl_name = levl_ment.group(1)
await message.channel.send("*Gz @" + levl_name + " on the level")
elif drop_ment:
drop_name = drop_ment.group(1)
await message.channel.send("*Gz @" + drop_name + " on the drop")
elif qwst_ment:
qwst_name = qwst_ment.group(1)
await message.channel.send("*Gz @" + qwst_name + " on the quest")
elif pets_ment:
pets_name = pets_ment.group(1)
await message.channel.send("*Gz @" + pets_name + " on the pet")
elif pkrs_ment:
pkrs_name = pkrs_ment.group(1)
await message.channel.send("*lmao sit @" + pkrs_name)
elif dpst_ment:
dpst_name = dpst_ment.group(1)
await message.channel.send("*Thank you @" + dpst_name + "!")
coffer_chan = client.get_channel(int(os.getenv('coffer_chan')))
await coffer_chan.send(content)
elif wtdr_ment:
wtdr_name = wtdr_ment.group(1)
await message.channel.send("*O.O I'm watching you @" + wtdr_name)
coffer_chan = client.get_channel(int(os.getenv('coffer_chan')))
await coffer_chan.send(content)
else:
return
@client.listen()
async def on_message(message):
if message.channel.id == int(os.getenv('channel')):
if message.author == client.user:
content = str(message.content)
if content.startswith('*'):
return
rsn_ptrn = "] (.*?): "
login_ptrn = "0>(.*?) has joined"
logot_ptrn = "0>(.*?) has left"
emt_ptrn = "<:(.*?)>"
rsn = re.search(rsn_ptrn, content)
login = re.search(login_ptrn, content)
logot = re.search(logot_ptrn, content)
emt = re.search(emt_ptrn, content)
if login:
cc_logins = open("cc_logins.log", "a")
cc_logins.write(str(str(login.group(1)) + "\n"))
cc_logins.close()
cc_online = open("cc_online.log", "a")
cc_online.write(str(str(login.group(1)) + "\n"))
cc_online.close()
await asyncio.sleep(15)
await message.delete()
if logot:
cc_online = open("cc_online.log", "r")
cc_online_content = cc_online.readlines()
cc_online.close()
cc_online = open("cc_online.log", "w")
for logout_rsn in cc_online_content:
if logout_rsn.strip() != logot.group(1):
cc_online.write(logout_rsn)
cc_online.close()
await asyncio.sleep(15)
await message.delete()
if rsn:
if emt:
emt_full = str("<:" + str(emt.group(1)) + ">")
rsn = str(rsn.group(1)).replace(emt_full, "")
else:
rsn = rsn.group(1)
cc_messages = open("cc_messages.log", "a")
cc_messages.write(str(rsn + "\n"))
cc_messages.close()
else:
print(message.author,":",message.content)
else:
return
@client.listen()
async def on_message(message):
if message.channel.id == int(os.getenv('channel')):
return
content = message.content
if content.lower() == "!commands":
if message.author == client.user:
if message.channel.id == int(os.getenv('botchan')):
cc_chan = client.get_channel(int(os.getenv('channel')))
cmd_cfg = open("ccbot_commands.cfg", "r")
cmdlist = "Prefix !: "
for cmd in cmd_cfg:
cmdlist = str(cmdlist + cmd.strip() + ", ")
cmd_cfg.close()
await cc_chan.send(str("*" + cmdlist))
else:
cmd_cfg = open("disc_commands.cfg", "r")
cmdlist = ""
for cmd in cmd_cfg:
cmdlist = str(cmdlist + "!" + cmd.strip() + ", ")
cmd_cfg.close()
await message.channel.send(cmdlist)
else:
return
@client.listen()
async def on_message(message):
if message.channel.id == int(os.getenv('channel')):
return
content = message.content
if content.lower() == "!discord":
if message.author == client.user:
if message.channel.id == int(os.getenv('botchan')):
cc_chan = client.get_channel(int(os.getenv('channel')))
#await cc_chan.send('*Head to www tentalkosrs com for a Discord invite')
await cc_chan.send('*Head to tentalk.ca for a Discord invite')
else:
#await message.channel.send('Head to https://www.tentalkosrs.com for a Discord invite')
await message.channel.send('Head to tentalk.ca for a Discord invite')
else:
return
@client.command()
@commands.has_permissions(manage_roles=True)
async def givefriend(ctx, user: discord.Member, rsn):
if ctx.channel.id == int(os.getenv('channel')):
return
if ctx.channel.category_id != int(os.getenv('app_cat')):
await ctx.send("This command can only be used in an application channel")
return
await ctx.send("Checking rank status...")
ranked=0
rsn = str(rsn)
rsn_nospace = rsn.replace(" ","%20")
sheet_frnd = sheetclient.open_by_key(os.getenv('sheet')).worksheet("Clan Friends")
sheet_smry = sheetclient.open_by_key(os.getenv('sheet')).worksheet("Member Summary")
sheet_stat = sheetclient.open_by_key(os.getenv('sheet')).worksheet("Member Stats")
memb_role = discord.utils.get(ctx.guild.roles, name="Clan Member")
rune_role = discord.utils.get(ctx.guild.roles, name="Rune")
addy_role = discord.utils.get(ctx.guild.roles, name="Addy")
mith_role = discord.utils.get(ctx.guild.roles, name="Mith")
stel_role = discord.utils.get(ctx.guild.roles, name="Steel")
iron_role = discord.utils.get(ctx.guild.roles, name="Iron")
brnz_role = discord.utils.get(ctx.guild.roles, name="Bronze")
maxd_role = discord.utils.get(ctx.guild.roles, name="Maxed")
frend_role = discord.utils.get(ctx.guild.roles, name="Clan Friend")
leadr_role = discord.utils.get(ctx.guild.roles, name="Leader")
concl_role = discord.utils.get(ctx.guild.roles, name="Council")
unverified = discord.utils.get(ctx.guild.roles, name="unverified")
if memb_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is a clan member. Demoting them to friend. Use !giverank to undo this.")
await user.remove_roles(memb_role)
await user.remove_roles(rune_role)
await user.remove_roles(addy_role)
await user.remove_roles(mith_role)
await user.remove_roles(stel_role)
await user.remove_roles(iron_role)
await user.remove_roles(brnz_role)
ranked=1
elif frend_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is already a Clan Friend.")
return
elif leadr_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is a clan Leader, cannot demote them to friend.")
return
elif concl_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is on clan Council, cannot demote them to friend.")
return
try:
main_stats = Hiscores(rsn_nospace, 'N')
except:
await ctx.send("RSN " + rsn + " not found on hiscores. Must provide vaild RSN to give friend.")
main_stats = 0
return
i=0
for membername in sheet_frnd.col_values(1):
i=i+1
if str(membername) == str(user):
await ctx.send("<@!" + str(user.id) + "> (RSN " + sheet_frnd.cell(i, 2).value + ") is already in the clan friend list, but not ranked friend in Discord?")
await ctx.send("Please manually correct this <@!" + str(ctx.author.id) + ">")
return
i=0
for memberrsn in sheet_frnd.col_values(2):
i=i+1
if str(memberrsn) == str(rsn):
await ctx.send("RSN " + rsn + " (@" + sheet_frnd.cell(i, 1).value + ") is already in the clan friend list, did their Discord name change?")
await ctx.send("Please manually correct this <@!" + str(ctx.author.id) + ">")
return
new_frnd = [str(user), str(rsn)]
new_frnd.append(str(""))
new_frnd.append(str("Clan Friend"))
new_frnd.append(str("=COUNTIF(Offences!A1:A,B" + str(i) + ")+COUNTIF(Offences!A1:A,A" + str(i) + ")"))
new_frnd.append(str(user.joined_at))
new_frnd.append(str(""))
sheet_frnd.append_row(new_frnd, "USER_ENTERED")
await user.add_roles(frend_role)
await user.remove_roles(unverified)
await ctx.send("Gave Clan Friend rank to <@!" + str(user.id) + ">")
await ctx.send("You must also manually assign this rank ingame, <@!" + str(ctx.author.id) + ">")
if ranked:
i=0
for membername in sheet_smry.col_values(1):
i=i+1
if str(membername) == str(user):
sheet_smry.delete_rows(i)
sheet_stat.delete_rows(i)
print(datetime.now())
print(str(str(ctx.author) + " gave friend to " + str(user) + " with RSN " + rsn))
await user.edit(nick=rsn)
await ctx.send("This channel will self-destruct in 24 hours")
await asyncio.sleep(86400)
await ctx.channel.delete()
@givefriend.error
async def givefriend_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingPermissions):
await ctx.send("Must be able to manage roles to run this command. This has been reported")
print(datetime.now())
print(ctx.author, "attempted to use !givefriend without permission")
elif isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
await ctx.send("Must provide @DiscordUser and RSN")
elif isinstance(error, discord.ext.commands.errors.MemberNotFound):
await ctx.send("Invalid Discord User")
@client.command()
@commands.has_permissions(manage_roles=True)
async def giverank(ctx, user: discord.Member, rsn):
if ctx.channel.id == int(os.getenv('channel')):
return
if ctx.channel.category_id != int(os.getenv('app_cat')):
await ctx.send("This command can only be used in an application channel")
return
await ctx.send("Checking rank status...")
friend=0
rsn = str(rsn)
rsn_nospace = rsn.replace(" ","%20")
sheet_frnd = sheetclient.open_by_key(os.getenv('sheet')).worksheet("Clan Friends")
sheet_smry = sheetclient.open_by_key(os.getenv('sheet')).worksheet("Member Summary")
sheet_stat = sheetclient.open_by_key(os.getenv('sheet')).worksheet("Member Stats")
memb_role = discord.utils.get(ctx.guild.roles, name="Clan Member")
rune_role = discord.utils.get(ctx.guild.roles, name="Rune")
addy_role = discord.utils.get(ctx.guild.roles, name="Addy")
mith_role = discord.utils.get(ctx.guild.roles, name="Mith")
stel_role = discord.utils.get(ctx.guild.roles, name="Steel")
iron_role = discord.utils.get(ctx.guild.roles, name="Iron")
brnz_role = discord.utils.get(ctx.guild.roles, name="Bronze")
maxd_role = discord.utils.get(ctx.guild.roles, name="Maxed")
frend_role = discord.utils.get(ctx.guild.roles, name="Clan Friend")
leadr_role = discord.utils.get(ctx.guild.roles, name="Leader")
concl_role = discord.utils.get(ctx.guild.roles, name="Council")
unverified = discord.utils.get(ctx.guild.roles, name="unverified")
if memb_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is already ranked in clan. Use !rankup to change.")
return
elif frend_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is currently a clan friend. Giving them full Clan membership (if 10HP).")
friend=1
elif leadr_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is a clan Leader, cannot give them member rank.")
return
elif concl_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is on clan Council, cannot give them member rank.")
return
try:
main_stats = Hiscores(rsn_nospace, 'N')
except:
await ctx.send("RSN " + rsn + " not found on hiscores. Must provide vaild RSN to give rank.")
main_stats = 0
return
i=0
for membername in sheet_smry.col_values(1):
i=i+1
if str(membername) == str(user):
await ctx.send("<@!" + str(user.id) + "> (RSN " + sheet_smry.cell(i, 2).value + ") is already in the clan member list, but not ranked in Discord? They should be ranked " + sheet_smry.cell(i, 8).value)
await ctx.send("Please manually correct this <@!" + str(ctx.author.id) + ">")
return
i=0
for memberrsn in sheet_smry.col_values(2):
i=i+1
if str(memberrsn) == str(rsn):
await ctx.send("RSN " + rsn + " (@" + sheet_smry.cell(i, 1).value + ") is already in the clan member list, did their Discord name change? They should be ranked " + sheet_smry.cell(i, 8).value)
await ctx.send("Please manually correct this <@!" + str(ctx.author.id) + ">")
return
i=i+1
new_stats = [str(user), str(rsn)]
new_smry = [str("='Member Stats'!A" + str(i)), str("='Member Stats'!B" + str(i))]
if main_stats:
try:
iron_stats = Hiscores(rsn_nospace, 'IM')
except:
iron_stats = 0
if iron_stats:
new_stats.append(int(iron_stats.skill('total', 'level')))
try:
uim_stats = Hiscores(rsn_nospace, 'UIM')
except:
uim_stats = 0
if uim_stats:
new_stats.append(int(uim_stats.skill('total', 'level')))
new_stats.append('N/A')
else:
try:
hci_stats = Hiscores(rsn_nospace, 'HIM')
except:
hci_stats = 0
if hci_stats:
new_stats.append('N/A')
new_stats.append(int(hci_stats.skill('total', 'level')))
else:
new_stats.append('N/A')
new_stats.append('N/A')
else:
new_stats.append('N/A')
new_stats.append('N/A')
new_stats.append('N/A')
new_stats.append(int(main_stats.skill('total', 'level')))
new_stats.append(int(main_stats.skill('attack', 'level')))
new_stats.append(int(main_stats.skill('defense', 'level')))
new_stats.append(int(main_stats.skill('strength', 'level')))
new_stats.append(int(main_stats.skill('hitpoints', 'level')))
new_stats.append(int(main_stats.skill('ranged', 'level')))
new_stats.append(int(main_stats.skill('prayer', 'level')))
new_stats.append(int(main_stats.skill('magic', 'level')))
new_stats.append(int(main_stats.skill('cooking', 'level')))
new_stats.append(int(main_stats.skill('woodcutting', 'level')))
new_stats.append(int(main_stats.skill('fletching', 'level')))
new_stats.append(int(main_stats.skill('fishing', 'level')))
new_stats.append(int(main_stats.skill('firemaking', 'level')))
new_stats.append(int(main_stats.skill('crafting', 'level')))
new_stats.append(int(main_stats.skill('smithing', 'level')))
new_stats.append(int(main_stats.skill('mining', 'level')))
new_stats.append(int(main_stats.skill('herblore', 'level')))
new_stats.append(int(main_stats.skill('agility', 'level')))
new_stats.append(int(main_stats.skill('thieving', 'level')))
new_stats.append(int(main_stats.skill('slayer', 'level')))
new_stats.append(int(main_stats.skill('farming', 'level')))
new_stats.append(int(main_stats.skill('runecrafting', 'level')))
new_stats.append(int(main_stats.skill('hunter', 'level')))
new_stats.append(int(main_stats.skill('construction', 'level')))
new_smry.append(str("=MAX('Member Stats'!C" + str(i) + ", 'Member Stats'!D" + str(i) + ",'Member Stats'!E" + str(i) + ",'Member Stats'!F" + str(i) + ")"))
new_smry.append(str("=0.25*('Member Stats'!H" + str(i) + "+'Member Stats'!J" + str(i) + "+0.5*'Member Stats'!L" + str(i) + ")+MAX((13/40)*('Member Stats'!I" + str(i) + "+'Member Stats'!G" + str(i) + "),((13/40)*('Member Stats'!K" + str(i) + "*1.5)),((13/40)*('Member Stats'!M" + str(i) + "*1.5)))"))
new_smry.append("='Member Stats'!J" + str(i))
new_smry.append(str("=COUNTIF('Member Stats'!G" + str(i) + ":M" + str(i) + ",\">10\")"))
new_smry.append(str("=IF(ISNUMBER('Member Stats'!C" + str(i) + "),IF(ISNUMBER('Member Stats'!D" + str(i) + "),\"UIM\",IF(ISNUMBER('Member Stats'!E" + str(i) + "),IF('Member Stats'!C" + str(i) + " > 'Member Stats'!E" + str(i) + ",\"Dead HCIM\",\"HCIM\"),\"IM\")),\"Normal\")"))
new_smry.append(str("=IF(E" + str(i) + ">10,\"Clan Friend\",(IF(G" + str(i) + "=\"Normal\",(IF(F" + str(i) + "<1,(IF(C" + str(i) + ">=1500,\"Rune\",(IF(C" + str(i) + ">=1400,\"Adamant\",(IF(C" + str(i) + ">=1200,\"Mithril\",(IF(C" + str(i) + ">=900,\"Steel\",(IF(C" + str(i) + ">=600,\"Iron\",\"Bronze\")))))))))),(IF(F" + str(i) + "<3,(IF(C" + str(i) + ">=1666,\"Rune\",(IF(C" + str(i) + ">=1533,\"Adamant\",(IF(C" + str(i) + ">=1300,\"Mithril\",(IF(C" + str(i) + ">=966,\"Steel\",(IF(C" + str(i) + ">=633,\"Iron\",\"Bronze\")))))))))),(IF(F" + str(i) + "<5,(IF(C" + str(i) + ">=1833,\"Rune\",(IF(C" + str(i) + ">=1666,\"Adamant\",(IF(C" + str(i) + ">=1400,\"Mithril\",(IF(C" + str(i) + ">=1033,\"Steel\",(IF(C" + str(i) + ">=666,\"Iron\",\"Bronze\")))))))))),(IF(C" + str(i) + ">=2000,\"Rune\",(IF(C" + str(i) + ">=1800,\"Adamant\",(IF(C" + str(i) + ">=1500,\"Mithril\",(IF(C" + str(i) + ">=1100,\"Steel\",(IF(C" + str(i) + ">=700,\"Iron\",\"Bronze\")))))))))))))))),(IF(OR(G" + str(i) + "=\"IM\",G" + str(i) + "=\"Dead HCIM\",G" + str(i) + "=\"HCIM\"),(IF(F" + str(i) + "<1,(IF(C" + str(i) + ">=1500,\"Rune\",(IF(C" + str(i) + ">=1300,\"Adamant\",(IF(C" + str(i) + ">=1100,\"Mithril\",(IF(C" + str(i) + ">=800,\"Steel\",(IF(C" + str(i) + ">=500,\"Iron\",\"Bronze\")))))))))),(IF(F" + str(i) + "<3,(IF(C" + str(i) + ">=1666,\"Rune\",(IF(C" + str(i) + ">=1433,\"Adamant\",(IF(C" + str(i) + ">=1200,\"Mithril\",(IF(C" + str(i) + ">=866,\"Steel\",(IF(C" + str(i) + ">=533,\"Iron\",\"Bronze\")))))))))),(IF(F" + str(i) + "<5,(IF(C" + str(i) + ">=1833,\"Rune\",(IF(C" + str(i) + ">=1566,\"Adamant\",(IF(C" + str(i) + ">=1300,\"Mithril\",(IF(C" + str(i) + ">=933,\"Steel\",(IF(C" + str(i) + ">=566,\"Iron\",\"Bronze\")))))))))),(IF(C" + str(i) + ">=2000,\"Rune\",(IF(C" + str(i) + ">=1700,\"Adamant\",(IF(C" + str(i) + ">=1400,\"Mithril\",(IF(C" + str(i) + ">=1000,\"Steel\",(IF(C" + str(i) + ">=600,\"Iron\",\"Bronze\")))))))))))))))),(IF(G" + str(i) + "=\"UIM\",(IF(F" + str(i) + "<1,(IF(C" + str(i) + ">=1500,\"Rune\",(IF(C" + str(i) + ">=1200,\"Adamant\",(IF(C" + str(i) + ">=1000,\"Mithril\",(IF(C" + str(i) + ">=700,\"Steel\",(IF(C" + str(i) + ">=400,\"Iron\",\"Bronze\")))))))))),(IF(F" + str(i) + "<3,(IF(C" + str(i) + ">=1666,\"Rune\",(IF(C" + str(i) + ">=1333,\"Adamant\",(IF(C" + str(i) + ">=1100,\"Mithril\",(IF(C" + str(i) + ">=766,\"Steel\",(IF(C" + str(i) + ">=433,\"Iron\",\"Bronze\")))))))))),(IF(F" + str(i) + "<5,(IF(C" + str(i) + ">=1833,\"Rune\",(IF(C" + str(i) + ">=1466,\"Adamant\",(IF(C" + str(i) + ">=1200,\"Mithril\",(IF(C" + str(i) + ">=833,\"Steel\",(IF(C" + str(i) + ">=466,\"Iron\",\"Bronze\")))))))))),(IF(C" + str(i) + ">=2000,\"Rune\",(IF(C" + str(i) + ">=1600,\"Adamant\",(IF(C" + str(i) + ">=1300,\"Mithril\",(IF(C" + str(i) + ">=900,\"Steel\",(IF(C" + str(i) + ">=500,\"Iron\",\"Bronze\")))))))))))))))),\"ERROR\")))))))"))
new_smry.append(str(""))
new_smry.append(str(""))
new_smry.append(str("=COUNTIF(Offences!A1:A,B" + str(i) + ")+COUNTIF(Offences!A1:A,A" + str(i) + ")"))
new_smry.append(str(user.joined_at))
new_smry.append(str(""))
sheet_stat.append_row(new_stats, "USER_ENTERED")
sheet_smry.append_row(new_smry, "USER_ENTERED")
await asyncio.sleep(1)
recom_rank = sheet_smry.cell(i, 8).value
if friend:
await user.remove_roles(frend_role)
j=0
for membername in sheet_frnd.col_values(1):
j=j+1
if str(membername) == str(user):
sheet_frnd.delete_rows(j)
if str(recom_rank) == "Clan Friend":
await ctx.send(rsn + " is not 10HP, giving Clan Friend rank to <@!" + str(user.id) + ">")
await ctx.send("You can manually override this if desired to admit the member anyway")
await user.add_roles(frend_role)
sheet_smry.update_cell(i, 10, "Clan Friend")
elif str(recom_rank) == "Bronze":
await ctx.send(rsn + " is " + str(sheet_smry.cell(i, 3).value) + " total, giving Bronze rank to <@!" + str(user.id) + ">")
await user.add_roles(brnz_role)
sheet_smry.update_cell(i, 10, "Bronze")
elif str(recom_rank) == "Iron":
await ctx.send(rsn + " is " + str(sheet_smry.cell(i, 3).value) + " total, giving Iron rank to <@!" + str(user.id) + ">")
await user.add_roles(iron_role)
sheet_smry.update_cell(i, 10, "Iron")
elif str(recom_rank) == "Steel":
await ctx.send(rsn + " is " + str(sheet_smry.cell(i, 3).value) + " total, giving Steel rank to <@!" + str(user.id) + ">")
await user.add_roles(stel_role)
sheet_smry.update_cell(i, 10, "Steel")
elif str(recom_rank) == "Mithril":
await ctx.send(rsn + " is " + str(sheet_smry.cell(i, 3).value) + " total, giving Mith rank to <@!" + str(user.id) + ">")
await user.add_roles(mith_role)
sheet_smry.update_cell(i, 10, "Mithril")
elif str(recom_rank) == "Adamant":
await ctx.send(rsn + " is " + str(sheet_smry.cell(i, 3).value) + " total, giving Addy rank to <@!" + str(user.id) + ">")
await user.add_roles(addy_role)
sheet_smry.update_cell(i, 10, "Adamant")
elif str(recom_rank) == "Rune":
await ctx.send(rsn + " is " + str(sheet_smry.cell(i, 3).value) + " total, giving Rune rank to <@!" + str(user.id) + ">")
await user.add_roles(rune_role)
sheet_smry.update_cell(i, 10, "Rune")
await user.add_roles(memb_role)
await user.remove_roles(unverified)
await user.edit(nick=rsn)
await ctx.send("You must also manually assign this rank ingame, <@!" + str(ctx.author.id) + ">")
print(datetime.now())
print(str(str(ctx.author) + " gave rank to " + str(user) + " with RSN " + rsn))
await ctx.send("This channel will self-destruct in 24 hours")
await asyncio.sleep(86400)
await ctx.channel.delete()
@giverank.error
async def giverank_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingPermissions):
await ctx.send("Must be able to manage roles to run this command. This has been reported")
print(datetime.now())
print(ctx.author, "attempted to use !giverank without permission")
elif isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
await ctx.send("Must provide @DiscordUser and RSN")
elif isinstance(error, discord.ext.commands.errors.MemberNotFound):
await ctx.send("Invalid Discord User")
@client.listen()
async def on_message(message):
if message.channel.id == int(os.getenv('channel')):
return
content = message.content
if content.lower() == "!info":
if message.author == client.user:
if message.channel.id == int(os.getenv('botchan')):
try:
info_file = open("info_cc.msg", "r")
info_msg = info_file.read()
info_file.close()
except:
info_msg = "No info message is set"
cc_chan = client.get_channel(int(os.getenv('channel')))
await cc_chan.send(str('*' + info_msg))
else:
try:
info_file = open("info_disc.msg", "r")
info_msg = info_file.read()
info_file.close()
except:
info_msg = "No info message is set"
await message.channel.send(str(info_msg))
else:
return
@client.command()
@commands.has_permissions(manage_messages=True)
async def info_set(ctx, typ, info):
if ctx.channel.id == int(os.getenv('channel')):
return
if typ.lower() == "discord":
info_file = open("info_disc.msg", "w")
info_file.write(str(info))
info_file.close()
await ctx.send("Info Discord message set to:")
info_file = open("info_disc.msg", "r")
await ctx.send(str(info_file.read()))
print(ctx.author, "set Discord info message to", info)
info_file.close()
elif typ.lower() == "cc":
if len(info) > 79:
await ctx.send("Message too long. Character limit is 79 for info cc message")
await ctx.send(str("Your message is " + str(len(info)) + " characters"))
else:
info_file = open("info_cc.msg", "w")
info_file.write(str(info))
info_file.close()
await ctx.send("Info CC message set to:")
info_file = open("info_cc.msg", "r")
await ctx.send(str(info_file.read()))
print(ctx.author, "set CC info message to", info)
info_file.close()
else:
await ctx.send("Info type not valid. Specify either 'cc' or 'discord'")
@info_set.error
async def info_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
await ctx.send("Must provide a message to set")
if isinstance(error, discord.ext.commands.errors.MissingPermissions):
await ctx.send("Must be able to manage messages to run this command. This has been reported")
print(datetime.now())
print(ctx.author, "attempted to use !info_set without permission")
@client.listen()
async def on_message(message):
if message.channel.id == int(os.getenv('channel')):
return
content = message.content
if content.lower() == "!motd":
if message.author == client.user:
if message.channel.id == int(os.getenv('botchan')):
try:
motd_file = open("motd_cc.msg", "r")
motd_msg = motd_file.read()
motd_file.close()
except:
motd_msg = "No motd is set"
cc_chan = client.get_channel(int(os.getenv('channel')))
await cc_chan.send(str('*' + motd_msg))
else:
try:
motd_file = open("motd_disc.msg", "r")
motd_msg = motd_file.read()
motd_file.close()
except:
motd_msg = "No motd is set"
await message.channel.send(str(motd_msg))
else:
return
@client.command()
@commands.has_permissions(manage_messages=True)
async def motd_set(ctx, typ, motd):
if ctx.channel.id == int(os.getenv('channel')):
return
if typ.lower() == "discord":
motd_file = open("motd_disc.msg", "w")
motd_file.write(str(motd))
motd_file.close()
await ctx.send("MOTD Discord message set to:")
motd_file = open("motd_disc.msg", "r")
await ctx.send(str(motd_file.read()))
print(ctx.author, "set the Discord motd to", motd)
motd_file.close()
elif typ.lower() == "cc":
if len(motd) > 79:
await ctx.send("Message too long. Character limit is 79 for motd cc message")
await ctx.send(str("Your message is " + str(len(motd)) + " characters"))
else:
motd_file = open("motd_cc.msg", "w")
motd_file.write(str(motd))
motd_file.close()
await ctx.send("MOTD CC message set to:")
motd_file = open("motd_cc.msg", "r")
await ctx.send(str(motd_file.read()))
print(ctx.author, "set the CC motd to", motd)
motd_file.close()
else:
await ctx.send("MOTD type not valid. Specify either 'cc' or 'discord'")
@motd_set.error
async def motd_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
await ctx.send("Must provide a message to set")
if isinstance(error, discord.ext.commands.errors.MissingPermissions):
await ctx.send("Must be able to manage messages to run this command. This has been reported")
print(datetime.now())
print(ctx.author, "attempted to use !motd_set without permission")
@client.command()
#@commands.has_permissions(manage_messages=True)
async def poll_cancel(ctx, poll_num: int):
if ctx.channel.id == int(os.getenv('channel')):
return
if os.path.exists(str("poll" + str(poll_num) + ".tmp")):
poll_file = open(str("poll" + str(poll_num) + ".tmp"), "r")
poll_data = poll_file.readlines()
poll_file.close()
if str(poll_data[1]).strip() == str(ctx.author.id):
os.remove(str("poll" + str(poll_num) + ".tmp"))
await ctx.send("Cancelled poll #" + str(poll_num) + " by <@!" + str(poll_data[1]).strip() + ">")
elif ctx.author.guild_permissions.manage_messages:
os.remove(str("poll" + str(poll_num) + ".tmp"))
await ctx.send("Cancelled poll #" + str(poll_num) + " by <@!" + str(poll_data[1]).strip() + ">")
else:
await ctx.send("You can only cancel your own polls without mod status.")
print(str(str(datetime.now()) + str(ctx.author) + " attempted to delete a poll without permission"))
else:
await ctx.send("Poll #" + str(poll_num) + " not currently running")
@poll_cancel.error
async def poll_cancel_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
await ctx.send("Must provide poll number to cancel")
@client.command()
async def poll(ctx, ttl: int, question: str, *options: str):
if ctx.channel.id == int(os.getenv('channel')):
return
if len(options) == 0:
await ctx.channel.send("You must provide at least 1 option")
return
poll_chan = client.get_channel(int(os.getenv('poll_chan')))
try:
polls_hist = open("polls.hist", "r")
poll_num = len(polls_hist.readlines())
polls_hist.close()
except:
ctx.channel.send("Error in creating poll. Contact Ten Talk Bot Admin")
return
poll_msg = str("Poll #" + str(poll_num+1) + ": " + question)
polls_hist = open("polls.hist", "a")
polls_hist.write(str(str(datetime.now()) + " " + poll_msg + " by: " + str(ctx.author) + "\n"))
polls_hist.close()
poll_msg = str(poll_msg + "\n" + "by: <@!" + str(ctx.author.id) + ">\n")
if ttl < 60:
ttl_flt = ttl
scale = " minutes"
else:
ttl_flt = ttl/60
if ttl_flt < 24:
scale = " hours"
else:
ttl_flt = ttl_flt/24
scale = " days"
ttl_flt = round(ttl_flt, 2)
poll_msg = str(poll_msg + "Time Left: " + str(ttl_flt) + scale + "\n\n")
i=0
for option in options:
if i==0:
poll_msg = str(poll_msg + ":regional_indicator_a: ")
reactions = ['π¦']
elif i==1:
poll_msg = str(poll_msg + ":regional_indicator_b: ")
reactions.append('π§')
elif i==2:
poll_msg = str(poll_msg + ":regional_indicator_c: ")
reactions.append('π¨')
elif i==3:
poll_msg = str(poll_msg + ":regional_indicator_d: ")
reactions.append('π©')
elif i==4:
poll_msg = str(poll_msg + ":regional_indicator_e: ")
reactions.append('πͺ')
elif i==5:
poll_msg = str(poll_msg + ":regional_indicator_f: ")
reactions.append('π«')
elif i==6:
poll_msg = str(poll_msg + ":regional_indicator_g: ")
reactions.append('π¬')
elif i==7:
poll_msg = str(poll_msg + ":regional_indicator_h: ")
reactions.append('π')
elif i==8:
await ctx.author.send("Warning: !poll is limited to 8 options. Your poll has been truncated to this.")
break
poll_msg = str(poll_msg + option + "\n")
i=i+1
poll_create = await poll_chan.send(poll_msg)
for reaction in reactions:
await poll_create.add_reaction(reaction)
poll_lock = open(str("poll" + str(poll_num+1) + ".tmp"), "w")
poll_lock.write(str(question + " by: " + str(ctx.author) + "\n" + str(ctx.author.id) + "\n" + str(poll_create.id)))
poll_lock.close()
while ttl:
await asyncio.sleep(60)
ttl=ttl-1
if not os.path.exists(str("poll" + str(poll_num+1) + ".tmp")):
poll_msg = poll_msg.replace(str("Time Left: " + str(ttl_flt) + scale), str("Time Left: Poll Cancelled"))
await poll_create.edit(content=poll_msg)
return
if ttl < 60:
ttl_flt_new = ttl
scale_new = " minutes"
else:
ttl_flt_new = ttl/60
if ttl_flt_new < 24:
scale_new = " hours"
else:
ttl_flt_new = ttl_flt_new/24
scale_new = " days"
ttl_flt_new = round(ttl_flt_new, 2)
poll_msg = poll_msg.replace(str("Time Left: " + str(ttl_flt) + scale), str("Time Left: " + str(ttl_flt_new) + scale_new))
await poll_create.edit(content=poll_msg)
ttl_flt = ttl_flt_new
scale = scale_new
if os.path.exists(str("poll" + str(poll_num+1) + ".tmp")):
os.remove(str("poll" + str(poll_num+1) + ".tmp"))
poll_msg = poll_msg.replace(str("Time Left: " + str(ttl_flt) + scale), str("Time Left: Poll Completed"))
await poll_create.edit(content=poll_msg)
poll_result = await poll_chan.fetch_message(int(poll_create.id))
results = []
for reaction in poll_result.reactions:
results.append(reaction.count)
results = results[0 : len(options)]
plt.pie(results, labels = options)
plt.savefig(str("poll" + str(poll_num+1) + ".png"))
plt.clf()
await poll_chan.send(str("Poll #" + str(poll_num+1) + " Results by: <@!" + str(ctx.author.id) + ">\n**" + question + "**"), file=discord.File(str("poll" + str(poll_num+1) + ".png")))
os.remove(str("poll" + str(poll_num+1) + ".png"))
@poll.error
async def poll_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
await ctx.send("Usage: !poll <minutes> <\"Question\"> <\"Option 1\"> ... <\"Option 8\">")
elif isinstance(error, discord.ext.commands.errors.BadArgument):
await ctx.send("Usage: !poll <minutes> <\"Question\"> <\"Option 1\"> ... <\"Option 8\">")
elif isinstance(error, discord.ext.commands.errors.ExpectedClosingQuoteError):
await ctx.send("Usage: !poll <minutes> <\"Question\"> <\"Option 1\"> ... <\"Option 8\">")
else:
await ctx.send("Error in creating poll. Contact Ten Talk Bot Admin")
@client.listen()
async def on_message(message):
if message.channel.id == int(os.getenv('channel')):
return
content = message.content
if content.lower() == "!raids":
if message.author == client.user:
if message.channel.id == int(os.getenv('botchan')):
cc_chan = client.get_channel(int(os.getenv('channel')))
await cc_chan.send('*Use this in Discord for an invite to Level 3 Raids server. Learn how to get purps on level 3!')
else:
if message.author.nick:
name = message.author.nick
else:
name = message.author.name
await message.channel.send("If you are interested in learning CoX Raids on a Level 3 or 10HP, check out the Level 3 Raids Discord Server. Invite link: https://discord.gg/wVSkAABhdr")
else:
return
@client.command()
@commands.has_permissions(manage_roles=True)
async def rankup(ctx, user: discord.Member):
if ctx.channel.id == int(os.getenv('channel')):
return
await ctx.send("Checking rank status...")
ready=0
found=0
sheet_smry = sheetclient.open_by_key(os.getenv('sheet')).worksheet("Member Summary")
sheet_stat = sheetclient.open_by_key(os.getenv('sheet')).worksheet("Member Stats")
memb_role = discord.utils.get(ctx.guild.roles, name="Clan Member")
rune_role = discord.utils.get(ctx.guild.roles, name="Rune")
addy_role = discord.utils.get(ctx.guild.roles, name="Addy")
mith_role = discord.utils.get(ctx.guild.roles, name="Mith")
stel_role = discord.utils.get(ctx.guild.roles, name="Steel")
iron_role = discord.utils.get(ctx.guild.roles, name="Iron")
brnz_role = discord.utils.get(ctx.guild.roles, name="Bronze")
maxd_role = discord.utils.get(ctx.guild.roles, name="Maxed")
frend_role = discord.utils.get(ctx.guild.roles, name="Clan Friend")
leadr_role = discord.utils.get(ctx.guild.roles, name="Leader")
concl_role = discord.utils.get(ctx.guild.roles, name="Council")
if maxd_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is already Maxed, can't rank-up any further.")
return
elif rune_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is already Rune. Maxed rank-ups must be done manually.")
return
elif memb_role in user.roles:
ready=1
elif frend_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is currently a clan friend. Use !giverank to add them to the member role.")
return
elif leadr_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is a clan Leader, cannot give them member rank.")
return
elif concl_role in user.roles:
await ctx.send("<@!" + str(user.id) + "> is on clan Council, cannot give them member rank.")
return