diff options
Diffstat (limited to 'bot/seasons')
| -rw-r--r-- | bot/seasons/evergreen/minesweeper.py | 16 | ||||
| -rw-r--r-- | bot/seasons/evergreen/recommend_game.py | 51 |
2 files changed, 64 insertions, 3 deletions
diff --git a/bot/seasons/evergreen/minesweeper.py b/bot/seasons/evergreen/minesweeper.py index 9f6aff95..f6fa9c47 100644 --- a/bot/seasons/evergreen/minesweeper.py +++ b/bot/seasons/evergreen/minesweeper.py @@ -1,7 +1,7 @@ import logging import typing from dataclasses import dataclass -from random import random +from random import randint, random import discord from discord.ext import commands @@ -22,7 +22,7 @@ MESSAGE_MAPPING = { 10: ":keycap_ten:", "bomb": ":bomb:", "hidden": ":grey_question:", - "flag": ":pyflag:" + "flag": ":flag_black:" } log = logging.getLogger(__name__) @@ -36,7 +36,13 @@ class CoordinateConverter(commands.Converter): if not 2 <= len(coordinate) <= 3: raise commands.BadArgument('Invalid co-ordinate provided') - digit, letter = sorted(coordinate.lower()) + coordinate = coordinate.lower() + if coordinate[0].isalpha(): + digit = coordinate[1:] + letter = coordinate[0] + else: + digit = coordinate[:-1] + letter = coordinate[-1] if not digit.isdigit(): raise commands.BadArgument @@ -93,6 +99,10 @@ class Minesweeper(commands.Cog): for _ in range(10) ] for _ in range(10) ] + + # make sure there is always a free cell + board[randint(0, 9)][randint(0, 9)] = "number" + for y, row in enumerate(board): for x, cell in enumerate(row): if cell == "number": diff --git a/bot/seasons/evergreen/recommend_game.py b/bot/seasons/evergreen/recommend_game.py new file mode 100644 index 00000000..835a4e53 --- /dev/null +++ b/bot/seasons/evergreen/recommend_game.py @@ -0,0 +1,51 @@ +import json +import logging +from pathlib import Path +from random import shuffle + +import discord +from discord.ext import commands + +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='utf-8') as file: + data = json.load(file) + game_recs.append(data) +shuffle(game_recs) + + +class RecommendGame(commands.Cog): + """Commands related to recommending games.""" + + def __init__(self, bot: commands.Bot) -> None: + self.bot = bot + self.index = 0 + + @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): + self.index = 0 + shuffle(game_recs) + game = game_recs[self.index] + self.index += 1 + + 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']) + + await ctx.send(embed=embed) + + +def setup(bot: commands.Bot) -> None: + """Loads the RecommendGame cog.""" + bot.add_cog(RecommendGame(bot)) + log.info("RecommendGame cog loaded") |