-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
padinfo.py
1658 lines (1417 loc) · 76.9 KB
/
padinfo.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
import asyncio
import csv
import io
import json
import logging
import os
import random
import re
from collections import defaultdict
from enum import EnumMeta
from io import BytesIO
from typing import Callable, List, Optional, TYPE_CHECKING, Type
import aiohttp
import discord
from discord import Color
from discordmenu.emoji.emoji_cache import emoji_cache
from redbot.core import Config, checks, commands, data_manager
from redbot.core.utils.chat_formatting import bold, box, inline, pagify
from tsutils.cogs.donations import is_donor
from tsutils.cogs.globaladmin import auth_check
from tsutils.emoji import char_to_emoji
from tsutils.enums import Server
from tsutils.json_utils import safe_read_json
from tsutils.menu.components.config import BotConfig
from tsutils.menu.simple_text import SimpleTextMenu
from tsutils.menu.view.closable_embed import ClosableEmbedViewState
from tsutils.menu.view.simple_text import SimpleTextViewState
from tsutils.query_settings import converters
from tsutils.query_settings.enums import AltEvoSort, CardLevelModifier, CardModeModifier, CardPlusModifier, EvoGrouping, \
LsMultiplier, \
MonsterLinkTarget, SkillDisplay
from tsutils.query_settings.query_settings import QuerySettings
from tsutils.tsubaki.custom_emoji import AWAKENING_ID_TO_EMOJI_NAME_MAP, get_attribute_emoji_by_enum, \
get_attribute_emoji_by_monster, get_awakening_emoji, get_type_emoji, get_emoji
from tsutils.tsubaki.monster_header import MonsterHeader
from tsutils.user_interaction import send_cancellation_message, send_confirmation_message
from padinfo.board_generator import BoardGenerator
from padinfo.core.button_info import button_info
from padinfo.core.leader_skills import leaderskill_query
from padinfo.core.padinfo_settings import settings
from padinfo.core.transforminfo import perform_transforminfo_query
from padinfo.menu.awakening_list import AwakeningListMenu, AwakeningListMenuPanes
from padinfo.menu.button_info import ButtonInfoMenu, ButtonInfoMenuPanes
from padinfo.menu.closable_embed import ClosableEmbedMenu
from padinfo.menu.favcard import FavcardMenu
from padinfo.menu.id import IdMenu, IdMenuPanes
from padinfo.menu.leader_skill import LeaderSkillMenu
from padinfo.menu.leader_skill_single import LeaderSkillSingleMenu
from padinfo.menu.menu_map import padinfo_menu_map
from padinfo.menu.monster_list import MonsterListEmoji, MonsterListMenu, MonsterListMenuPanes
from padinfo.menu.na_diff import NaDiffMenu, NaDiffMenuPanes
from padinfo.menu.scroll import ScrollMenuPanes
from padinfo.menu.series_scroll import SeriesScrollEmoji, SeriesScrollMenu, SeriesScrollMenuPanes
from padinfo.menu.transforminfo import TransformInfoMenu, TransformInfoMenuPanes
from padinfo.reaction_list import get_id_menu_initial_reaction_list
from padinfo.view.awakening_help import AwakeningHelpView, AwakeningHelpViewProps
from padinfo.view.awakening_list import AwakeningListSortTypes, AwakeningListViewState
from padinfo.view.button_info import ButtonInfoToggles, ButtonInfoViewState
from padinfo.view.common import invalid_monster_text
from padinfo.view.dungeon_list.dungeon_list import DungeonListViewProps, DungeonListBase
from padinfo.view.dungeon_list.jp_dungeon_name import JpDungeonNameViewProps, JpDungeonNameView
from padinfo.view.dungeon_list.jpytdglead import JpYtDgLeadProps, JpYtDgLeadView
from padinfo.view.dungeon_list.jptwtdglead import JpTwtDgLeadProps, JpTwtDgLeadView
from padinfo.view.dungeon_list.skyo_links import SkyoLinksView, SkyoLinksViewProps
from padinfo.view.evos import EvosViewState
from padinfo.view.experience_curve import ExperienceCurveView, ExperienceCurveViewProps
from padinfo.view.favcard import FavcardViewState
from padinfo.view.id import IdViewState
from padinfo.view.id_traceback import IdTracebackView, IdTracebackViewProps
from padinfo.view.leader_skill import LeaderSkillViewState
from padinfo.view.leader_skill_single import LeaderSkillSingleViewState
from padinfo.view.links import LinksView
from padinfo.view.lookup import LookupView
from padinfo.view.materials import MaterialsViewState
from padinfo.view.monster_list.all_mats import AllMatsViewState
from padinfo.view.monster_list.id_search import IdSearchViewState
from padinfo.view.monster_list.monster_list import MonsterListViewState, MonsterListQueriedProps
from padinfo.view.monster_list.scroll import ScrollViewState
from padinfo.view.monster_list.static_monster_list import StaticMonsterListViewState
from padinfo.view.otherinfo import OtherInfoViewState
from padinfo.view.pantheon import PantheonViewState
from padinfo.view.pic import PicViewState
from padinfo.view.series_scroll import SeriesScrollViewState
from padinfo.view.transforminfo import TransformInfoViewState
if TYPE_CHECKING:
from dbcog.dbcog import DBCog
from dbcog.database_manager import DBCogDatabase
from dbcog.models.monster_model import MonsterModel
from dbcog.models.series_model import SeriesModel
logger = logging.getLogger('red.padbot-cogs.padinfo')
EMBED_NOT_GENERATED = -1
IDGUIDE = "https://github.com/TsubakiBotPad/pad-cogs/wiki/id-user-guide"
DUNGEON_ALIASES = "https://docs.google.com/spreadsheets/d/e/" \
"2PACX-1vQ3F4shS6w2na4FXA-vZyyhKcOQ0zRA1B3T7zaX0Bm4cEjW-1IVw91josPtLgc9Zh_TGh8GTD6zFmd0" \
"/pub?gid=0&single=true&output=csv"
HISTORY_DURATION = 11
def _data_file(file_name: str) -> str:
return os.path.join(str(data_manager.cog_data_path(raw_name='padinfo')), file_name)
class PadInfo(commands.Cog):
"""Info for PAD Cards"""
menu_map = padinfo_menu_map
def __init__(self, bot, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bot = bot
# These emojis are the keys into the idmenu submenus
self.ls_emoji = '\N{HOUSE BUILDING}'
self.left_emoji = char_to_emoji('l')
self.right_emoji = char_to_emoji('r')
self.remove_emoji = '\N{CROSS MARK}'
self.config = Config.get_conf(self, identifier=9401770)
self.config.register_user(color=None, beta_id3=False, id_history=[])
self.config.register_global(sometimes_perc=20, good=0, bad=0, bad_queries=[])
self.historic_lookups_file_path = _data_file('historic_lookups_id3.json')
self.historic_lookups = safe_read_json(self.historic_lookups_file_path)
self.awoken_emoji_names = {v: k for k, v in AWAKENING_ID_TO_EMOJI_NAME_MAP.items()}
self.get_attribute_emoji_by_monster = get_attribute_emoji_by_monster
self.settings = settings
self.aliases = defaultdict(set)
self.aliases_loaded = asyncio.Event()
async def load_aliases(self):
self.aliases_loaded.clear()
self.aliases = defaultdict(set)
async with aiohttp.ClientSession() as session:
async with session.get(DUNGEON_ALIASES) as response:
reader = csv.reader(io.StringIO(await response.text()), delimiter=',')
next(reader)
for line in reader:
for a in line[2].replace(' ', '').split(','):
self.aliases[a].add(line[0] or line[1])
self.aliases_loaded.set()
async def red_get_data_for_user(self, *, user_id):
"""Get a user's personal data."""
idhist = await self.config.user_from_id(user_id).id_history()
if idhist:
data = f"You have {len(idhist)} past queries stored. Use" \
f" {(await self.bot.get_valid_prefixes())[0]}idhistory to see what they are.\n"
else:
data = f"No data is stored for user with ID {user_id}."
return {"user_data.txt": BytesIO(data.encode())}
async def red_delete_data_for_user(self, *, requester, user_id):
"""Delete a user's personal data.
No personal data is stored in this cog.
"""
await self.config.user_from_id(user_id).clear()
async def register_menu(self):
await self.bot.wait_until_ready()
menulistener = self.bot.get_cog("MenuListener")
if menulistener is None:
logger.warning("MenuListener is not loaded.")
return
await menulistener.register(self)
async def reload_nicknames(self):
await self.bot.wait_until_ready()
while self == self.bot.get_cog('PadInfo'):
wait_time = 60 * 60 * 1
try:
emoji_cache.set_guild_ids([g.id for g in self.bot.guilds])
emoji_cache.refresh_from_discord_bot(self.bot)
except Exception as ex:
wait_time = 5
logger.exception("reload padinfo loop caught exception " + str(ex))
await asyncio.sleep(wait_time)
async def get_dbcog(self) -> "DBCog":
dbcog = self.bot.get_cog("DBCog")
if dbcog is None:
raise ValueError("DBCog cog is not loaded")
await dbcog.wait_until_ready()
return dbcog
def save_historic_data(self, query, monster: Optional["MonsterModel"]):
self.historic_lookups[query] = monster.monster_id if monster else -1
json.dump(self.historic_lookups, open(self.historic_lookups_file_path, "w+"))
async def get_menu_default_data(self, ims):
data = {
'dbcog': await self.get_dbcog(),
'user_config': await BotConfig.get_user(self.config, ims['original_author_id'])
}
return data
@commands.command()
async def jpname(self, ctx, *, query: str):
"""Show the Japanese name of a monster"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if monster is not None:
await ctx.send(MonsterHeader.text_with_emoji(monster))
await ctx.send(box(monster.name_ja))
else:
await self.send_id_failure_message(ctx, query)
@commands.command(name="id", aliases=['I\'d', 'ID'])
@checks.bot_has_permissions(embed_links=True)
async def _id(self, ctx, *, query: str):
"""Monster info (main tab)"""
await self._do_id(ctx, query)
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def idna(self, ctx, *, query: str):
"""Monster info (limited to NA monsters ONLY)"""
await self._do_id(ctx, "--na " + query)
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def idjp(self, ctx, *, query: str):
"""Monster info (limited to JP monsters ONLY)"""
await self._do_id(ctx, "injp " + query)
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def id3(self, ctx, *, query: str):
"""Monster info (main tab)"""
await self._do_id(ctx, query)
async def _get_monster(self, ctx, query) -> Optional["MonsterModel"]:
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
return monster
async def _do_id(self, ctx, query: str):
dbcog = await self.get_dbcog()
original_author_id = ctx.message.author.id
raw_query = query
if (monster := await self._get_monster(ctx, query)) is None:
self.save_historic_data(query, monster)
return
# id3 messaging stuff
if monster and monster.on_na and monster.on_jp and monster.monster_no_na != monster.monster_no_jp:
await ctx.send(f"The NA ID and JP ID of this card differ! The JP ID is {monster.monster_id}, so "
f"you can query with {ctx.prefix}id jp{monster.monster_id}." +
(" Make sure you use the **JP id number** when updating the Google doc!!!!!" if
ctx.author.id in self.bot.get_cog("PadGlobal").settings.bot_settings['admins'] else ""))
alt_monsters = IdViewState.get_alt_monsters_and_evos(dbcog, monster)
id_queried_props = await IdViewState.do_query(dbcog, monster)
full_reaction_list = IdMenuPanes.emoji_names()
initial_reaction_list = await get_id_menu_initial_reaction_list(ctx, dbcog, monster, full_reaction_list)
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(monster)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
state = IdViewState(original_author_id, IdMenu.MENU_TYPE, raw_query, query, qs, monster,
alt_monsters, is_jp_buffed, id_queried_props,
reaction_list=initial_reaction_list)
menu = IdMenu.menu()
await menu.create(ctx, state)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
@staticmethod
async def send_invalid_monster_message(ctx, query: str, monster: "MonsterModel", append_text: str):
await ctx.send(invalid_monster_text(query, monster, append_text))
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def nadiff(self, ctx, *, query: str):
"""Show differences between NA & JP versions of a card"""
dbcog = await self.get_dbcog()
raw_query = query
original_author_id = ctx.message.author.id
monster = await dbcog.find_monster(raw_query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
self.save_historic_data(query, monster)
return
alt_monsters = IdViewState.get_alt_monsters_and_evos(dbcog, monster)
id_queried_props = await IdViewState.do_query(dbcog, monster)
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(monster)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
state = IdViewState(original_author_id, NaDiffMenu.MENU_TYPE, raw_query, query, qs, monster,
alt_monsters, is_jp_buffed, id_queried_props)
menu = NaDiffMenu.menu()
message = state.get_na_diff_invalid_message()
if message:
state = SimpleTextViewState(original_author_id, NaDiffMenu.MENU_TYPE,
raw_query, qs, message)
menu = NaDiffMenu.menu(initial_control=NaDiffMenu.message_control)
await menu.create(ctx, state)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
@commands.command(name="evos")
@checks.bot_has_permissions(embed_links=True)
async def evos(self, ctx, *, query: str):
"""Monster info (evolutions tab)"""
dbcog = await self.get_dbcog()
raw_query = query
original_author_id = ctx.message.author.id
monster = await dbcog.find_monster(raw_query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
self.save_historic_data(query, monster)
return
alt_monsters = EvosViewState.get_alt_monsters_and_evos(dbcog, monster)
alt_versions, gem_versions = await EvosViewState.do_query(dbcog, monster)
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(monster)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
if alt_versions is None:
await self.send_invalid_monster_message(ctx, query, monster, ', which has no alt evos or gems')
return
full_reaction_list = IdMenuPanes.emoji_names()
initial_reaction_list = await get_id_menu_initial_reaction_list(ctx, dbcog, monster, full_reaction_list)
state = EvosViewState(original_author_id, IdMenu.MENU_TYPE, raw_query, query, qs, monster,
alt_monsters, is_jp_buffed,
alt_versions, gem_versions,
reaction_list=initial_reaction_list
)
menu = IdMenu.menu(initial_control=IdMenu.evos_control)
await menu.create(ctx, state)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
@commands.command(name="mats", aliases=['evomats', 'evomat', 'skillups'])
@checks.bot_has_permissions(embed_links=True)
async def evomats(self, ctx, *, query: str):
"""Monster info (evo materials tab)"""
dbcog = await self.get_dbcog()
raw_query = query
original_author_id = ctx.message.author.id
monster = await dbcog.find_monster(raw_query, ctx.author.id)
if not monster:
await self.send_id_failure_message(ctx, query)
self.save_historic_data(query, monster)
return
mats, usedin, gemid, gemusedin, skillups, skillup_evo_count, link, gem_override = \
await MaterialsViewState.do_query(dbcog, monster)
if mats is None:
await ctx.send("This monster has no mats or skillups and isn't used in any evolutions.")
return
alt_monsters = MaterialsViewState.get_alt_monsters_and_evos(dbcog, monster)
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(monster)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
full_reaction_list = IdMenuPanes.emoji_names()
initial_reaction_list = await get_id_menu_initial_reaction_list(ctx, dbcog, monster, full_reaction_list)
state = MaterialsViewState(original_author_id, IdMenu.MENU_TYPE, raw_query, query, qs, monster,
alt_monsters, is_jp_buffed,
mats, usedin, gemid, gemusedin, skillups, skillup_evo_count, link, gem_override,
reaction_list=initial_reaction_list
)
menu = IdMenu.menu(initial_control=IdMenu.mats_control)
await menu.create(ctx, state)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
@commands.command(aliases=["series", "panth"])
@checks.bot_has_permissions(embed_links=True)
async def pantheon(self, ctx, *, query: str):
"""Monster info (pantheon tab)"""
dbcog = await self.get_dbcog()
raw_query = query
original_author_id = ctx.message.author.id
monster = await dbcog.find_monster(raw_query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
self.save_historic_data(query, monster)
return
pantheon_list, series_name, base_monster = await PantheonViewState.do_query(dbcog, monster)
if pantheon_list is None:
await ctx.send('Unable to find a pantheon for the result of your query,'
+ ' [{}] {}.'.format(monster.monster_id, monster.name_en))
return
alt_monsters = PantheonViewState.get_alt_monsters_and_evos(dbcog, monster)
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(monster)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
full_reaction_list = IdMenuPanes.emoji_names()
initial_reaction_list = await get_id_menu_initial_reaction_list(ctx, dbcog, monster, full_reaction_list)
state = PantheonViewState(original_author_id, IdMenu.MENU_TYPE, raw_query, query, qs, monster,
alt_monsters, is_jp_buffed,
pantheon_list, series_name, base_monster,
reaction_list=initial_reaction_list
)
menu = IdMenu.menu(initial_control=IdMenu.pantheon_control)
await menu.create(ctx, state)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
@commands.command(aliases=['img'])
@checks.bot_has_permissions(embed_links=True)
async def pic(self, ctx, *, query: str):
"""Monster info (full image tab)"""
dbcog = await self.get_dbcog()
raw_query = query
original_author_id = ctx.message.author.id
monster = await dbcog.find_monster(raw_query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
self.save_historic_data(query, monster)
return
alt_monsters = PicViewState.get_alt_monsters_and_evos(dbcog, monster)
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(monster)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
full_reaction_list = IdMenuPanes.emoji_names()
initial_reaction_list = await get_id_menu_initial_reaction_list(ctx, dbcog, monster, full_reaction_list)
state = PicViewState(original_author_id, IdMenu.MENU_TYPE, raw_query, query, qs, monster,
alt_monsters, is_jp_buffed,
reaction_list=initial_reaction_list
)
menu = IdMenu.menu(initial_control=IdMenu.pic_control)
await menu.create(ctx, state)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
@commands.command(aliases=['stats'])
@checks.bot_has_permissions(embed_links=True)
async def otherinfo(self, ctx, *, query: str):
"""Monster info (misc info tab)"""
dbcog = await self.get_dbcog()
raw_query = query
original_author_id = ctx.message.author.id
monster = await dbcog.find_monster(raw_query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
self.save_historic_data(query, monster)
return
alt_monsters = PicViewState.get_alt_monsters_and_evos(dbcog, monster)
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(monster)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
full_reaction_list = IdMenuPanes.emoji_names()
initial_reaction_list = await get_id_menu_initial_reaction_list(ctx, dbcog, monster, full_reaction_list)
state = OtherInfoViewState(original_author_id, IdMenu.MENU_TYPE, raw_query, query, qs, monster,
alt_monsters, is_jp_buffed,
reaction_list=initial_reaction_list
)
menu = IdMenu.menu(initial_control=IdMenu.otherinfo_control)
await menu.create(ctx, state)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def links(self, ctx, *, query: str):
"""Monster links"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
self.save_historic_data(query, monster)
return
await self.log_id_result(ctx, monster.monster_id)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
embed = LinksView.embed(monster, qs).to_embed()
await ctx.send(embed=embed)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
@commands.command(aliases=['lu'])
@checks.bot_has_permissions(embed_links=True)
async def lookup(self, ctx, *, query: str):
"""Short info results for a monster query"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
self.save_historic_data(query, monster)
return
await self.log_id_result(ctx, monster.monster_id)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
embed = LookupView.embed(monster, qs).to_embed()
await ctx.send(embed=embed)
await self.log_id_result(ctx, monster.monster_id)
self.save_historic_data(query, monster)
async def log_id_result(self, ctx, monster_id: int):
history = await self.config.user(ctx.author).id_history()
if monster_id in history:
history.remove(monster_id)
history.insert(0, monster_id)
if len(history) > HISTORY_DURATION:
history.pop()
await self.config.user(ctx.author).id_history.set(history)
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def buttoninfo(self, ctx, *, query: str):
"""Button farming theorycrafting info"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
return
original_author_id = ctx.message.author.id
info = button_info.get_info(dbcog, monster)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
display_options = ButtonInfoToggles()
alt_monsters = ButtonInfoViewState.get_alt_monsters_and_evos(dbcog, monster)
state = ButtonInfoViewState(original_author_id, ButtonInfoMenu.MENU_TYPE, query, qs,
display_options,
monster, alt_monsters, info,
reaction_list=ButtonInfoMenuPanes.get_user_reaction_list(display_options))
menu = ButtonInfoMenu.menu()
await menu.create(ctx, state)
@commands.command(aliases=["ids"])
@checks.bot_has_permissions(embed_links=True)
async def idsearch(self, ctx, *, query):
"""Usually called `[p]ids`. Receive several `[p]id` results at once, using a two menu sydtem.
Example queries:
- `[p]ids marvel 7*b rem` to get all 7* base rarity rem Marvel cards
- `[p]ids orbskin`to get all orb skins
- `[p]ids rb` to get all red-blue cards
"""
await self._do_idsearch(ctx, query)
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def nadiffs(self, ctx, *, query):
"""See the differences between several NA & JP cards at once.
Example usage: `[p]nadiffs Heroine` or `[p]nadiffs orbskin`
"""
await self._do_idsearch(ctx, query, child_menu_type=NaDiffMenu.MENU_TYPE,
child_reaction_list=NaDiffMenuPanes.emoji_names())
async def _do_idsearch(self, ctx, query, child_menu_type=None,
child_reaction_list=None):
dbcog = await self.get_dbcog()
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
queried_props = await IdSearchViewState.do_query(dbcog, query, ctx.author.id, qs)
if not queried_props or not queried_props.monster_list:
await ctx.send("No monster matched.")
return
await self._do_monster_list(ctx, dbcog, query, queried_props, 'ID Search Results',
IdSearchViewState,
child_menu_type=child_menu_type,
child_reaction_list=child_reaction_list)
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def allmats(self, ctx, *, query: str):
"""Monster info (evo materials tab)"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if not monster:
await self.send_id_failure_message(ctx, query)
return
monster_list = await AllMatsViewState.do_query(dbcog, monster)
if not monster_list:
await ctx.send("This monster is not a mat for anything nor does it have a gem.")
return
_, usedin, _, gemusedin, _, _, _, _ = await MaterialsViewState.do_query(dbcog, monster)
title = 'Material For' if usedin else 'Gem is Material For'
await self._do_monster_list(ctx, dbcog, query, MonsterListQueriedProps(monster_list), title, AllMatsViewState)
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def evolist(self, ctx, *, query):
"""See all evos of a card, using a two-menu system.
Example usage: `[p]evolist Jiraiya`
"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
return
monster_list, _ = await EvosViewState.do_query(dbcog, monster)
if monster_list is None:
await self.send_invalid_monster_message(ctx, query, monster, ', which has no alt evos')
return
await self._do_monster_list(ctx, dbcog, query, MonsterListQueriedProps(monster_list),
'Evolution List', StaticMonsterListViewState)
async def _do_monster_list(self, ctx, dbcog, query, queried_props: MonsterListQueriedProps,
title, view_state_type: Type[MonsterListViewState],
child_menu_type: Optional[str] = None,
child_reaction_list: Optional[List] = None
):
raw_query = query
original_author_id = ctx.message.author.id
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
initial_reaction_list = MonsterListMenuPanes.get_initial_reaction_list(len(queried_props.monster_list))
instruction_message = 'Click a reaction to see monster details!'
if child_menu_type is None:
child_menu_type = qs.child_menu_type.name
_, child_panes_class = padinfo_menu_map[child_menu_type]
child_reaction_list = child_panes_class.emoji_names()
state = view_state_type(original_author_id, view_state_type.VIEW_STATE_TYPE, query,
qs, queried_props,
title, instruction_message,
child_menu_type=child_menu_type,
child_reaction_list=child_reaction_list,
reaction_list=initial_reaction_list
)
parent_menu = MonsterListMenu.menu()
message = await ctx.send('Setting up!')
ims = state.serialize()
user_config = await BotConfig.get_user(self.config, ctx.author.id)
data = {
'dbcog': dbcog,
'user_config': user_config,
}
child_state = SimpleTextViewState(original_author_id, view_state_type.VIEW_STATE_TYPE,
raw_query, qs,
instruction_message,
reaction_list=[]
)
child_menu = SimpleTextMenu.menu()
child_message = await child_menu.create(ctx, child_state)
data['child_message_id'] = child_message.id
try:
await parent_menu.transition(message, ims, MonsterListEmoji.refresh, ctx.author, **data)
await message.edit(content=None)
except discord.errors.NotFound:
# The user could delete the menu before we can do this
pass
@commands.command()
@checks.bot_has_permissions(embed_links=True)
async def scroll(self, ctx, *, query: str):
"""Scroll numerically through PAD cards, using a two-menu system.
Example usage: `[p]scroll Tsubaki`
"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if not monster:
await self.send_id_failure_message(ctx, query)
return
queried_props = await ScrollViewState.do_query(dbcog, monster)
title = 'Monster Book Scroll'
raw_query = query
original_author_id = ctx.message.author.id
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
initial_reaction_list = ScrollMenuPanes.get_initial_reaction_list(len(queried_props.monster_list))
instruction_message = 'Click a reaction to see monster details!'
state = ScrollViewState(original_author_id, ScrollViewState.VIEW_STATE_TYPE, query, qs,
queried_props,
title, instruction_message, monster.monster_id,
child_menu_type=IdMenu.MENU_TYPE,
child_reaction_list=IdMenuPanes.emoji_names(),
reaction_list=initial_reaction_list
)
parent_menu = MonsterListMenu.menu()
message = await ctx.send('Setting up!')
ims = state.serialize()
user_config = await BotConfig.get_user(self.config, ctx.author.id)
data = {
'dbcog': dbcog,
'user_config': user_config,
}
alt_monsters = IdViewState.get_alt_monsters_and_evos(dbcog, monster)
id_queried_props = await IdViewState.do_query(dbcog, monster)
full_reaction_list = IdMenuPanes.emoji_names()
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(monster)
child_state = IdViewState(original_author_id, IdMenu.MENU_TYPE, raw_query, query, qs, monster,
alt_monsters, is_jp_buffed, id_queried_props,
reaction_list=full_reaction_list)
child_menu = IdMenu.menu()
child_message = await child_menu.create(ctx, child_state)
data['child_message_id'] = child_message.id
try:
await parent_menu.transition(message, ims, MonsterListEmoji.refresh, ctx.author, **data)
await message.edit(content=None)
except discord.errors.NotFound:
# The user could delete the menu before we can do this
pass
@commands.command(aliases=['collabscroll', 'ss'])
@checks.bot_has_permissions(embed_links=True)
async def seriesscroll(self, ctx, *, query):
"""Scroll through a collab, grouped by rarity. Defaults to rarity 6.
Example usage: `[p]seriesscroll Marvel`
"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if monster is None:
await self.send_id_failure_message(ctx, query)
return
series_id = monster.series_id
series_object: "SeriesModel" = monster.series
title = series_object.name_en
paginated_monsters = None
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
rarity = None
for rarity in SeriesScrollMenu.RARITY_INITIAL_TRY_ORDER:
paginated_monsters = await SeriesScrollViewState.do_query(dbcog, monster.series_id,
rarity, monster.server_priority)
if paginated_monsters:
break
all_rarities = SeriesScrollViewState.query_all_rarities(dbcog, series_id, monster.server_priority)
raw_query = query
original_author_id = ctx.message.author.id
initial_reaction_list = SeriesScrollMenuPanes.get_initial_reaction_list(len(paginated_monsters))
instruction_message = 'Click a reaction to see monster details!'
state = SeriesScrollViewState(original_author_id, SeriesScrollMenu.MENU_TYPE, raw_query, query,
qs, series_id, paginated_monsters, 0, int(rarity),
all_rarities,
title, instruction_message,
reaction_list=initial_reaction_list)
parent_menu = SeriesScrollMenu.menu()
message = await ctx.send('Setting up!')
ims = state.serialize()
user_config = await BotConfig.get_user(self.config, ctx.author.id)
data = {
'dbcog': dbcog,
'user_config': user_config,
}
child_state = SimpleTextViewState(original_author_id, SeriesScrollMenu.MENU_TYPE,
raw_query, qs,
instruction_message,
reaction_list=[]
)
child_menu = SimpleTextMenu.menu()
child_message = await child_menu.create(ctx, child_state)
data['child_message_id'] = child_message.id
try:
await parent_menu.transition(message, ims, SeriesScrollEmoji.refresh, ctx.author, **data)
await message.edit(content=None)
except discord.errors.NotFound:
# The user could delete the menu before we can do this
pass
@commands.command(aliases=['leaders', 'leaderskills', 'ls'], usage="<card_1> [card_2]")
@checks.bot_has_permissions(embed_links=True)
async def leaderskill(self, ctx, *, raw_query):
"""Display the multiplier and leaderskills for two monsters
Gets two monsters separated by a slash, wrapping quotes, a comma,
or spaces (if there's only two words).
[p]ls r sonia/ revo lu bu
[p]ls r sonia "revo lu bu"
[p]ls sonia lubu
"""
dbcog = await self.get_dbcog()
l_mon, l_query, r_mon, r_query = await leaderskill_query(dbcog, raw_query, ctx.author.id)
err_msg = ('{} query failed to match a monster: `{}`. If your query is multiple words,'
' try separating the queries with / or wrap with quotes.')
if l_mon is None:
await ctx.send(err_msg.format('Left', l_query))
return
if r_mon is None:
await ctx.send(err_msg.format('Right', r_query))
return
lqs = await QuerySettings.extract_raw(ctx.author, self.bot, l_query)
rqs = await QuerySettings.extract_raw(ctx.author, self.bot, r_query or l_query)
original_author_id = ctx.message.author.id
state = LeaderSkillViewState(original_author_id, LeaderSkillMenu.MENU_TYPE, raw_query, raw_query,
lqs,
l_mon, r_mon,
l_query, r_query, lqs, rqs)
menu = LeaderSkillMenu.menu()
await menu.create(ctx, state)
async def get_user_embed_color(self, ctx):
color = await self.config.user(ctx.author).color()
return self.user_color_to_discord_color(color)
@staticmethod
def user_color_to_discord_color(color):
if color is None:
return Color.default()
elif color == "random":
return Color(random.randint(0x000000, 0xffffff))
else:
return discord.Color(color)
async def get_user_friends(self, original_author_id):
friend_cog = self.bot.get_cog("Friend")
return (await friend_cog.get_friends(original_author_id)) if friend_cog else []
@commands.command(aliases=['lssingle'])
@checks.bot_has_permissions(embed_links=True)
async def leaderskillsingle(self, ctx, *, query):
"""See the 1x of a leaderskill, without implying a mirror pair
Example usage: `[p]lssingle Nautilus`
"""
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if not monster:
await self.send_id_failure_message(ctx, query)
return
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
original_author_id = ctx.message.author.id
state = LeaderSkillSingleViewState(original_author_id, LeaderSkillSingleMenu.MENU_TYPE, query, qs,
monster)
menu = LeaderSkillSingleMenu.menu()
await menu.create(ctx, state)
@commands.command(aliases=['tfinfo', 'xforminfo'])
@checks.bot_has_permissions(embed_links=True)
async def transforminfo(self, ctx, *, query):
"""Show info about a transform card, including some helpful details about the base card."""
dbcog = await self.get_dbcog()
raw_query = query
base_mon, transformed_mon, monster_ids = await perform_transforminfo_query(dbcog, query, ctx.author.id)
if not base_mon:
await self.send_id_failure_message(ctx, query)
return
if not transformed_mon:
await self.send_invalid_monster_message(ctx, query, base_mon, ', which has no evos that transform')
return
original_author_id = ctx.message.author.id
tfinfo_queried_props = await TransformInfoViewState.do_query(dbcog, transformed_mon)
reaction_list = TransformInfoMenuPanes.get_user_reaction_list(len(monster_ids))
is_jp_buffed = dbcog.database.graph.monster_is_discrepant(base_mon)
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query)
state = TransformInfoViewState(original_author_id, TransformInfoMenu.MENU_TYPE, raw_query, query, qs,
transformed_mon, base_mon, tfinfo_queried_props, monster_ids,
is_jp_buffed,
reaction_list=reaction_list)
menu = TransformInfoMenu.menu()
await menu.create(ctx, state)
@commands.command(aliases=['awakehelp', 'awakeningshelp', 'awohelp', 'awokenhelp', 'awakeninghelp'])
@checks.bot_has_permissions(embed_links=True)
async def awakenings(self, ctx, *, query=None):
"""Describe a monster's regular and super awakenings in detail.
Leave <query> blank to see a list of every awakening in the game."""
dbcog = await self.get_dbcog()
qs = await QuerySettings.extract_raw(ctx.author, self.bot, query or '')
# TODO: Fix this absolutely awful way of finding if the query is empty but has a QS
if not query or query.startswith('--'):
sort_type = AwakeningListSortTypes.numerical
paginated_skills = await AwakeningListViewState.do_query(dbcog, sort_type)
menu = AwakeningListMenu.menu()
state = AwakeningListViewState(ctx.message.author.id, AwakeningListMenu.MENU_TYPE, qs,
sort_type, paginated_skills, 0, dbcog.AWOKEN_SKILL_TOKEN_MAP,
reaction_list=AwakeningListMenuPanes.get_user_reaction_list(sort_type))
await menu.create(ctx, state)
return
monster = await dbcog.find_monster(query, ctx.author.id)
if not monster:
await self.send_id_failure_message(ctx, query)
return
original_author_id = ctx.message.author.id
menu = ClosableEmbedMenu.menu()
props = AwakeningHelpViewProps(monster=monster, token_map=dbcog.AWOKEN_SKILL_TOKEN_MAP)
state = ClosableEmbedViewState(original_author_id, ClosableEmbedMenu.MENU_TYPE, query,
qs, AwakeningHelpView.VIEW_TYPE, props)
await menu.create(ctx, state)
@commands.command(aliases=['idhist'])
@checks.bot_has_permissions(embed_links=True)
async def idhistory(self, ctx):
"""Show a list of the 11 most recent monsters that the user looked up."""
dbcog = await self.get_dbcog()
history = await self.config.user(ctx.author).id_history()
monster_list = [dbcog.get_monster(m) for m in history]
if not monster_list:
await ctx.send('Did not find any recent queries in history.')
return
queried_props = MonsterListQueriedProps(monster_list)
await self._do_monster_list(ctx, dbcog, '', queried_props, 'Result History', StaticMonsterListViewState)
@commands.command()
async def padsay(self, ctx, server, *, query: str = None):
"""Speak the voice line of a monster into your current chat"""
voice = ctx.author.voice
if not voice:
await send_cancellation_message(ctx, 'You must be in a voice channel to use this command.')
return
channel = voice.channel
speech_cog = self.bot.get_cog('Speech')
if not speech_cog:
await send_cancellation_message(ctx, 'Speech seems to be offline')
return
if server.lower() not in ['na', 'jp']:
query = server + ' ' + (query or '')
server = 'na'
query = query.strip().lower()
dbcog = await self.get_dbcog()
monster = await dbcog.find_monster(query, ctx.author.id)
if monster is not None:
voice_id = monster.voice_id_jp if server == 'jp' else monster.voice_id_na
if voice_id is None:
await ctx.send("No voice file found for " + monster.name_en)
return
base_dir = settings.voiceDir()
voice_file = os.path.join(base_dir, server, '{0:03d}.wav'.format(voice_id))
header = '{} ({})'.format(MonsterHeader.text_with_emoji(monster), server)
if not os.path.exists(voice_file):
await ctx.send('Could not find voice for ' + header)
return
await ctx.send('Speaking for ' + header)
await speech_cog.play_path(channel, voice_file)
else:
await self.send_id_failure_message(ctx, query)
@commands.group(aliases=['idmode'])
async def idset(self, ctx):
"""`[p]id` settings configuration"""
@idset.command(name="list", aliases=['show'])
async def idset_list(self, ctx):
"""`[p]id` settings list"""
fm_flags = await self.bot.get_cog("DBCog").config.user(ctx.author).fm_flags()
intro = f"Here are your current `{ctx.prefix}id` preference settings:\n"
user_settings = {
"cardlevel": '110' if 'cardlevel' not in fm_flags else CardLevelModifier(fm_flags['cardlevel']).name[2:],
"cardmode": 'Solo' if 'cardmode' not in fm_flags else CardModeModifier(fm_flags['cardmode']).name.title(),
"cardplus": '297' if 'cardplus' not in fm_flags else CardPlusModifier(fm_flags['cardplus']).name[4:],
"evogrouping": 'Grouped' if 'evogrouping' not in fm_flags or fm_flags['evogrouping'] == 1 else 'Split',
"evosort": 'Numerical' if 'evosort' not in fm_flags else AltEvoSort(fm_flags['evosort']).name.title(),
"linktarget": 'PADIndex' if 'linktarget' not in fm_flags or fm_flags[
'linktarget'] == 0 else MonsterLinkTarget(fm_flags['linktarget']).name.title(),
"lsmultiplier": 'Double' if 'lsmultiplier' not in fm_flags else LsMultiplier(fm_flags['lsmultiplier']).name[
2:].title(),
"naprio": 'On' if 'na_prio' not in fm_flags or fm_flags['na_prio'] == 1 else 'Off',
"ormod prio": 'On' if 'ormod_prio' not in fm_flags or fm_flags['ormod_prio'] is True else 'Off',