22import glob
33import io
44import logging
5+ import json
56import math
67import os
78import random
@@ -121,7 +122,7 @@ def __init__(self, bot):
121122 self .bot .user .id : ["602caef0-b928-4dcb-8785-3da2a7fb747d" ], # Super Mario 3D All-Stars
122123 config .parakarry : [
123124 "c47d6eda-ae22-4036-afca-bb7df4e81738" , # Paper Mario: The Thousand-Year Door
124- "dd2dbc1d-938c-495a-a630-75ac96024695" , # Nintendo 64 – Nintendo Classics
125+ "dd2dbc1d-938c-495a-a630-75ac96024695" , # Nintendo 64 – Nintendo Classics
125126 ],
126127 }
127128
@@ -138,7 +139,7 @@ def __init__(self, bot):
138139 'Not specified' ,
139140 '???' ,
140141 'Reply hazy' ,
141- 'Most likely' ,
142+ 'Most likely'
142143 ]
143144
144145 self .INDEX , self .EMOTES = (0 , 1 )
@@ -944,7 +945,7 @@ async def _profile_timezone_autocomplete(self, interaction: discord.Interaction,
944945 name = 'timezone' ,
945946 description = 'Pick your timezone to show on your profile and for when others are looking for group' ,
946947 )
947- @app_commands .describe (timezone = 'This is based on your region. I.e . "America/New_York' )
948+ @app_commands .describe (timezone = 'This is based on your region. e.g . "America/New_York' )
948949 @app_commands .autocomplete (timezone = _profile_timezone_autocomplete )
949950 async def _profile_timezone (self , interaction : discord .Interaction , timezone : str ):
950951 await interaction .response .defer (ephemeral = True )
@@ -986,16 +987,16 @@ async def _profile_games(
986987 # If user selected an auto-complete result, we will be provided the deku_id automatically which saves effort
987988 flagConfirmation = False
988989 gameList = []
989- deku_id1 = db .find_one ({'deku_id' : game1 })
990- deku_id2 = None if not game2 else db .find_one ({'deku_id' : game2 })
991- deku_id3 = None if not game3 else db .find_one ({'deku_id' : game3 })
992- deku_id4 = None if not game4 else db .find_one ({'deku_id' : game4 })
993- deku_id5 = None if not game5 else db .find_one ({'deku_id' : game5 })
990+ doc1 = db .find_one ({'deku_id' : game1 })
991+ doc2 = None if not game2 else db .find_one ({'deku_id' : game2 })
992+ doc3 = None if not game3 else db .find_one ({'deku_id' : game3 })
993+ doc4 = None if not game4 else db .find_one ({'deku_id' : game4 })
994+ doc5 = None if not game5 else db .find_one ({'deku_id' : game5 })
994995
995996 games = [game1 , game2 , game3 , game4 , game5 ]
996- deku_ids = [deku_id1 , deku_id2 , deku_id3 , deku_id4 , deku_id5 ]
997+ documents = [doc1 , doc2 , doc3 , doc4 , doc5 ]
997998
998- def resolve_deku_id (game_name : str ):
999+ def resolve_document (game_name : str ):
9991000 return self .Games .search (game_name )
10001001
10011002 async def return_failure (interaction : discord .Interaction , game_name : str ):
@@ -1004,18 +1005,18 @@ async def return_failure(interaction: discord.Interaction, game_name: str):
10041005 )
10051006
10061007 flagConfirmation = False
1007- for idx , deku_id in enumerate (deku_ids ):
1008+ for idx , document in enumerate (documents ):
10081009 if not games [idx ]:
10091010 continue
10101011
1011- if not deku_id :
1012+ if not document :
10121013 flagConfirmation = True
1013- deku_id = resolve_deku_id (games [idx ])
1014+ document = resolve_document (games [idx ])
10141015
1015- if not deku_id :
1016+ if not document :
10161017 return await return_failure (interaction , games [idx ])
10171018
1018- gameList .append (deku_id ['deku_id' ])
1019+ gameList .append (document ['deku_id' ])
10191020
10201021 msg = None
10211022 if flagConfirmation :
@@ -1532,6 +1533,77 @@ async def _profile_revoke(
15321533 return await msg .edit (
15331534 content = f'{ config .greenTick } { item .title ()} `{ name } ` revoked from { len (users ) - failCount } /{ len (users )} member(s).'
15341535 )
1536+
1537+ @commands .group (name = 'migratefavgames' , invoke_without_command = True )
1538+ async def _migratefavgames (self , ctx ):
1539+ if ctx .author .id not in [
1540+ 125233822760566784 , # MattBSG
1541+ 123879073972748290 , # Lyrus
1542+ ]:
1543+ return await ctx .reply ('no permission' )
1544+ new_id_cache = dict ()
1545+
1546+ with open ('giantbomb_names.json' ) as f :
1547+ game_lookup = json .load (f )
1548+
1549+ db = mclient .bowser .users
1550+
1551+ query = { "favgames" : { '$exists' : True , '$not' : { '$size' : 0 } } }
1552+ count = db .count_documents (query )
1553+ users = db .find (query )
1554+
1555+ message = await ctx .reply (f'Migrating... 0/{ count } ' )
1556+
1557+ for j , user in enumerate (users ):
1558+ new_games = user ['favgames' ]
1559+
1560+ for i , game in enumerate (user ['favgames' ]):
1561+ # Not a GiantBomb id
1562+ if not game .startswith ("3030-" ):
1563+ new_id_cache [game ] = game
1564+
1565+ # Already cached
1566+ if game in new_id_cache :
1567+ new_games [i ] = new_id_cache [game ]
1568+ continue
1569+
1570+ # Get name from GiantBomb archive and search
1571+
1572+ # giantbomb id unknown
1573+ if game not in game_lookup :
1574+ new_games [i ] = game # keep the giantbomb id
1575+ new_id_cache [game ] = game
1576+ continue
1577+
1578+ names = game_lookup [game ]
1579+
1580+ score = 0
1581+ deku_id = None
1582+ for name in names :
1583+ search = self .Games .search (name )
1584+
1585+ if search ['score' ] > score :
1586+ score = search ['score' ]
1587+ deku_id = search ['deku_id' ]
1588+
1589+ if not deku_id :
1590+ new_games [i ] = game # keep the giantbomb id
1591+ new_id_cache [game ] = game
1592+ continue
1593+
1594+ new_games [i ] = deku_id
1595+ new_id_cache [game ] = deku_id
1596+
1597+ # update user record
1598+ db .update_one ({'_id' : user ['_id' ]}, {'$set' : {'favgames' : new_games }}, upsert = True )
1599+
1600+ # update the progress message
1601+ interval = (count // 100 )+ 1
1602+ if (((j + 1 ) % interval ) == 0 ):
1603+ await message .edit (content = f'Migrating... { j + 1 } /{ count } ' )
1604+
1605+ await message .edit (content = f'Migrating... { count } /{ count } ' )
1606+ await message .reply ('Done!' )
15351607
15361608 @commands .Cog .listener ()
15371609 async def on_message (self , message ):
0 commit comments