-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
1003 lines (884 loc) · 34.5 KB
/
database.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 json
import os
import re
import aiosqlite # python -m pip install aiosqlite
class Database:
@staticmethod
async def create_heroes() -> None:
query = """
CREATE TABLE IF NOT EXISTS Heroes (
HeroID INTEGER,
Name TEXT,
Role TEXT,
Acronym TEXT,
EmoteID INTEGER,
PRIMARY KEY (HeroID)
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Heroes table created.")
@staticmethod
async def create_maps() -> None:
query = """
CREATE TABLE IF NOT EXISTS Maps (
MapID INTEGER,
Name TEXT,
QuickMatch INTEGER,
StormLeague INTEGER,
PRIMARY KEY (MapID)
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Maps table created.")
@staticmethod
async def create_drafts() -> None:
query = """
CREATE TABLE IF NOT EXISTS Drafts (
ChannelID INTEGER,
MessageID INTEGER,
Image BLOB,
Layout TEXT,
Map TEXT,
Time INTEGER,
PRIMARY KEY (ChannelID)
)"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Drafts table created.")
@staticmethod
async def create_teams() -> None:
query = """
CREATE TABLE IF NOT EXISTS Teams (
TeamID INTEGER,
UserID INTEGER,
ChannelID INTEGER,
PRIMARY KEY (TeamID),
FOREIGN KEY (ChannelID)
REFERENCES Drafts (ChannelID)
ON DELETE CASCADE
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Teams table created.")
@staticmethod
async def create_selections() -> None:
query = """
CREATE TABLE IF NOT EXISTS Selections (
SelectionID INTEGER,
ChannelID INTEGER,
HeroID INTEGER,
PRIMARY KEY (SelectionID),
FOREIGN KEY (ChannelID)
REFERENCES Drafts (ChannelID)
ON DELETE CASCADE,
FOREIGN KEY (HeroID)
REFERENCES Heroes (HeroID)
ON DELETE CASCADE
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Selections table created.")
@staticmethod
async def create_tooltips() -> None:
query = """
CREATE TABLE IF NOT EXISTS Tooltips (
TooltipID TEXT,
Title TEXT,
Cooldown FLOAT,
Cost INTEGER,
Description TEXT,
Hotkey TEXT,
Icon TEXT,
Level INTEGER,
Resource TEXT,
Slot TEXT,
Unit TEXT,
HeroID INTEGER,
PRIMARY KEY (TooltipID),
FOREIGN KEY (HeroID)
REFERENCES Heroes (HeroID)
ON DELETE CASCADE
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Tooltips table created.")
@staticmethod
async def create_keywords() -> None:
query = """
CREATE TABLE IF NOT EXISTS Keywords (
KeywordID INTEGER,
Name TEXT,
TooltipID INTEGER,
PRIMARY KEY (KeywordID),
FOREIGN KEY (TooltipID)
REFERENCES Tooltips (TooltipID)
ON DELETE CASCADE
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Keywords table created.")
@staticmethod
async def create_matchups() -> None:
query = """
CREATE TABLE IF NOT EXISTS Matchups (
MatchupID INTEGER,
UserID TEXT,
YourHeroID TEXT,
EnemyHeroID TEXT,
WinChance INTEGER,
Time INTEGER,
Notes TEXT,
PRIMARY KEY (MatchupID),
FOREIGN KEY (YourHeroID)
REFERENCES Heroes (HeroID)
ON DELETE CASCADE,
FOREIGN KEY (EnemyHeroID)
REFERENCES Heroes (HeroID)
ON DELETE CASCADE,
FOREIGN KEY (UserID)
REFERENCES Users (UserID)
ON DELETE CASCADE
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Matchups table created.")
@staticmethod
async def create_matchup_tips() -> None:
query = """
CREATE TABLE IF NOT EXISTS MatchupTips (
MatchupTipID INTEGER,
Text TEXT,
MatchupID INTEGER,
PRIMARY KEY (MatchupTipID),
FOREIGN KEY (MatchupID)
REFERENCES Matchups (MatchupID)
ON DELETE CASCADE
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Matchup Tips table created.")
@staticmethod
async def create_matchup_contributors() -> None:
query = """
CREATE TABLE IF NOT EXISTS Users (
UserID INTEGER,
Permission INTEGER,
PRIMARY KEY (UserID)
)
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
print("Matchup Contributors table created.")
@staticmethod
async def insert_heroes() -> None:
query = """
SELECT COUNT(*)
FROM Heroes
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
results = await cursor.fetchone()
assert results is not None
rows = results[0]
if rows > 0:
print("Heroes data present.")
else:
for file in os.listdir("./data/heroes/"):
if file.endswith(".json"):
with open(
f"./data/heroes/{file}",
"r",
encoding="utf-8",
) as file:
data: dict = json.load(file)
assert isinstance(data, dict)
id = data.get("id")
name = data.get("name")
role = data.get("expandedRole")
with open(
"./data/misc/acronyms.json",
"r",
encoding="utf-8",
) as file:
data = json.load(file)
acronym = data.get(name)
with open(
"./data/misc/emotes.json",
"r",
encoding="utf-8",
) as file:
data = json.load(file)
emote_id = data.get(name)
query = """
INSERT INTO Heroes (
HeroID,
Name,
Role,
Acronym,
EmoteID
)
VALUES (?, ?, ?, ?, ?)
"""
values = (id, name, role, acronym, emote_id)
async with database_connection.cursor() as cursor:
await cursor.execute(query, values)
await database_connection.commit()
print("Heroes data added.")
@staticmethod
def fix_description(
description: str,
hero: str,
title: str,
) -> str:
# To customize tooltips.
with open(
f"./data/misc/corrections.json",
"r",
encoding="utf-8",
) as file:
data = json.load(file)
try:
corrections = data[hero][title]
except KeyError:
# No corrections needed according to the data.
...
else:
for correction in corrections:
if correction[0] is None:
# Append a string to the description.
description += correction[1]
elif correction[1] is None:
# Prepend a string to the description.
description = correction[0] + description
elif correction[0] == "":
# Create a new description.
description = correction[1]
else:
# Remove a substring from the description.
description = description.replace(correction[0], correction[1])
# To split the text into paragraphs.
labels = [
"Dragonqueen: Breath of Life",
"Dragonqueen: Preservation",
"Dragonqueen: Wing Buffet",
"Breath of Fire",
"Keg Smash",
"Destroyer: Incinerate",
"World Breaker: Lava Burst",
"Destroyer: Onslaught",
"World Breaker: Earth Shatter",
"Worgen: Razor Swipe",
"Worgen: Disengage",
"Human: Gilnean Cocktail",
"Human: Darkflight",
"Molten Core: Molten Swing",
"Molten Core: Meteor Shower",
"Molten Core: Explosive Rune",
"Unstealth: Sinister Strike",
"Stealth: Ambush",
"Unstealth: Blade Flurry",
"Stealth: Cheap Shot",
"Unstealth: Eviscerate",
"Stealth: Garrote",
"Medivac Dropship",
"Reinforcements",
]
for label in labels:
label = f" {label} "
description = description.replace(label, f"{label} ")
# To fix inconsistencies.
old_strings = [
" ",
"Repeatable Quest:",
" Unlimited range.",
"After reaching level",
"After reaching Level",
]
new_strings = [
" ",
"Quest:",
" Unilimited range.",
"After reaching Level",
"Quest: After reaching Level",
]
for old_string, new_string in zip(old_strings, new_strings):
description = description.replace(old_string, new_string)
# To split paragraphs near keywords.
keywords = [
"Active",
"Passive",
"Quest",
"Reward",
]
for keyword in keywords:
description = description.replace(f". {keyword}:", f". {keyword}:")
# To remove leading and trailing space or new line characters.
description = description.strip(" \n")
# To add a period at the end when missing.
if not (description.endswith(".") or description.endswith("!")):
description += "."
return description
@staticmethod
async def update_tooltips_and_keywords():
resources = {
"Chen": "Brew",
"Deathwing": "Energy",
"Lt. Morales": "Energy",
"Sonya": "Fury",
"Valeera": "Energy",
"Zarya": "Energy",
}
query = "DELETE FROM Tooltips"
async with database_connection.cursor() as cursor:
await cursor.execute(query)
query = "DELETE FROM Keywords"
async with database_connection.cursor() as cursor:
await cursor.execute(query)
for file in os.listdir("./data/heroes/"):
if not file.endswith(".json"):
continue
with open(
f"./data/heroes/{file}",
"r",
encoding="utf-8",
) as file:
data = json.load(file)
hero_id = int(data.get("id"))
hero_code = data.get("hyperlinkId")
hero = data.get("name")
# Abilities
for unit in data["abilities"]:
for ability in data["abilities"][unit]:
assert isinstance(ability, dict)
is_new = True
level = None
code = ability.get("abilityId")
assert code is not None
if code in [
"Alexstrasza|R4",
"LostVikings|Q1",
"LostVikings|Q2",
"LostVikings|W1",
"LostVikings|W2",
"LostVikings|E1",
"Ragnaros|R3",
]:
continue
name = ability.get("name")
assert name is not None
try:
cooldown = ability.get("cooldown")
if cooldown is not None:
cooldown = float(cooldown)
except TypeError:
cooldown = None
description = ability.get("description")
assert description is not None
description = Database.fix_description(description, hero, name)
hotkey = ability.get("hotkey")
if name == "Nordic Attack Squad":
hotkey = None
icon = ability.get("icon")
try:
cost = ability.get("manaCost")
if cost is not None:
cost = float(cost)
if hero in list(resources):
resource = resources.get(hero)
else:
resource = "Mana"
except TypeError:
cost = None
resource = None
if code == "Guldan|D1":
cost = 222
resource = "Health"
elif code == "Gazlowe|Q1":
resource = "Scrap"
elif code == "Samuro|21":
icon = "storm_ui_ingame_heroselect_btn_samuro.png"
elif code == "LostVikings|41":
name = "Select All"
description = "Issue orders to Olaf, Baleog, and Erik."
elif code == "LtMorales|Q1":
cooldown = 1
elif code == "Stitches|D1":
description = description.replace(
"Vile Gas Hitting", "Vile Gas Hitting"
)
category = ability.get("type")
assert isinstance(category, str)
category = category.capitalize()
if category == "Heroic":
for tier in [4, 10]:
for talent in data["talents"][str(tier)]:
title = talent.get("name")
if name == title:
is_new = False
continue
elif category == "Activable":
category = "Active"
elif category == "Subunit":
category = "Special"
elif category == "Trait" and "Activate to" in description:
hotkey = "D"
if is_new:
query = """
INSERT INTO Tooltips (
TooltipID,
Title,
Cooldown,
Cost,
Description,
Hotkey,
Icon,
Level,
Resource,
Slot,
Unit,
HeroID
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
values = (
code,
name,
cooldown,
cost,
description,
hotkey,
icon,
level,
resource,
category,
unit,
hero_id,
)
async with database_connection.cursor() as cursor:
await cursor.execute(query, values)
await Database.insert_keyword(code, description)
# Missing from data, being added manually.
if hero == "Samuro":
code = "Samuro|D1"
name = "Image Transmission"
cooldown = 14
cost = None
description = "Activate to switch places with a target Mirror Image, removing most negative effects from Samuro and the Mirror Image. Advancing Strikes Basic Attacks against enemy Heroes increase Samuro's Movement Speed by 25% for 2 seconds."
hotkey = "D"
icon = "storm_ui_icon_samuro_flowingstrikes.png"
category = "Trait"
unit = "Samuro"
hero_id = 58
query = """
INSERT OR REPLACE INTO Tooltips (
TooltipID,
Title,
Cooldown,
Cost,
Description,
Hotkey,
Icon,
Level,
Resource,
Slot,
Unit,
HeroID
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
values = (
code,
name,
cooldown,
cost,
description,
hotkey,
icon,
level,
resource,
category,
unit,
hero_id,
)
async with database_connection.cursor() as cursor:
await cursor.execute(query, values)
await Database.insert_keyword(code, description)
# Talents
for level in [1, 4, 7, 10, 13, 16, 20]:
for talent in data["talents"][str(level)]:
cost = None
cooldown = None
unit = None
resource = None
# Replace generic terms to handle Talents with the same ID across different Heroes.
assert isinstance(talent, dict)
talent_id = talent.get("tooltipId")
assert talent_id is not None and isinstance(talent_id, str)
code = talent_id.replace("Generic", hero_code).replace(
"Nexus", f"{hero_code}Nexus"
)
name = talent.get("name")
assert name is not None
description = talent.get("description")
assert description is not None
if level == 20 and code in [
"AlarakCounterStrike2ndHeroic",
"AlarakDeadlyCharge",
]:
if name == "Deadly Charge":
code += "2ndHeroic"
description += (
" This ability will take over Alarak's Trait button."
)
for ability in data["abilities"]["Alarak"]:
assert isinstance(ability, dict)
title = ability.get("name")
if name == title:
cost = ability.get("manaCost")
if cost is not None:
cost = float(cost)
resource = (
resources.get(hero)
if hero in list(resources)
else "Mana"
)
description = Database.fix_description(description, hero, name)
try:
cooldown = talent.get("cooldown")
if cooldown is not None:
cooldown = float(cooldown)
except TypeError:
expressions = [
r"This effect has a(.+?)second cooldown.",
r"This effect can only happen once every(.+?)seconds.",
r"This can only occur every(.+?)seconds.",
r"Can only trigger once every(.+?)seconds.",
r"Every(.+?)seconds, ",
r"Additionally, every(.+?)seconds, ",
r"Can only occur once every(.+?)seconds",
r"every(.+?)seconds.",
]
for expression in expressions:
if match := re.search(expression, description):
try:
cooldown = float(match.group(1))
# To ignore periodic effects that match some expressions.
if cooldown < 5 or name in [
"Evolutionary Link",
"Fortified Bunker",
]:
cooldown = None
break
except ValueError:
cooldown = None
else:
cooldown = None
category = talent.get("type")
assert isinstance(category, str)
category = category.capitalize()
hotkey = talent.get("hotkey")
if level in [4, 10]:
if category == "Heroic" and hero not in [
"Deathwing",
"Tracer",
]:
hotkey = "R"
for ability in data["abilities"][hero_code]:
assert isinstance(ability, dict)
title = ability.get("name")
if name == title:
cost = ability.get("manaCost")
if cost is not None:
cost = float(cost)
resource = (
resources.get(hero)
if hero in list(resources)
else "Mana"
)
if hotkey is None:
if hero == "The Lost Vikings":
if name in [
"Spin To Win!",
"Norse Force!",
]:
hotkey = "Q"
elif name == "Jump!":
hotkey = "W"
elif name == "Viking Bribery":
hotkey = "E"
elif hero == "Tassadar":
if name == "Oracle":
hotkey = "D"
category = "Trait"
trait_tests = [
"Activate",
"Cancel",
"can be activated to",
"Stop channeling",
"can activate",
]
active_tests = [
"Can be toggled",
"can activate",
"Activate to",
]
if name == "Rite of Rak'Shir":
hotkey = "1"
category = "Active"
elif name == "Seasoned Soldier":
hotkey = None
category = "Passive"
elif name == "Legion of Beetles":
hotkey = "1"
category = "Active"
elif category == "Trait" and any(
string in description for string in trait_tests
):
hotkey = "D"
elif (category == "Active" and name != "Amani Hide") or any(
string in description for string in active_tests
):
hotkey = "1"
else:
if hero == "The Lost Vikings":
if name == "Nordic Attack Squad":
hotkey = None
icon = talent.get("icon")
query = """
INSERT OR REPLACE INTO Tooltips (
TooltipID,
Title,
Cooldown,
Cost,
Description,
Hotkey,
Icon,
Level,
Resource,
Slot,
Unit,
HeroID
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
values = (
code,
name,
cooldown,
cost,
description,
hotkey,
icon,
level,
resource,
category,
unit,
hero_id,
)
async with database_connection.cursor() as cursor:
await cursor.execute(query, values)
await Database.insert_keyword(code, description)
await database_connection.commit()
print("Tooltips data updated.")
# To change Keywords, update the list in the Search cog too.
@staticmethod
async def insert_keyword(
code: str,
description: str,
) -> None:
keywords = []
if "Armor" in description:
match = re.search("lose(.+?)Armor", description)
if match is not None:
match = match.group(1)
flag = len(match) < 6
else:
flag = False
if "0 Armor" in description or "5 Armor" in description:
keywords.append("Armor")
checks = [
"Armor reduc",
"Armor is reduced",
"lowers a Hero's Armor",
"lowers enemy Hero Armor",
"lowering their Armor",
"reduce their Armor",
"reduces their Armor",
"reduce the Armor",
"reduces the Armor",
"reduces the target's Armor",
"reducing their Armor",
"their Armor lowered",
]
if any(string in description for string in checks) or flag:
keywords.append("Armor Reduction")
if "Physical Armor" in description:
if "0 Physical A" in description or "5 Physical A" in description:
keywords.append("Physical Armor")
checks = [
"decrease the Physical A",
"reduce their Physical A",
"reduces Physical A",
]
if any(string in description for string in checks):
keywords.append("Physical Armor Reduction")
if "Physical Armor against" in description:
keywords.append("Block")
if "Spell Armor" in description:
if "0 Spell A" in description or "5 Spell A" in description:
keywords.append("Spell Armor")
if "toggled to allow" in description:
keywords.append("Spell Shield")
checks = [
"reduces their Spell A",
"their Spell Armor reduced",
]
if any(string in description for string in checks):
keywords.append("Spell Armor Reduction")
checks = [
"allied Heroes are Unstoppable",
"allies below Johanna are Unstoppable",
"them Unstoppable",
"ally Unstoppable",
"allies Unstoppable",
"both gain Unstoppable",
"removes Roots",
"removes Stuns",
"remove all Stuns",
"remove all damage over time and disabling effects",
"remove all disabling effects",
"remove all Slows",
"removes all Slows",
]
if (
any(string in description for string in checks)
and code != "BarbarianHurricaneWhirlwindTalent"
):
keywords.append("Cleanse")
checks = [
"reduce heal",
"reducing all healing received",
"reduce the healing received",
"reduce their healing received",
"reduce enemy healing received",
"reduces healing received",
"reduced heal",
"less healing",
]
if any(string in description for string in checks):
keywords.append("Healing Reduction")
for keyword in keywords:
query = """
INSERT INTO Keywords (
TooltipID,
Name
)
VALUES (?, ?)
"""
values = (
code,
keyword,
)
async with database_connection.cursor() as cursor:
await cursor.execute(query, values)
async def insert_maps(self) -> None:
query = """
SELECT COUNT(*)
FROM Maps
"""
async with database_connection.cursor() as cursor:
await cursor.execute(query)
results = await cursor.fetchone()
assert results is not None
rows = results[0]
if rows > 0:
print("Maps data present.")
else:
maps = [
"Alterac Pass",
"Battlefield of Eternity",
"Blackheart's Bay",
"Braxis Holdout",
"Cursed Hollow",
"Dragon Shire",
"Garden of Terror",
"Hanamura Temple",
"Haunted Mines",
"Infernal Shrines",
"Sky Temple",
"Tomb of the Spider Queen",
"Towers of Doom",
"Volskaya Foundry",
"Warhead Junction",
]
quick_match_bans = [
"Haunted Mines",
]
storm_league_bans = [
"Blackheart's Bay",
"Haunted Mines",
"Volskaya Foundry",
]
for map in maps:
quick_match = map not in quick_match_bans
storm_league = map not in storm_league_bans
query = """
INSERT INTO Maps (
Name,
QuickMatch,
StormLeague
)
VALUES (?, ?, ?)
"""
values = (
map,
quick_match,
storm_league,
)
async with database_connection.cursor() as cursor:
await cursor.execute(query, values)
await database_connection.commit()
print("Maps data added.")
async def load_database(self) -> None:
print("Database loading...")
query = "PRAGMA foreign_keys = ON;"
async with database_connection.cursor() as cursor:
await cursor.execute(query)
if not is_file:
await self.create_heroes()
await self.insert_heroes()
await self.create_tooltips()
await self.create_keywords()
await self.update_tooltips_and_keywords()
await self.create_maps()
await self.insert_maps()
await self.create_drafts()
await self.create_teams()
await self.create_selections()
await self.create_matchups()
await self.create_matchup_contributors()
await self.create_matchup_tips()
print("Database ready.")
async def main() -> None:
path = "./main.db"
# Check if the database exists and store the value for later usage.
global is_file
is_file = os.path.isfile(path)
# Connect to the database.
global database_connection
database_connection = await aiosqlite.connect(path)
# Create tables and insert data into the database.
database = Database()
# Load the database.
await database.load_database()