diff options
| author | 2021-05-16 15:50:07 -0400 | |
|---|---|---|
| committer | 2021-05-16 15:50:07 -0400 | |
| commit | 07b5f296bed099d4cde849cfeba3320e3f4aa808 (patch) | |
| tree | 87b8efa0a3d11d38eb0f77c75e4a42d5033584b9 /bot/exts/evergreen/recommend_game.py | |
| parent | delete trailing whitespace after docstring (diff) | |
| parent | Merge pull request #738 from python-discord/vcokltfre/feat/bookmark-reply (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'bot/exts/evergreen/recommend_game.py')
| -rw-r--r-- | bot/exts/evergreen/recommend_game.py | 17 | 
1 files changed, 9 insertions, 8 deletions
| diff --git a/bot/exts/evergreen/recommend_game.py b/bot/exts/evergreen/recommend_game.py index 5e262a5b..35d60128 100644 --- a/bot/exts/evergreen/recommend_game.py +++ b/bot/exts/evergreen/recommend_game.py @@ -6,13 +6,14 @@ from random import shuffle  import discord  from discord.ext import commands +from bot.bot import Bot +  log = logging.getLogger(__name__)  game_recs = []  # Populate the list `game_recs` with resource files  for rec_path in Path("bot/resources/evergreen/game_recs").glob("*.json"): -    with rec_path.open(encoding='utf8') as file: -        data = json.load(file) +    data = json.loads(rec_path.read_text("utf8"))      game_recs.append(data)  shuffle(game_recs) @@ -20,11 +21,11 @@ shuffle(game_recs)  class RecommendGame(commands.Cog):      """Commands related to recommending games.""" -    def __init__(self, bot: commands.Bot) -> None: +    def __init__(self, bot: Bot) -> None:          self.bot = bot          self.index = 0 -    @commands.command(name="recommendgame", aliases=['gamerec']) +    @commands.command(name="recommendgame", aliases=("gamerec",))      async def recommend_game(self, ctx: commands.Context) -> None:          """Sends an Embed of a random game recommendation."""          if self.index >= len(game_recs): @@ -33,18 +34,18 @@ class RecommendGame(commands.Cog):          game = game_recs[self.index]          self.index += 1 -        author = self.bot.get_user(int(game['author'])) +        author = self.bot.get_user(int(game["author"]))          # Creating and formatting Embed          embed = discord.Embed(color=discord.Colour.blue())          if author is not None:              embed.set_author(name=author.name, icon_url=author.avatar_url) -        embed.set_image(url=game['image']) -        embed.add_field(name='Recommendation: ' + game['title'] + '\n' + game['link'], value=game['description']) +        embed.set_image(url=game["image"]) +        embed.add_field(name=f"Recommendation: {game['title']}\n{game['link']}", value=game["description"])          await ctx.send(embed=embed) -def setup(bot: commands.Bot) -> None: +def setup(bot: Bot) -> None:      """Loads the RecommendGame cog."""      bot.add_cog(RecommendGame(bot)) | 
