-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmain.py
903 lines (802 loc) · 33 KB
/
main.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
# bot.py
import os
import json
import discord
from dotenv import load_dotenv
import re
import random
from mtsbotdata import aliases, suggestables
import timeout
load_dotenv()
token = os.getenv("DISCORD_TOKEN")
pin_links = [
"https://media.discordapp.net/attachments/398373038732738570/543527729077682187/sts-check-the-pins.gif",
"https://media.discordapp.net/attachments/504438263012917254/542101742377107467/kumikopins.gif",
"https://cdn.discordapp.com/attachments/504438263012917254/632966857292513320/fireworks.gif",
"https://cdn.discordapp.com/attachments/504438263012917254/632966856596127745/ruiPins.gif",
]
broken_mod_situation = [
"Thanks to the 2.0 update changing the game code, many mods that were compatible with 1.1 will probably have bugs or crash when used with 2.0, most mods should be fixed eventually (we hope).",
"Modders are working in mod fixing for 2.0, plz be patient :)"
]
client = discord.Client()
prefix = "?"
banned_users = []
uncolor = re.compile(r"^\[#[0-9A-Fa-f]{6}\](\S+?)$")
energy = re.compile(r"^(\[[RGBWE]])(.?)$")
default_energy = "<:red_energy:382625376838615061>"
icon_dictionary = {
"[R]": "<:red_energy:382625376838615061>",
"[G]": "<:green_energy:646206147220471808>",
"[B]": "<:blue_energy:668151236003889184>",
"[W]": "<:purple_energy:620384758068674560>"
}
color_dictionary = {
"Red": "<:red_energy:382625376838615061>",
"Green": "<:green_energy:646206147220471808>",
"Blue": "<:blue_energy:668151236003889184>",
"Purple": "<:purple_energy:620384758068674560>",
"Colorless": "<:colorless_energy:382625433016991745>"
}
class Mod_Data:
def __init__(self, id):
self.data = self.get_data(id)
def get_data(self, id):
data = []
if os.path.exists(f"data/{id}.json"):
with open(f"data/{id}.json") as json_file:
data.append(json.load(json_file))
else:
for file in os.listdir("data/"):
with open(f"data/{file}") as json_file:
data.append(json.load(json_file))
return data
@client.event
async def on_ready():
print(f"{client.user} has connected to Discord!")
def is_command(message):
return message.content.startswith(prefix)
def del_char(string, index):
return string[1:]
@client.event
async def on_message(message):
if message.author == client.user:
return
if (
message.content.lower() == "update body text"
and message.author.id == 114667440507453441
):
await message.channel.send("UPDATE BODY TEXT")
return
if (
message.content.lower() == "big thanks papa kio!"
and message.author.id == 95258954090676224
):
await message.channel.send("Big thanks papa Kio!")
return
if is_command(message):
print(message.content)
message.content = del_char(message.content, len(prefix))
await get_id(message)
async def get_id(message):
s = message.content.lower()
if s == "help":
await help_command(message.channel)
return
if s == "praise":
if message.author.id == 132940023522656256:
await message.channel.send("i love reina <3")
if message.author.id == 86261397213708288:
await message.channel.send("i love alchy <3")
return
if s == "notneh" and message.author.id == 125669982041276416:
await message.channel.send("djbtkdkfndn")
return
if s == "contribute":
await message.channel.send(
"https://github.com/runttekita/mts-bot/blob/master/CONTRIBUTING.md"
)
return
if s == "list":
await message.channel.send(
"https://github.com/runttekita/mts-bot/tree/master/data"
)
return
if s == "default":
await message.channel.send("https://github.com/Gremious/StS-DefaultModBase")
return
if s == "pins" or s == "pin":
await message.channel.send(random.choice(pin_links))
return
if s == "brokenmod":
await message.channel.send(random.choice(broken_mod_situation))
return
if s == "xy":
await message.channel.send("http://xyproblem.info/")
return
if s == "debugger":
await message.channel.send(
"https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems"
)
return
if s == "spirepatch":
await message.channel.send(
"https://github.com/kiooeht/ModTheSpire/wiki/SpirePatch"
)
return
if s == "cardmods":
await message.channel.send(
"https://github.com/daviscook477/BaseMod/wiki/CardModifiers"
)
return
if s == "optin":
await message.channel.send(
"https://github.com/velvet-halation/mts-bot/blob/master/README.md#opt-in-for-receiving-feedback"
)
return
if s == "console":
await message.channel.send(
"Enable it on the Main Menu by going to Mods>BaseMod>Config>Enable console.\n"
+ "Then hit ` while in a run."
)
return
if s == "relic:124":
await message.channel.send(
"https://github.com/daviscook477/BaseMod/wiki/Custom-Relics#relicstrings"
)
return
if s == "cansuggest":
await message.channel.send(
"https://github.com/velvet-halation/mts-bot/blob/master/mtsbotdata.py#L32"
)
if s == "pathwater":
await message.channel.send(
"https://cdn.discordapp.com/attachments/398373038732738570/633779880873689110/FB_IMG_1570999646277.png"
)
if len(s.split(" ")) == 1:
return
tokenized_message = tokenize_message(s)
if (
message.author.id in banned_users
and tokenized_message[1] == "bug"
or tokenized_message[1] == "feedback"
or tokenized_message[1] == "suggestion"
):
return
await do_command(message.channel, tokenized_message)
def tokenize_message(message):
if len(message.split(" ")) >= 3:
for mod in aliases:
names = aliases.get(mod)
if message.split(" ")[1] in names:
tokenized_message = message.split(" ", 2)
del tokenized_message[1]
tokenized_message.insert(1, mod)
print(tokenized_message)
return tokenized_message
if os.path.exists(f'data/{message.split(" ")[1]}.json'):
return message.split(" ", 2)
else:
return message.split(" ", 1)
def check_for_aliases(self, id):
print(id)
for mod in aliases:
mod_aliases = aliases.get(mod)
if id in mod_aliases:
return mod
async def do_command(channel, tokenized_message):
commands = {
"help": help_command,
"card": card,
"relic": relic,
"keyword": keyword,
"suggestion": dm_modder,
"bug": dm_modder,
"feedback": dm_modder,
"find": find,
"findcard": find,
"findrelic": findrelic,
"modder": get_mods_by_author,
"mod": get_mod_info
}
callback = commands.get(tokenized_message[0])
await callback(channel, tokenized_message)
@client.event
async def get_mod_info(channel, tokenized_message):
"""
Get the info for a mod for the `?mod` command
Example: ?mod challengethespire
Input: ["mod", "challengethespire"]
Output: **Challenge The Spire**
Author: alexdriedger
Boss Rush, Elite Rush, & Sneaky Strike!! Challenge The Spire adds a variety of challenge modes to Slay The Spire.
:param channel: Channel to send message to
:param tokenized_message: List of Strings with length == 2. The first string should be "mod" and the second string
should be the file name (without the .json) of the mod to get information about
:return: None
"""
mod = Mod_Data(tokenized_message[1]).data
# If a mod name is supplied that a file doesn't exist for, `Mod_Data` will load all mod data
if len(mod) != 1:
await channel.send(f"**{tokenized_message[1]}** is not a mod! (Or the author has not uploaded the data to me)")
return
# Mod has a file but doesn't have mod info
if "mod" not in mod[0]:
# await channel.send(f"**{tokenized_message[1]}** does not have a correctly formatted data file. Complain to the mod author")
print(f"**{tokenized_message[1]}** does not have a correctly formatted data file. Complain to the mod author")
return
mod_data = mod[0]["mod"]
# Check if the file is incorrectly formatted
if (
mod_data["name"] is None
or mod_data["authors"] is None
or len(mod_data["authors"]) == 0
or mod_data["description"] is None
):
await channel.send(f"**{tokenized_message[1]}** does not have a correctly formatted data file. Complain to the mod author")
return
# Formatted message should resemble
# My Awesome Mod
# Author: Casey Yano
# This mod makes the spire more awesome by updating body text
message = f"""**{mod_data["name"]}**\n"""
message += "Authors:\t" if len(mod_data["authors"]) > 1 else "Author:\t"
for author in mod_data["authors"]:
message += author
message += ", "
message = message[: -2] # Remove last comma and space
message += "\n"
message += mod_data["description"]
await channel.send(message)
@client.event
async def get_mods_by_author(channel, tokenized_message):
mod_list = []
author_name = "reina" if tokenized_message[1] == "reina" else None
for mod in Mod_Data("").data:
if (
"mod" in mod
and "authors" in mod["mod"]
and tokenized_message[1]
in [author.lower() for author in mod["mod"]["authors"]]
):
mod_list.append("`%s`" % mod["mod"]["name"])
if author_name is None:
author_name = mod["mod"]["authors"][
[author.lower() for author in mod["mod"]["authors"]].index(
tokenized_message[1]
)
] # Ugly way to get the correct caps for a name since tokenized_message is always lowercase
if len(mod_list) == 0:
await channel.send("**%s** does not have any mods" % tokenized_message[1])
else:
await channel.send("**%s**\n%s" % (author_name, " ".join(mod_list)))
@client.event
async def find(channel, tokenized_message):
"""
find a card
-n causes to search name rather than description
-c=amount specifies a card cost
-t=attack/skill/power to specify card type
-r= to specify rarity
"""
try:
with timeout.timeout(1):
cards = Mod_Data(tokenized_message[1]).data
random.shuffle(cards)
first_match = {}
other_results = {}
search_field = "description"
cost = None
type = None
rarity = None
if len(tokenized_message) == 3:
tokens = tokenized_message[2].split()
else:
tokens = tokenized_message[1].split()
data = ""
for item in tokens:
if data == "": # Once any value is found, the rest should be input regex
if item == "-n" and search_field != "name":
search_field = "name"
continue
if cost is None and item.startswith("-c=") and len(item) > 3:
cost = item[3:]
continue
if type is None and item.startswith("-t=") and len(item) > 3:
type = item[3:]
continue
if rarity is None and item.startswith("-r=") and len(item) > 3:
rarity = item[3:]
continue
data += item + " "
data = data[:-1]
if data == "":
data = "^[\s\S]*$"
regex = re.compile(data)
failure = "No card "
if cost is not None:
failure += "with cost " + cost + " "
if type is not None:
failure += "of type " + type + " "
if rarity is not None:
failure += "of rarity " + rarity + " "
if len(tokenized_message) == 3:
failure += f"with {data} in the {search_field} found in {tokenized_message[1]}."
else:
failure += f"with {data} in the {search_field} found."
for x in range(len(cards)):
for card in cards[x]["cards"]:
if cost is not None and card["cost"].lower() != cost:
continue
if type is not None and card["type"].lower() != type:
continue
if rarity is not None and card["rarity"].lower() != rarity:
continue
if len(tokenized_message) == 3:
if regex.search(card[search_field].lower()):
if "mod" in cards[x]:
if not first_match:
first_match.update({cards[x]["mod"]["name"]: card})
else:
if len(other_results) < 3:
other_results.update(
{cards[x]["mod"]["name"]: card["name"]}
)
else:
if not first_match:
first_match.update({card["mod"]: card})
else:
if len(other_results) < 3:
other_results.update({card["mod"]: card["name"]})
else:
if regex.search(card[search_field].lower()):
if "mod" in cards[x]:
if not first_match:
first_match.update({cards[x]["mod"]["name"]: card})
else:
if len(other_results) < 3:
other_results.update(
{cards[x]["mod"]["name"]: card["name"]}
)
else:
if not first_match:
first_match.update({card["mod"]: card})
else:
if len(other_results) < 3:
other_results.update({card["mod"]: card["name"]})
message = ""
if first_match:
for key in first_match:
message += card_format(first_match.get(key), key) + "\n"
if len(other_results) > 3:
other_results = other_results[:2]
if other_results:
message += "Other matches include:\n"
for match in other_results:
name = other_results.get(match)
message += f"`{makeCaps(name)} from {makeCaps(match)}` "
await channel.send(message)
return
await channel.send(failure)
except TimeoutError:
await channel.send("Unable to find a match in time!")
@client.event
async def findrelic(channel, tokenized_message):
"""
find a relic
-n causes to search name rather than description
-c= to specify a color
-t= to specify tier
"""
try:
with timeout.timeout(1):
relics = Mod_Data(tokenized_message[1]).data
random.shuffle(relics)
first_match = {}
other_results = {}
search_field = "description"
tier = None
color = None
if len(tokenized_message) == 3:
tokens = tokenized_message[2].split()
else:
tokens = tokenized_message[1].split()
data = ""
for item in tokens:
if data == "": # Once any value is found, the rest should be input regex
if item == "-n" and search_field != "name":
search_field = "name"
continue
if color is None and item.startswith("-c=") and len(item) > 3:
color = item[3:]
continue
if tier is None and item.startswith("-t=") and len(item) > 3:
tier = item[3:]
continue
data += item + " "
data = data[:-1]
if data == "":
data = "^[\s\S]*$"
regex = re.compile(data)
failure = "No relic "
if color is not None:
failure += "of color " + color + " "
if tier is not None:
failure += "of tier " + tier + " "
if len(tokenized_message) == 3:
failure += f"with {data} in the {search_field} found in {tokenized_message[1]}."
else:
failure += f"with {data} in the {search_field} found."
for x in range(len(relics)):
for relic in relics[x]["relics"]:
if tier is not None and relic["tier"].lower() != tier:
continue
if color is not None and relic["pool"].lower() != color:
continue
if regex.search(relic[search_field].lower()):
if "mod" in relics[x]:
if not first_match:
first_match.update({relics[x]["mod"]["name"]: relic})
else:
if len(other_results) < 3:
other_results.update(
{relics[x]["mod"]["name"]: relic["name"]}
)
else:
if not first_match:
first_match.update({relic["mod"]: relic})
else:
if len(other_results) < 3:
other_results.update({relic["mod"]: relic["name"]})
message = ""
if first_match:
for key in first_match:
message += relic_format(first_match.get(key), key) + "\n"
if len(other_results) > 3:
other_results = other_results[:2]
if other_results:
message += "Other matches include:\n"
for match in other_results:
name = other_results.get(match)
message += f"`{makeCaps(name)} from {makeCaps(match)}` "
await channel.send(message)
return
await channel.send(failure)
except TimeoutError:
await channel.send("Unable to find a match in time!")
def makeCaps(string):
split_word = string.split(" ")
for word in split_word:
word.capitalize()
if split_word.index(word) != len(split_word) - 1:
word += " "
final_string = ""
return final_string.join(split_word)
@client.event
async def dm_modder(channel, tokenized_message):
if len(tokenized_message) == 2:
await channel.send("No mod ID or feedback supplied!")
return
for id in suggestables:
mods = suggestables.get(id)
if tokenized_message[1] in mods:
modder = await client.fetch_user(id)
await modder.send(
tokenized_message[0].capitalize()
+ " for "
+ tokenized_message[1].capitalize()
+ "\n"
+ tokenized_message[2]
)
await channel.send(f"Feedback sent to developer of {tokenized_message[1]}!")
return
await channel.send(
f"{tokenized_message[1].capitalize()} does not currently accept feedback."
)
@client.event
async def card(channel, tokenized_message):
cards = Mod_Data(tokenized_message[1]).data
random.shuffle(cards)
first_match = {}
other_results = {}
if len(tokenized_message) == 3:
if tokenized_message[2] == "random" and (
channel.id == 384046138610941953 or channel.id == 632350690479570950
):
if "mod" in cards[0]:
await channel.send(
card_format(
random.choice(cards[0]["cards"]), cards[0]["mod"]["name"]
)
)
return
else:
card = random.choice(cards[0]["cards"])
await channel.send(card_format(card, card["mod"]))
return
if len(tokenized_message) == 2:
if tokenized_message[1] == "random" and (
channel.id == 384046138610941953 or channel.id == 632350690479570950
):
mod_object = random.choice(cards)
if len(mod_object["cards"]) == 0:
await card(channel, tokenized_message)
return
cards_object = random.choice(mod_object["cards"])
if "mod" in mod_object:
await channel.send(card_format(cards_object, mod_object["mod"]["name"]))
return
else:
await channel.send(card_format(cards_object, cards_object["mod"]))
return
for x in range(len(cards)):
for card in cards[x]["cards"]:
if len(tokenized_message) == 3:
if tokenized_message[2] == card["name"].lower():
if "mod" in cards[x]:
if not first_match:
first_match.update({cards[x]["mod"]["name"]: card})
else:
if len(other_results) < 3:
other_results.update(
{cards[x]["mod"]["name"]: card["name"]}
)
else:
if not first_match:
first_match.update({card["mod"]: card})
else:
if len(other_results) < 3:
other_results.update({card["mod"]: card["name"]})
else:
if tokenized_message[1] == card["name"].lower():
if "mod" in cards[x]:
if not first_match:
first_match.update({cards[x]["mod"]["name"]: card})
else:
if len(other_results) < 3:
other_results.update(
{cards[x]["mod"]["name"]: card["name"]}
)
else:
if not first_match:
first_match.update({card["mod"]: card})
else:
if len(other_results) < 3:
other_results.update({card["mod"]: card["name"]})
message = ""
if first_match:
for key in first_match:
message += card_format(first_match.get(key), key) + "\n"
if len(other_results) > 3:
other_results = other_results[:2]
if other_results:
message += "Other matches include:\n"
for match in other_results:
name = other_results.get(match)
message += f"`{makeCaps(name)} from {makeCaps(match)}` "
await channel.send(message)
return
if len(tokenized_message) == 3:
await channel.send(
f"No card named {tokenized_message[2]} found in {tokenized_message[1]}."
)
else:
await channel.send(f"No card named {tokenized_message[1]} found.")
@client.event
async def relic(channel, tokenized_message):
relics = Mod_Data(tokenized_message[1]).data
random.shuffle(relics)
first_match = {}
other_results = {}
if "star compass" in tokenized_message:
await channel.send("Oops, I dropped it. Oh well.")
return
if len(tokenized_message) == 3:
if tokenized_message[2] == "random" and (
channel.id == 384046138610941953 or channel.id == 632350690479570950
):
if "mod" in relics[0]:
await channel.send(
relic_format(
random.choice(relics[0]["relics"]), relics[0]["mod"]["name"]
)
)
return
else:
relic = random.choice(relics[0]["relics"])
await channel.send(relic_format(relic, relic["mod"]))
return
if len(tokenized_message) == 2:
if tokenized_message[1] == "random" and (
channel.id == 384046138610941953 or channel.id == 632350690479570950
):
mod_object = random.choice(relics)
if len(mod_object["relics"]) == 0:
await relic(channel, tokenized_message)
return
relics_object = random.choice(mod_object["relics"])
if "mod" in mod_object:
await channel.send(
relic_format(relics_object, mod_object["mod"]["name"])
)
return
else:
await channel.send(relic_format(relics_object, relics_object["mod"]))
return
for x in range(len(relics)):
for relic in relics[x]["relics"]:
if len(tokenized_message) == 3:
if tokenized_message[2] == relic["name"].lower():
if "mod" in relics[x]:
if not first_match:
first_match.update({relics[x]["mod"]["name"]: relic})
else:
if len(other_results) < 3:
other_results.update(
{relics[x]["mod"]["name"]: relic["name"]}
)
else:
if not first_match:
first_match.update({relic["mod"]: relic})
else:
if len(other_results) < 3:
other_results.update({relic["mod"]: relic["name"]})
else:
if tokenized_message[1] == relic["name"].lower():
if "mod" in relics[x]:
if not first_match:
first_match.update({relics[x]["mod"]["name"]: relic})
else:
if len(other_results) < 3:
other_results.update(
{relics[x]["mod"]["name"]: relic["name"]}
)
else:
if not first_match:
first_match.update({relic["mod"]: relic})
else:
if len(other_results) < 3:
other_results.update({relic["mod"]: relic["name"]})
message = ""
if first_match:
for key in first_match:
message += relic_format(first_match.get(key), key) + "\n"
if len(other_results) > 3:
other_results = other_results[:2]
if other_results:
message += "Other matches include:\n"
for match in other_results:
name = other_results.get(match)
message += f"`{makeCaps(name)} from {makeCaps(match)}` "
await channel.send(message)
return
if len(tokenized_message) == 3:
await channel.send(
f"No relic named {tokenized_message[2]} found in {tokenized_message[1]}."
)
else:
await channel.send(f"No relic named {tokenized_message[1]} found.")
@client.event
async def keyword(channel, tokenized_message):
keywords = Mod_Data(tokenized_message[1]).data
for x in range(len(keywords)):
for keyword in keywords[x]["keywords"]:
keyword_name = ""
split_keyword = keyword["name"].split(":")
if len(split_keyword) == 2:
keyword_name = split_keyword[1]
else:
keyword_name = split_keyword[0]
if len(tokenized_message) == 3:
if tokenized_message[2] == keyword_name.lower():
if len(split_keyword) == 2:
await channel.send(
keyword_format_mod(keyword, keyword_name, split_keyword[0])
)
return
else:
await channel.send(keyword_format(keyword, keyword_name))
return
else:
if tokenized_message[1] == keyword_name.lower():
if len(split_keyword) == 2:
await channel.send(
keyword_format_mod(keyword, keyword_name, split_keyword[0])
)
return
else:
await channel.send(keyword_format(keyword, keyword_name))
return
if len(tokenized_message) == 3:
await channel.send(
f"No keyword named {tokenized_message[2]} found in {tokenized_message[1]}."
)
else:
await channel.send(f"No keyword named {tokenized_message[1]} found.")
@client.event
async def help_command(channel):
await channel.send(
f"I can display modded info with {prefix}card, {prefix}relic or {prefix}keyword!"
+ "\n"
+ f"You can use {prefix}help, {prefix}list, {prefix}find or {prefix}contribute to get information!"
+ "\n"
+ f"You can use {prefix}bug, {prefix}feedback or {prefix}suggestion to send information to the developer of certain mods that have opted in."
)
def card_format(card, id):
if card["cost"] == "":
return "**{0}**\n`{1}` `{2}` `{3}` `{4}`\n{5}".format(
card["name"],
card["type"],
card["rarity"],
card["color"],
id,
remove_keyword_prefixes(card["description"]),
)
return "**{0}**\n`{1}` `{2}` `{3}` `{4}` `{5}`\n{6}".format(
card["name"],
energy_string(card["cost"]),
card["type"],
card["rarity"],
card["color"],
id,
remove_keyword_prefixes(card["description"]),
)
def relic_format(relic, id):
if relic["pool"] == "":
return "**{0}**\n`{1}` `{2}`\n{3}\n*{4}*".format(
relic["name"], relic["tier"], id, relic["description"], relic["flavorText"]
)
return "**{0}**\n`{1}` `{2}` `{3}`\n{4}\n*{5}*".format(
relic["name"],
relic["tier"],
relic["pool"],
id,
relic["description"],
relic["flavorText"],
)
def keyword_format_mod(keyword, name, mod):
return "**{0}**\n {1}".format(name.capitalize(), keyword["description"])
def keyword_format(keyword, name):
return "**{0}**\n{1}".format(name.capitalize(), keyword["description"])
def energy_string(cost):
if cost == "X" or "0":
return cost
cost = int(cost)
s = ""
for i in range(0, cost):
s += "[E] "
return s
def remove_keyword_prefixes(description):
description = description.replace("\n", "\n ")
description = description.split(" ")
final_description = ""
for word in description:
res = uncolor.match(word)
if res:
final_description += res.group(1).replace("[]", "", 1) + " "
continue
if word.startswith("!"):
if word.find("!", 1) > 0:
final_description += "#"
if word.find("!", 1) + 1 < len(word):
final_description += word[word.index("!", 1) + 1 :]
final_description += " "
continue
if is_keyword(word):
if word.split(":", 1)[1][len(word.split(":", 1)[1]) - 1] == ".":
final_description += word.split(":", 1)[1].replace("_", " ")
else:
final_description += word.split(":", 1)[1].replace("_", " ") + " "
continue
final_description += word + " "
final_description = final_description.replace("\n ", "\n")
return final_description
def is_keyword(word):
return (
len(word) > 0
and not word[0].isupper()
and ":" in word
and word.find(":") < len(word) - 1
and word[word.find(":") + 1] != "\n"
)
client.run(token)