-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_addons.py
1625 lines (1519 loc) · 86.7 KB
/
cmd_addons.py
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
from Uncute_Rina import *
from import_modules import *
report_message_reminder_unix = 0 #int(mktime(datetime.now().timetuple()))
selfies_delete_week_command_cooldown = 0
currency_options = {
code: 0 for code in "AED,AFN,ALL,AMD,ANG,AOA,ARS,AUD,AWG,AZN,BAM,BBD,BDT,BGN,BHD,BIF,BMD,BND,BOB,BRL,BSD,BTC,BTN,BWP,BYN,BZD,CAD,CDF,"
"CHF,CLF,CLP,CNH,CNY,COP,CRC,CUC,CUP,CVE,CZK,DJF,DKK,DOP,DZD,EGP,ERN,ETB,EUR,FJD,FKP,GBP,GEL,GGP,GHS,GIP,GMD,GNF,"
"GTQ,GYD,HKD,HNL,HRK,HTG,HUF,IDR,ILS,IMP,INR,IQD,IRR,ISK,JEP,JMD,JOD,JPY,KES,KGS,KHR,KMF,KPW,KRW,KWD,KYD,KZT,LAK,"
"LBP,LKR,LRD,LSL,LYD,MAD,MDL,MGA,MKD,MMK,MNT,MOP,MRU,MUR,MVR,MWK,MXN,MYR,MZN,NAD,NGN,NIO,NOK,NPR,NZD,OMR,PAB,PEN,"
"PGK,PHP,PKR,PLN,PYG,QAR,RON,RSD,RUB,RWF,SAR,SBD,SCR,SDG,SEK,SGD,SHP,SLL,SOS,SRD,SSP,STD,STN,SVC,SYP,SZL,THB,TJS,"
"TMT,TND,TOP,TRY,TTD,TWD,TZS,UAH,UGX,USD,UYU,UZS,VES,VND,VUV,WST,XAF,XAG,XAU,XCD,XDR,XOF,XPD,XPF,XPT,YER,"
"ZAR,ZMW,ZWL".split(",")}
conversion_rates: dict[str, dict[str, tuple[int|float,int|float,str]]] = { # [default 0, incrementation]
"temperature":{
"Celcius" : [273.15, 1, "°C"],
"Kelvin" : [0, 1, "K"],
"Fahrenheit" : [459.67, 1.8, "°F"],
"Rankine" : [0, 1.8, "°R"]
},
"length":{
"kilometer" : [0, 0.001, "km"],
"hectometer" : [0, 0.01, "hm"],
"meter" : [0, 1, "m"],
"decimeter" : [0, 10, "dm"],
"centimeter" : [0, 100, "cm"],
"millimeter" : [0, 1000, "mm"],
"micrometer" : [0, 10 ** 6, "μm"],
"nanometer" : [0, 10 ** 9, "nm"],
"picometer" : [0, 10 ** 12, "pm"],
"femtometer" : [0, 10 ** 15, "fm"],
"ångström" : [0, 10 ** 10, "Å"],
"mile" : [0, 0.0006213711922373339, "mi"],
"yard" : [0, 1.09361329833770778652, "yd"],
"foot" : [0, 3.28083989501312335958, "ft"],
"inch" : [0, 39.37007874015748031496, "in"],
},
"surface area": {
"square kilometer" : [0, 0.000001, "km²"],
"square meter" : [0, 1, "m²"],
"square centimeter" : [0, 10000, "cm²"],
"square mile" : [0, 0.00000038610215854781256, "mi²"],
"square yard" : [0, 1.19599, "yd²"],
"square feet" : [0, 10.76391, "ft²"],
"square inch" : [0, 1550, "in²"],
"hectare" : [0, 0.0001, "ha"],
"acre" : [0, 0.00024710538146716534, "ac"]
},
"volume": {
"cubic meter" : [0, 1, "m³"],
"cubic centimeter" : [0, 1000000, "cm³"],
"cubic feet" : [0, 35.31466666, "ft³"],
"quart" : [0, 1056.688209, "qt"],
"pint" : [0, 2113.376419, "pt"],
"fluid ounce" : [0, 33814.0227, "fl oz"],
"milliliter" : [0, 1000000, "mL"],
"liter" : [0, 1000, "L"],
"gallon" : [0, 264.172052, "gal"],
"cup" : [0, 4226.752838, "cp"],
},
"speed": {
"meter per second" : [0, 1, "m/s"],
"feet per second" : [0, 3.28084, "ft/s"],
"kilometers per hour" : [0, 3.6, "km/h"],
"miles per hour" : [0, 2.23694, "mph"],
"knots" : [0, 1.94384, "kn"]
},
"weight": {
"kilogram" : [0, 1, "kg"],
"gram" : [0, 1000, "g"],
"milligram" : [0, 1000000, "mg"],
"ounce" : [0, 35.273962, "oz"], # 28.349523125
"pound" : [0, 2.20462262, "lb"], # 0.45359237
"stone" : [0, 0.157473],
"US ton" : [0, 0.001102311310924388],
"UK ton" : [0, 0.0009842065264486655],
"Metric ton": [0, 0.001],
},
"currency":currency_options,
"time": {
# 365.2421896698-6.15359\cdot10^{-6}a-7.29\cdot10^{-10}a^{2}+2.64\cdot10^{-10}a^{3} where a is centuries of 36525 SI days
# 31556925.1 <- this will hold up for 3 years (until 2025-7-13T21:48:21.351744), after which it will be 31556925.0
# 31556925.0 will hold up for another 18 years (until 2044); after which it will be 31556924.9 for 19 years (2063)
"decenium" : [0, 1/315569251.0, "dec"],
"year" : [0, 1/31556925.1, "yr"],
"month" : [0, 12/31556925.1, "mo"],
"week" : [0, 1/604800, "wk"],
"day" : [0, 1/86400, "d"],
"hour" : [0, 1/3600, "hr"],
"minute" : [0, 1/60, "min"],
"second" : [0, 1, "sec"],
"millisecond" : [0, 10**3, "ms"],
"microsecond" : [0, 10**6, "μs"],
"shake" : [0, 10**8, "shake"],
"nanosecond" : [0, 10**9, "ns"],
"picosecond" : [0, 10**12, "ps"],
"femtosecond" : [0, 10**15, "fs"],
}
}
def generateOutput(responses, author):
output = ""
if len(responses) > 0:
output += f"""Hey there {author.mention},
Thank you for taking the time to answer our questions
If you don't mind, could you answer some more for us?"""
keywords = ["First of all","Next","aaand..","Also","Lastly","PS","PPS","PPPS","PPPPS","PPPPPS","PPPPPPS"]
for index in range(len(responses)):
output += f"""
{keywords[index]},
{responses[index]}"""
if len(output) > 0:
output += """
Once again, if you dislike answering any of these or following questions, feel free to tell me. I can give others.
Thank you in advance :)"""
else:
output += "\n:warning: Couldn't think of any responses."
return output
class SearchAddons(commands.Cog):
def __init__(self, client: Bot):
self.client = client
nameusage = app_commands.Group(name='nameusage', description='Get data about which names are used in the server')
@nameusage.command(name="gettop", description="See how often different names occur in this server")
@app_commands.choices(mode=[
discord.app_commands.Choice(name='Search most-used usernames', value=1),
discord.app_commands.Choice(name='Search most-used nicknames', value=2),
discord.app_commands.Choice(name='Search nicks and usernames', value=3),
])
async def nameusage_gettop(self, itx: discord.Interaction, mode: int):
await itx.response.defer(ephemeral=True)
sections = {}
for member in itx.guild.members:
member_sections = []
if mode == 1: # most-used usernames
names = [member.name]
elif mode == 2 and member.nick is not None: # most-used nicknames
names = [member.nick]
elif mode == 3: # most-used nicks and usernames
names = [member.name]
if member.nick is not None:
names.append(member.nick)
else:
continue
_pronouns = [
"she", "her",
"he", "him",
"they", "them",
"it", "its",
]
pronouns = []
for pronounx in _pronouns:
for pronouny in _pronouns:
pronouns.append(pronounx + " " + pronouny)
for index in range(len(names)):
new_name = ""
for char in names[index]:
if char.lower() in "abcdefghijklmnopqrstuvwxyz":
new_name += char
else:
new_name += " "
for pronoun in pronouns:
_name_backup = new_name + " "
while new_name != _name_backup:
_name_backup = new_name
new_name = re.sub(pronoun, "", new_name, flags=re.IGNORECASE)
names[index] = new_name
def add(part):
if part not in member_sections:
member_sections.append(part)
for name in names:
for section in name.split():
if section in member_sections:
pass
else:
parts = []
match = 1
while match:
match = re.search("[A-Z][a-z]*[A-Z]", section, re.MULTILINE)
if match:
caps = match.span()[1]-1
parts.append(section[:caps])
section = section[caps:]
if len(parts) != 0:
for part in parts:
add(part)
add(section)
else:
add(section)
for section in member_sections:
section = section.lower()
if section in ["the", "any", "not"]:
continue
if len(section) < 3:
continue
if section in sections:
sections[section] += 1
else:
sections[section] = 1
sections = sorted(sections.items(), key=lambda x:x[1], reverse=True)
pages = []
for i in range(int(len(sections)/20+0.999)+1):
result_page = ""
for section in sections[0+20*i:20+20*i]:
result_page += f"{section[1]} {section[0]}\n"
if result_page == "":
result_page = "_"
pages.append(result_page)
page = 0
class Pages(discord.ui.View):
class GetName(discord.ui.Modal, title="Search page with word"):
def __init__(self, pages, embed_title, timeout=None):
super().__init__()
self.value = None
self.timeout = timeout
self.embed_title = embed_title
self.pages = pages
self.page = None
self.word = None
self.question_text = discord.ui.TextInput(label='What word to look up in the server name list?',
placeholder=f"The word you want to look up",
# style=discord.TextStyle.short,
# required=True
)
self.add_item(self.question_text)
async def on_submit(self, itx: discord.Interaction):
self.value = 9 # failed; placeholder
self.word = self.question_text.value.lower()
for page_id in range(len(self.pages)):
# self.pages[page_id] returns ['15 nora\n13 rose\n9 brand\n8 george\n4 rina\n3 grace\n3 chroma\n2 eliza\n','1 cleo','_']
# split at \n and " " to get [["15", "nora"], ["13", "rose"], ["9", "brand"], ["8", "george"]] and compare self.word with the names
if self.word in [name.split(" ")[-1] for name in self.pages[page_id].split("\n")]:
self.page = int(page_id / 2)
break
else:
await itx.response.send_message(
content=f"I couldn't find '{self.word}' in any of the pages! Perhaps nobody chose this name!",
ephemeral=True)
return
result_page = self.pages[self.page * 2]
result_page2 = self.pages[self.page * 2 + 1]
result_page = result_page.replace(f" {self.word}\n", f" **__{self.word}__**\n")
result_page2 = result_page2.replace(f" {self.word}\n", f" **__{self.word}__**\n")
embed = discord.Embed(color=8481900, title=self.embed_title)
embed.add_field(name="Column 1", value=result_page)
embed.add_field(name="Column 2", value=result_page2)
embed.set_footer(text="page: " + str(self.page + 1) + " / " + str(int(len(self.pages) / 2)))
await itx.response.edit_message(embed=embed)
self.value = 1
self.stop()
def __init__(self, pages, embed_title, timeout=None):
super().__init__()
self.value = None
self.timeout = timeout
self.page = 0
self.pages = pages
self.embed_title = embed_title
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label='Previous', style=discord.ButtonStyle.blurple)
async def previous(self, itx: discord.Interaction, _button: discord.ui.Button):
# self.value = "previous"
self.page -= 1
if self.page < 0:
self.page = int(len(self.pages)/2)-1
result_page = self.pages[self.page*2]
result_page2 = self.pages[self.page*2+1]
embed = discord.Embed(color=8481900, title=self.embed_title)
embed.add_field(name="Column 1",value=result_page)
embed.add_field(name="Column 2",value=result_page2)
embed.set_footer(text="page: "+str(self.page+1)+" / "+str(int(len(self.pages)/2)))
await itx.response.edit_message(embed=embed)
@discord.ui.button(label='Next', style=discord.ButtonStyle.blurple)
async def next(self, itx: discord.Interaction, _button: discord.ui.Button):
self.page += 1
if self.page >= int(len(self.pages)/2):
self.page = 0
result_page = self.pages[self.page*2]
result_page2 = self.pages[self.page*2+1]
embed = discord.Embed(color=8481900, title=self.embed_title)
embed.add_field(name="Column 1",value=result_page)
embed.add_field(name="Column 2",value=result_page2)
embed.set_footer(text="page: "+str(self.page+1)+" / "+str(int(len(self.pages)/2)))
await itx.response.edit_message(embed=embed)
@discord.ui.button(label='Find my name', style=discord.ButtonStyle.blurple)
async def find_name(self, itx: discord.Interaction, _button: discord.ui.Button):
send_one = Pages.GetName(self.pages, self.embed_title)
await itx.response.send_modal(send_one)
await send_one.wait()
if send_one.value in [None, 9]:
pass
else:
self.page = send_one.page
result_page = pages[page]
result_page2 = pages[page+1]
embed_title = f'Most-used {"user" if mode==1 else "nick" if mode==2 else "usernames and nick"}names leaderboard!'
embed = discord.Embed(color=8481900, title=embed_title)
embed.add_field(name="Column 1",value=result_page)
embed.add_field(name="Column 2",value=result_page2)
embed.set_footer(text="page: "+str(page+1)+" / "+str(int(len(pages)/2)))
view = Pages(pages, embed_title, timeout=60)
await itx.followup.send(f"",embed=embed, view=view,ephemeral=True)
await view.wait()
if view.value is None:
await itx.edit_original_response(view=None)
@nameusage.command(name="name", description="See how often different names occur in this server")
@app_commands.describe(name="What specific name are you looking for?")
@app_commands.choices(type=[
discord.app_commands.Choice(name='usernames', value=1),
discord.app_commands.Choice(name='nicknames', value=2),
discord.app_commands.Choice(name='Search both nicknames and usernames', value=3),
])
async def nameusage_name(self, itx: discord.Interaction, name: str, type: int, public: bool = False):
await itx.response.defer(ephemeral=not public)
count = 0
type_string = ""
if type == 1: # usernames
for member in itx.guild.members:
if name.lower() in member.name.lower():
count += 1
type_string = "username"
elif type == 2: # nicknames
for member in itx.guild.members:
if member.nick is not None:
if name.lower() in member.nick.lower():
count += 1
type_string = "nickname"
elif type == 3: # usernames and nicknames
for member in itx.guild.members:
if member.nick is not None:
if name.lower() in member.nick.lower() or name.lower() in member.name.lower():
count += 1
elif name.lower() in member.name.lower():
count += 1
type_string = "username or nickname"
await itx.followup.send(f"I found {count} people with '{name.lower()}' in their {type_string}",ephemeral=not public)
@app_commands.command(name="equaldex", description="Find info about LGBTQ+ laws in different countries!")
@app_commands.describe(country_id="What country do you want to know more about? (GB, US, AU, etc.)")
async def equaldex(self, itx: discord.Interaction, country_id: str):
illegal_characters = ""
for char in country_id:
if char not in "abcdefghijklmnopqrstuvwxyz":
if char not in illegal_characters:
illegal_characters += char
if len(illegal_characters) > 1:
await itx.response.send_message(f"You can't use the following characters for country_id!\n> {illegal_characters}", ephemeral=True)
return
response_api = requests.get(
f"https://www.equaldex.com/api/region?regionid={country_id}&formatted=true").text
# returns -> <pre>{"regions":{...}}</pre> <- so you need to remove the <pre> and </pre> parts
# it also has some <br \/>\r\n strings in there for some reason..? so uh
jsonizing_table = str.maketrans({
r"<br \/>\r\n":r"\n",
"<pre>":"",
"</pre>":""
})
response_api = response_api.translate(jsonizing_table)
data = json.loads(response_api)
if "error" in data:
if country_id.lower() == "uk":
await itx.response.send_message(f"I'm sorry, I couldn't find '{country_id}'...\nTry 'GB' instead!", ephemeral=True)
else:
await itx.response.send_message(f"I'm sorry, I couldn't find '{country_id}'...",ephemeral=True)
return
class Region:
def __init__(self, data):
self.id = data['region_id']
self.name = data['name']
self.continent = data['continent']
self.url = data['url']
self.issues = data['issues']
region = Region(data['regions']['region'])
embed = discord.Embed(color=7829503, title=region.name)
for issue in region.issues:
if type(region.issues[issue]['current_status']) is list:
value = "No data"
else:
value = region.issues[issue]['current_status']['value_formatted']
# if region.issues[issue]['current_status']['value'] in ['Legal',
# 'Equal',
# 'No censorship',
# 'Legal, '
# 'surgery not required',
# "Sexual orientation and gender identity",
# "Recognized"]:
# value = "❤️ " + value
# elif region.issues[issue]['current_status']['value'] in ["Illegal"]:
# value = "🚫 " + value
# elif region.issues[issue]['current_status']['value'] in ["Not legally recognized",
# "Not banned",
# "Varies by Region"]:
# value = "🟨 " + value
# else:
# value = "➖ " + value
if len(region.issues[issue]['current_status']['description']) > 0:
value += f" ({region.issues[issue]['current_status']['description']})"
elif len(region.issues[issue]['description']) > 0:
value += f" ({region.issues[issue]['description']})"
if len(value) > 1024:
value = value[:1020]+"..."
embed.add_field(name = region.issues[issue]['label'],
value = value,
inline = False)
embed.set_footer(text=f"For more info, click the button below,")
class MoreInfo(discord.ui.View):
def __init__(self, url):
super().__init__()
link_button = discord.ui.Button(style = discord.ButtonStyle.gray,
label = "More info",
url = url)
self.add_item(link_button)
view = MoreInfo(region.url)
await itx.response.send_message(embed=embed, view=view, ephemeral=True)
@app_commands.command(name="math", description="Ask Wolfram Alpha a question")
async def math(self, itx: discord.Interaction, query: str):
await itx.response.defer(ephemeral=True)
if query.lower() in ["help", "what is this", "what is this?"]:
await itx.followup.send(
"This is a math command that connects to the Wolfram Alpha website! "
"You can ask it math or science questions, and it will answer them for you! Kinda like an AI. "
"It uses scientific data. Here are some example queries:\n"
"- What is 9+10\n"
"- What is the derivative of 4x^2+3x+5\n"
"- What color is the sky?", ephemeral=True)
return
if "&" in query:
await itx.response.send_message("Your query cannot contain an ampersand (&/and symbol)! (it can mess with the URL)", ephemeral=True)
return
query = query.replace("+", " plus ") # plusses are interpreted as a spacebar in urls. In LaTeX, that can mean multiply
api_key = self.client.api_tokens['Wolfram Alpha']
try:
data = requests.get(
f"http://api.wolframalpha.com/v2/query?appid={api_key}&input={query}&output=json").json()
except requests.exceptions.JSONDecodeError:
await itx.followup.send("Your input gave a malformed result! Perhaps it took too long to calculate...", ephemeral=True)
return
class SendPublic(discord.ui.View):
def __init__(self, client: Bot, timeout=180):
super().__init__()
self.value = None
self.client = client
self.timeout = timeout
@discord.ui.button(label='Send Publicly', style=discord.ButtonStyle.gray)
async def send_publicly(self, itx: discord.Interaction, _button: discord.ui.Button):
self.value = 1
await itx.response.edit_message(content="Sent successfully!")
cmd_mention = self.client.get_command_mention("math")
await itx.followup.send(f"**{itx.user.mention} shared a {cmd_mention} output:**\n" + itx.message.content, ephemeral=False, allowed_mentions=discord.AllowedMentions.none())
data = data["queryresult"]
if data["success"]:
interpreted_input = ""
output = ""
other_primary_outputs = []
error_or_nodata = 0
for pod in data["pods"]:
subpods = []
if pod["id"] == "Input":
for subpod in pod["subpods"]:
subpods.append(subpod["plaintext"].replace("\n", "\n> "))
interpreted_input = '\n> '.join(subpods)
if pod["id"] == "Result":
for subpod in pod["subpods"]:
if subpod.get("nodata") or subpod.get("error"): # error or nodata == True
error_or_nodata += 1
subpods.append(subpod["plaintext"].replace("\n", "\n> "))
output = '\n> '.join(subpods)
elif pod.get("primary", False):
for subpod in pod["subpods"]:
if len(subpod["plaintext"]) == 0:
continue
if subpod.get("nodata") or subpod.get("error"): # error or nodata == True
error_or_nodata += 1
other_primary_outputs.append(subpod["plaintext"].replace("\n", "\n> "))
if len(output) == 0 and len(other_primary_outputs) == 0:
error_or_nodata = 0
# if there is no result and all other pods are 'primary: False'
for pod in data["pods"]:
if pod["id"] not in ["Input", "Result"]:
for subpod in pod["subpods"]:
if len(subpod["plaintext"]) == 0:
continue
if subpod.get("nodata") or subpod.get("error"): # error or nodata == True
error_or_nodata += 1
other_primary_outputs.append(subpod["plaintext"].replace("\n", "\n> "))
if len(other_primary_outputs) > 0:
other_results = '\n> '.join(other_primary_outputs)
other_results = "\nOther results:\n> " + other_results
else:
other_results = ""
if len(other_primary_outputs) + bool(len(output)) <= error_or_nodata:
# if there are more or an equal amount of errors as there are text entries
await itx.followup.send(f"There was no data for your answer!\n"
f"It seems all your answers had an error or were 'nodata entries', meaning "
f"you might need to try a different query to get an answer to your question!", ephemeral=True)
return
assumptions = []
if "assumptions" in data:
if type(data["assumptions"]) is dict:
# only 1 assumption, instead of a list. So just make a list of 1 assumption instead.
data["assumptions"] = [data["assumptions"]]
for assumption in data.get("assumptions", []):
assumption_data = {} # because Wolfram|Alpha is being annoyingly inconsistent.
if "word" in assumption:
assumption_data["${word}"] = assumption["word"]
for value_index in range(len(assumption["values"])):
assumption_data["${desc"+str(value_index + 1)+"}"] = assumption["values"][value_index]["desc"]
try:
assumption_data["${word"+str(value_index + 1)+"}"] = assumption["values"][value_index]["word"]
except KeyError:
pass # the "word" variable is only there sometimes. for some stupid reason.
template: str = assumption["template"]
for replacer in assumption_data:
template = template.replace(replacer, assumption_data[replacer])
if template.endswith("."):
template = template[:-1]
assumptions.append(template + "?")
if len(assumptions) > 0:
alternatives = "\nAssumptions:\n> " + '\n> '.join(assumptions)
else:
alternatives = ""
warnings = []
if "warnings" in data:
# not sure if multiple warnings will be stored into a list instead
warnings.append(data["warnings"]["text"])
if len(data.get("timedout", "")) > 0:
warnings.append("Timed out: " + data["timedout"].replace(",", ", "))
if len(data.get("timedoutpods", "")) > 0:
warnings.append("Timed out pods: " + data["timedout"].replace(",", ", "))
if len(warnings) > 0:
warnings = "\nWarnings:\n> " + '\n> '.join(warnings)
else:
warnings = ""
view = SendPublic(self.client)
await itx.followup.send(
f"Input\n> {interpreted_input}\n"
f"Result:\n> {output}" +
other_results +
alternatives +
warnings, view=view, ephemeral=True)
await view.wait()
if view.value is None:
await itx.edit_original_response(view=None)
return
else:
if data["error"]:
code = data["error"]["code"]
message = data["error"]["msg"]
await itx.followup.send(f"I'm sorry, but I wasn't able to give a response to that!\n"
f"> code: {code}\n"
f"> message: {message}", ephemeral=True)
return
elif "didyoumeans" in data:
didyoumeans = {}
if type(data["didyoumeans"]) is list:
for option in data["didyoumeans"]:
didyoumeans[option["score"]] = option["val"]
else:
didyoumeans[data["didyoumeans"]["score"]] = data["didyoumeans"]["val"]
options_sorted = sorted(didyoumeans.items(), key=lambda x: float(x[0]), reverse=True)
options = [value for _, value in options_sorted]
options_str = "\n> ".join(options)
await itx.followup.send(f"I'm sorry, but I wasn't able to give a response to that! However, here are some possible improvements to your prompt:\n"
f"> {options_str}", ephemeral=True)
return
elif "languagemsg" in data: # x does not support [language].
await itx.followup.send(f"Error:\n> {data['languagemsg']['english']}\n"
f"> {data['languagemsg']['other']}", ephemeral=True)
return
elif "futuretopic" in data: # x does not support [language].
await itx.followup.send(f"Error:\n> {data['futuretopic']['topic']}\n"
f"> {data['futuretopic']['msg']}", ephemeral=True)
return
# why aren't these in the documentation? cmon wolfram, please.
elif "tips" in data:
# not sure if this is put into a list if there are multiple.
await itx.followup.send(f"Error:\n> {data['tips']['text']}", ephemeral=True)
return
elif "examplepage" in data:
# not sure if this is put into a list if there are multiple.
await itx.followup.send(f"Here is an example page for the things you can do with {data['examplepage']['category']}:\n"
f"> {data['examplepage']['url']}", ephemeral=True)
return
else:
# welp. Apparently you can get *no* info in the output as well!! UGHHHHH
await itx.followup.send("Error: No further info\n"
"It appears you filled in something for which I can't get extra feedback..\n"
"Feel free to report the situation to MysticMia#7612", ephemeral=True)
return
await itx.followup.send("debug; It seems you reached the end of the function without "
"actually getting a response! Please report the query to MysticMia#7612", ephemeral=True)
class OtherAddons(commands.Cog):
def __init__(self, client: Bot):
global RinaDB, asyncRinaDB
client.on_message_events.append(self.on_message_addons)
self.client = client
RinaDB = client.RinaDB
asyncRinaDB = client.asyncRinaDB
self.headpatWait = 0
async def on_message_addons(self, message: revolt.Message):
# global report_message_reminder_unix
# try: # mention targeted user if added to mod-ticket with /add target:@user
# if message.channel.category.id in [995330645901455380, 995330667665707108, 1086349703182041089]:
# print("embeds:", len(message.embeds), "| message.author.id:", message.author.id)
# if message.author.id == 557628352828014614 and len(message.embeds) == 1:
# # if ticket tool adds a user to a ticket, reply by mentioning the newly added user
# components = message.embeds[0].description.split(" ")
# print("components:", repr(components))
# print("@" in components[0])
# print(f'{components[1]} {components[2]} {components[3]} == "added to ticket"', f"{components[1]} {components[2]} {components[3]}" == "added to ticket")
# if "@" in components[0] and f"{components[1]} {components[2]} {components[3]}" == "added to ticket":
# await message.channel.send("Obligatory ping to notify newly added user: " + components[0], allowed_mentions=discord.AllowedMentions.all())
# except AttributeError:
# pass
if message.author.bot:
return
# #random cool commands
# self.headpatWait += 1
# if self.headpatWait >= 1000:
# ignore = False
# if type(message.channel) is discord.Thread:
# if message.channel.parent == 987358841245151262: # <#welcome-verify>
# ignore = True
# if message.channel.name.startswith('ticket-') or message.channel.name.startswith('closed-'):
# ignore = True
# if message.channel.category.id in [959584962443632700, 959590295777968128, 959928799309484032, 1041487583475138692,
# 995330645901455380, 995330667665707108]:
# # <#Bulletin Board>, <#Moderation Logs>, <#Verifier Archive>, <#Events>, <#Open Tickets>, <#Closed Tickets>
# ignore = True
# if message.guild.id in [981730502987898960]: # don't send in Mod server
# ignore = True
# if not ignore:
# self.headpatWait = 0
# try:
# await message.add_reaction("<:TPF_02_Pat:968285920421875744>") #headpatWait
# except discord.errors.HTTPException:
# await log_to_guild(self.client, message.guild, f'**:warning: Warning: **Couldn\'t add pat reaction to {message.jump_url}. They might have blocked Rina...')
# try:
# await message.add_reaction("☺") # relaxed
# except discord.errors.Forbidden:
# pass
# for staff_role_mention in ["<@&981735650971775077>", "<@&1012954384142966807>", "<@&981735525784358962>"]:
# if staff_role_mention in message.content:
# time_now = int(mktime(datetime.now().timetuple())) # get time in unix
# if time_now - report_message_reminder_unix > 900: # 15 minutes
# await Tags().send_report_info("report", message.channel, self.client, additional_info=[message.author.name, message.author.id])
# report_message_reminder_unix = time_now
# break
if self.client.user.mention in message.content.split():
msg = message.content.lower()
if ((("cute" or "cutie" or "adorable" in msg) and "not" in msg) or "uncute" in msg) and "not uncute" not in msg:
try:
await message.add_reaction("<:this:960916817801535528>")
except:
await log_to_guild(self.client, message.guild, f'**:warning: Warning: **Couldn\'t add pat reaction to {message.jump_url}')
raise
elif "cutie" in msg or "cute" in msg:
responses = [
"I'm not cute >_<",
"I'm not cute! I'm... Tough! Badass!",
"Nyaa~",
"Who? Me? No you're mistaken.",
"I very much deny the cuteness of someone like myself",
"If you think I'm cute, then you must be uber-cute!!",
"I don't think so.",
"Haha. Good joke. Tell me another tomorrow",
"Ehe, cutie what do u need help with?",
"No, I'm !cute.",
"You too!",
"No, you are <3",
"[shocked] Wha- w. .. w what?? .. NOo? no im nott?\nwhstre you tslking about?",
"Oh you were talking to me? I thought you were talking about everyone else here,",
"Nope. I doubt it. There's no way I can be as cute as you",
"Maybe.. Maybe I am cute.",
"If the sun was dying, would you still think I was cute?",
"Awww. Thanks sweety, but you've got the wrong number",
":joy: You *reaaally* think so? You've gotta be kidding me.",
"If you're gonna be spamming this, .. maybe #general isn't the best channel for that.",
"You gotta praise those around you as well. "+(message.author.nickname or message.author.name)+", for example, is very cute.",
"Oh by the way, did I say "+(message.author.nickname or message.author.name)+" was cute yet? I probably didn't. "+(message.author.nickname or message.author.name)+"? You're very cute",
"Such nice weather outside, isn't it? What- you asked me a question?\nNo you didn't, you're just talking to youself.",
"".join(random.choice("acefgilrsuwnopacefgilrsuwnopacefgilrsuwnop;; ") for _ in range(random.randint(10,25))), # 3:2 letters to symbols
"Oh I heard about that! That's a way to get randomized passwords from a transfem!",
"Cuties are not gender-specific. For example, my cat is a cutie!\nOh wait, species aren't the same as genders. Am I still a catgirl then? Trans-species?",
"...",
"Hey that's not how it works!",
"Hey my lie detector said you are lying.",
"You know i'm not a mirror, right?",
"*And the oscar for cutest responses goes to.. YOU!!*",
"No I am not cute",
"k",
(message.author.nickname or message.author.name)+", stop lying >:C",
"BAD!",
"You're also part of the cuties set",
"https://cdn.discordapp.com/emojis/920918513969950750.webp?size=4096&quality=lossless",
"[Checks machine]; Huh? Is my lie detector broken? I should fix that..",
"Hey, you should be talking about yourself first! After all, how do you keep up with being such a cutie all the time?"]
respond = random.choice(responses)
if respond == "BAD!":
await message.channel.send("https://cdn.discordapp.com/emojis/902351699182780468.gif?size=56&quality=lossless")
await message.channel.send(respond)
else:
cmd_mention = self.client.get_command_mention("help")
msg = await message.channel.send(f"I use chat commands! Use {cmd_mention} and see what cool things might pop up!\nPS: If you're trying to call me cute: no, I'm not")
await asyncio.wait(8)
await msg.delete()
@commands.command(cls=CustomCommand, usage={
"description":"Force Rina to repeat your wise words",
"usage":"say <text...>",
"examples":["say Good morning everyone"],
"parameters":{
"text":{
"description":"What will you make Rina repeat?",
"type": CustomCommand.template("str", wrapped=True)
}
}
})
async def say(self, ctx: commands.Context, *text: str):
if not is_staff(ctx):
await ctx.message.reply("Hi. sorry.. It would be too powerful to let you very cool person use this command.")
return
print(type(self), repr(self), str(self), dir(self))
text = ' '.join(text)
if text == "":
await ctx.client.dispatch("command_error", ctx, RuntimeError)
cmd_mention = self.client.get_command_mention("editguildinfo")
vc_log = await self.client.get_guild_info(ctx.server, "vcLog", log=[
ctx, "Couldn't send your message. You can't send messages in this server because the bot setup seems incomplete\n"
f"Use {cmd_mention} `11` to fix this!"])
try:
# vcLog = guild["vcLog"]
log_channel = ctx.server.get_channel(vc_log)
await log_channel.send(f"{ctx.author.name} ({ctx.author.id}) said a message using Rina: {safe_string(text)}")
text = text.replace("[[\\n]]","\n").replace("[[del]]","")
await ctx.channel.send(f"{text}")
except revolt.errors.Forbidden:
await ctx.message.reply("Forbidden! I can't send a message in this channel/thread because I can't see it or because I'm not added to it yet!\n(Add me to the thread by mentioning me, or let Rina see this channel)")
return
except:
#No longer necessary: this gets caught by the on_app_command_error() event in the main file.
# await ctx.message.reply("Oops. Something went wrong!")
raise
#No longer necessary: Revolt doesn't have ephemeral 'confirm' messages :(
# await ctx.message.reply("Successfully sent!")
# @app_commands.command(name="compliment", description="Complement someone fem/masc/enby")
# @app_commands.describe(user="Who do you want to compliment?")
# async def compliment(self, itx: discord.Interaction, user: discord.User):
# # discord.User because discord.Member gets errors.TransformerError in DMs (dunno why i'm accounting for that..)
# try:
# user: discord.Member # make IDE happy, i guess
# userroles = user.roles[:]
# except AttributeError:
# await itx.response.send_message("Aw man, it seems this person isn't in the server. I wish I could compliment them but they won't be able to see it!", ephemeral=True)
# return
# async def call(itx, user, type):
# quotes = {
# "fem_quotes": [
# # "Was the sun always this hot? or is it because of you?",
# # "Hey baby, are you an angel? Cuz I’m allergic to feathers.",
# # "I bet you sweat glitter.",
# "Your hair looks stunning!",
# "Being around you is like being on a happy little vacation.",
# "Good girll",
# "Who's a good girl?? You are!!",
# "Amazing! Perfect! Beautiful! How **does** she do it?!",
# "I can tell that you are a very special and talented girl!",
# "Here, have this cute sticker!",
# "Beep boop :zap: Oh no! my circuits overloaded! Her cuteness was too much for me to handle!",
# ],
# "masc_quotes": [
# "You are the best man out there.",
# "You are the strongest guy I know.",
# "You have an amazing energy!",
# "You seem to know how to fix everything!",
# "Waw, you seem like a very attractive guy!",
# "Good boyy!",
# "Who's a cool guy? You are!!",
# "I can tell that you are a very special and talented guy!",
# "You're such a gentleman!",
# "You always know how to make people feel welcome and included :D",
# "Your intelligence and knowledge never cease to amaze me :O",
# "Beep boop :zap: Oh no! my circuits overloaded! His aura was so strong that I couldn't generate a cool compliment!",
# ],
# "they_quotes": [
# "I can tell that you are a very special and talented person!",
# "Their, their... ",
# ],
# "it_quotes": [
# "I bet you do the crossword puzzle in ink!",
# ],
# "unisex_quotes": [ #unisex quotes are added to each of the other quotes later on.
# "Hey I have some leftover cookies.. \\*wink wink\\*",
# # "_Let me just hide this here-_ hey wait, are you looking?!", #it were meant to be cookies TwT
# "Would you like a hug?",
# "Would you like to walk in the park with me? I gotta walk my catgirls",
# "morb",
# "You look great today!",
# "You light up the room!",
# "On a scale from 1 to 10, you’re an 11!",
# 'When you say, “I meant to do that,” I totally believe you.',
# "You should be thanked more often. So thank you!",
# "You are so easy to have a conversation with!",
# "Ooh you look like a good candidate to give my pet blahaj to!",
# "Here, have a sticker!",
# "You always know how to put a positive spin on things!",
# "You make the world a better place just by being in it",
# "Your strength and resilience is truly inspiring.",
# "You have a contagious positive attitude that lifts up those around you.",
# "Your positive energy is infectious and makes everyone feel welcomed!",
# "You have a great sense of style and always look so put together <3",
# "You are a truly unique and wonderful person!",
# ]
# }
# type = {
# "she/her" : "fem_quotes",
# "he/him" : "masc_quotes",
# "they/them" : "they_quotes",
# "it/its" : "it_quotes",
# "unisex" : "unisex_quotes", #todo
# }[type]
# for x in quotes:
# if x == "unisex_quotes":
# continue
# else:
# quotes[x] += quotes["unisex_quotes"]
# collection = RinaDB["complimentblacklist"]
# query = {"user": user.id}
# search = collection.find_one(query)
# if search is None:
# blacklist = []
# else:
# blacklist = search["list"]
# for string in blacklist:
# dec = 0
# for x in range(len(quotes[type])):
# if string in quotes[type][x-dec]:
# del quotes[type][x-dec]
# dec += 1
# if len(quotes[type]) == 0:
# quotes[type].append("No compliment quotes could be given... This person seems to have blacklisted every quote.")
# base = f"{itx.user.mention} complimented {user.mention}!\n"
# if itx.response.is_done():
# # await itx.edit_original_response(content=base+random.choice(quotes[type]), view=None)
# await itx.followup.send(content=base+random.choice(quotes[type]), allowed_mentions=discord.AllowedMentions(everyone=False, users=[user], roles=False, replied_user=False))
# else:
# await itx.response.send_message(base+random.choice(quotes[type]), allowed_mentions=discord.AllowedMentions(everyone=False, users=[user], roles=False, replied_user=False))
# async def confirm_gender():
# # Define a simple View that gives us a confirmation menu
# class Confirm(discord.ui.View):
# def __init__(self, timeout=None):
# super().__init__()
# self.value = None
# self.timeout = timeout
# # When the confirm button is pressed, set the inner value to `True` and
# # stop the View from listening to more input.
# # We also send the user an ephemeral message that we're confirming their choice.
# @discord.ui.button(label='She/Her', style=discord.ButtonStyle.green)
# async def feminine(self, itx: discord.Interaction, _button: discord.ui.Button):
# self.value = "she/her"
# await itx.response.edit_message(content='Selected She/Her pronouns for compliment', view=None)
# self.stop()
# @discord.ui.button(label='He/Him', style=discord.ButtonStyle.green)
# async def masculine(self, itx: discord.Interaction, _button: discord.ui.Button):
# self.value = "he/him"
# await itx.response.edit_message(content='Selected He/Him pronouns for the compliment', view=None)
# self.stop()
# @discord.ui.button(label='They/Them', style=discord.ButtonStyle.green)
# async def enby_them(self, itx: discord.Interaction, _button: discord.ui.Button):
# self.value = "they/them"
# await itx.response.edit_message(content='Selected They/Them pronouns for the compliment', view=None)
# self.stop()
# @discord.ui.button(label='It/Its', style=discord.ButtonStyle.green)
# async def enby_its(self, itx: discord.Interaction, _button: discord.ui.Button):
# self.value = "it/its"
# await itx.response.edit_message(content='Selected It/Its pronouns for the compliment', view=None)
# self.stop()
# @discord.ui.button(label='Unisex/Unknown', style=discord.ButtonStyle.grey)
# async def unisex(self, itx: discord.Interaction, _button: discord.ui.Button):
# self.value = "unisex"
# await itx.response.edit_message(content='Selected Unisex/Unknown gender for the compliment', view=None)
# self.stop()
# view = Confirm(timeout=60)
# await itx.response.send_message(f"{user.mention} doesn't have any pronoun roles! Which pronouns would like to use for the compliment?", view=view,ephemeral=True)
# await view.wait()
# if view.value is None:
# await itx.edit_original_response(content=':x: Timed out...', view=None)
# else:
# await call(itx, user, view.value)
# roles = ["he/him", "she/her", "they/them", "it/its"]
# random.shuffle(userroles) # pick a random order for which pronoun role to pick
# for role in userroles:
# if role.name.lower() in roles:
# await call(itx, user, role.name.lower())
# return
# await confirm_gender()
# @app_commands.command(name="complimentblacklist", description="If you dislike words in certain compliments")
# @app_commands.choices(mode=[
# discord.app_commands.Choice(name='Add a string to your compliments blacklist', value=1),
# discord.app_commands.Choice(name='Remove a string from your compliments blacklist', value=2),
# discord.app_commands.Choice(name='Check your blacklisted strings', value=3)
# ])
# @app_commands.describe(string="What sentence or word do you want to blacklist? (eg: 'good girl' or 'girl')")
# async def complimentblacklist(self, itx: discord.Interaction, mode: int, string: str = None):
# if mode == 1: # add an item to the blacklist
# if string is None:
# await itx.response.send_message("With this command, you can blacklist a section of text in compliments. "
# "For example, if you don't like being called 'Good girl', you can "
# "blacklist this compliment by blacklisting 'good' or 'girl'. \n"
# "Note: it's case sensitive", ephemeral=True)
# return
# if len(string) > 150:
# await itx.response.send_message("Please make strings shorter than 150 characters...",ephemeral=True)
# return
# collection = RinaDB["complimentblacklist"]
# query = {"user": itx.user.id}
# search = collection.find_one(query)
# if search is None:
# blacklist = []
# else:
# blacklist = search['list']
# blacklist.append(string)
# collection.update_one(query, {"$set":{f"list":blacklist}}, upsert=True)
# await itx.response.send_message(f"Successfully added {repr(string)} to your blacklist. ({len(blacklist)} item{'s'*(len(blacklist)!=1)} in your blacklist now)",ephemeral=True)
# elif mode == 2: # Remove item from black list
# if string is None:
# cmd_mention = self.client.get_command_mention("complimentblacklist")
# await itx.response.send_message(f"Type the id of the string you want to remove. To find the id, type {cmd_mention} `mode:Check`.", ephemeral=True)
# return
# try:
# string = int(string)
# except ValueError:
# await itx.response.send_message("To remove a string from your blacklist, you must give the id of the string you want to remove. This should be a number... You didn't give a number...", ephemeral=True)
# return
# collection = RinaDB["complimentblacklist"]
# query = {"user": itx.user.id}
# search = collection.find_one(query)
# if search is None:
# await itx.response.send_message("There are no items on your blacklist, so you can't remove any either...",ephemeral=True)
# return
# blacklist = search["list"]