aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/evergreen
diff options
context:
space:
mode:
Diffstat (limited to 'bot/seasons/evergreen')
-rw-r--r--bot/seasons/evergreen/minesweeper.py8
-rw-r--r--bot/seasons/evergreen/showprojects.py4
-rw-r--r--bot/seasons/evergreen/snakes/utils.py26
-rw-r--r--bot/seasons/evergreen/speedrun.py2
4 files changed, 23 insertions, 17 deletions
diff --git a/bot/seasons/evergreen/minesweeper.py b/bot/seasons/evergreen/minesweeper.py
index 015b09df..b0ba8145 100644
--- a/bot/seasons/evergreen/minesweeper.py
+++ b/bot/seasons/evergreen/minesweeper.py
@@ -33,7 +33,7 @@ class CoordinateConverter(commands.Converter):
"""Converter for Coordinates."""
async def convert(self, ctx: commands.Context, coordinate: str) -> typing.Tuple[int, int]:
- """Take in a coordinate string and turn it into x, y"""
+ """Take in a coordinate string and turn it into an (x, y) tuple."""
if not 2 <= len(coordinate) <= 3:
raise commands.BadArgument('Invalid co-ordinate provided')
@@ -81,7 +81,7 @@ class Minesweeper(commands.Cog):
@commands.group(name='minesweeper', aliases=('ms',), invoke_without_command=True)
async def minesweeper_group(self, ctx: commands.Context) -> None:
- """Commands for Playing Minesweeper"""
+ """Commands for Playing Minesweeper."""
await ctx.send_help(ctx.command)
@staticmethod
@@ -216,7 +216,7 @@ class Minesweeper(commands.Cog):
self.reveal_zeros(revealed, board, x_, y_)
async def check_if_won(self, ctx: commands.Context, revealed: GameBoard, board: GameBoard) -> bool:
- """Checks if a player has won"""
+ """Checks if a player has won."""
if any(
revealed[y][x] in ["hidden", "flag"] and board[y][x] != "bomb"
for x in range(10)
@@ -268,7 +268,7 @@ class Minesweeper(commands.Cog):
@minesweeper_group.command(name="end")
async def end_command(self, ctx: commands.Context) -> None:
- """End your current game"""
+ """End your current game."""
game = self.games[ctx.author.id]
game.revealed = game.board
await self.update_boards(ctx)
diff --git a/bot/seasons/evergreen/showprojects.py b/bot/seasons/evergreen/showprojects.py
index d41132aa..a943e548 100644
--- a/bot/seasons/evergreen/showprojects.py
+++ b/bot/seasons/evergreen/showprojects.py
@@ -17,7 +17,7 @@ class ShowProjects(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message: Message) -> None:
- """Adds reactions to posts in #show-your-projects"""
+ """Adds reactions to posts in #show-your-projects."""
reactions = ["\U0001f44d", "\U00002764", "\U0001f440", "\U0001f389", "\U0001f680", "\U00002b50", "\U0001f6a9"]
if (message.channel.id == Channels.show_your_projects
and message.author.bot is False
@@ -29,6 +29,6 @@ class ShowProjects(commands.Cog):
def setup(bot: commands.Bot) -> None:
- """Show Projects Reaction Cog"""
+ """Show Projects Reaction Cog."""
bot.add_cog(ShowProjects(bot))
log.info("ShowProjects cog loaded")
diff --git a/bot/seasons/evergreen/snakes/utils.py b/bot/seasons/evergreen/snakes/utils.py
index 76809bd4..7d6caf04 100644
--- a/bot/seasons/evergreen/snakes/utils.py
+++ b/bot/seasons/evergreen/snakes/utils.py
@@ -388,8 +388,7 @@ class SnakeAndLaddersGame:
"""
Create a new Snakes and Ladders game.
- Listen for reactions until players have joined,
- and the game has been started.
+ Listen for reactions until players have joined, and the game has been started.
"""
def startup_event_check(reaction_: Reaction, user_: Member) -> bool:
"""Make sure that this reaction is what we want to operate on."""
@@ -457,6 +456,7 @@ class SnakeAndLaddersGame:
return # We're done, no reactions for the last 5 minutes
async def _add_player(self, user: Member) -> None:
+ """Add player to game."""
self.players.append(user)
self.player_tiles[user.id] = 1
@@ -490,7 +490,7 @@ class SnakeAndLaddersGame:
delete_after=10
)
- async def player_leave(self, user: Member) -> None:
+ async def player_leave(self, user: Member) -> bool:
"""
Handle players leaving the game.
@@ -515,11 +515,13 @@ class SnakeAndLaddersGame:
is_surrendered = True
self._destruct()
- async def cancel_game(self, user: Member) -> None:
- """Allow the game author to cancel the running game."""
- if not user == self.author:
- await self.channel.send(user.mention + " Only the author of the game can cancel it.", delete_after=10)
- return
+ return is_surrendered
+ else:
+ await self.channel.send(user.mention + " You are not in the match.", delete_after=10)
+ return is_surrendered
+
+ async def cancel_game(self) -> None:
+ """Cancel the running game."""
await self.channel.send("**Snakes and Ladders**: Game has been canceled.")
self._destruct()
@@ -670,6 +672,7 @@ class SnakeAndLaddersGame:
self.round_has_rolled[user.id] = True
async def _complete_round(self) -> None:
+ """At the conclusion of a round check to see if there's been a winner."""
self.state = 'post_round'
# check for winner
@@ -684,19 +687,22 @@ class SnakeAndLaddersGame:
self._destruct()
def _check_winner(self) -> Member:
+ """Return a winning member if we're in the post-round state and there's a winner."""
if self.state != 'post_round':
return None
return next((player for player in self.players if self.player_tiles[player.id] == 100),
None)
def _check_all_rolled(self) -> bool:
+ """Check if all members have made their roll."""
return all(rolled for rolled in self.round_has_rolled.values())
def _destruct(self) -> None:
+ """Clean up the finished game object."""
del self.snakes.active_sal[self.channel]
- def _board_coordinate_from_index(self, index: int) -> Tuple[float, float]:
- # converts the tile number to the x/y coordinates for graphical purposes
+ def _board_coordinate_from_index(self, index: int) -> Tuple[int, int]:
+ """Convert the tile number to the x/y coordinates for graphical purposes."""
y_level = 9 - math.floor((index - 1) / 10)
is_reversed = math.floor((index - 1) / 10) % 2 != 0
x_level = (index - 1) % 10
diff --git a/bot/seasons/evergreen/speedrun.py b/bot/seasons/evergreen/speedrun.py
index 2f59c886..76c5e8d3 100644
--- a/bot/seasons/evergreen/speedrun.py
+++ b/bot/seasons/evergreen/speedrun.py
@@ -23,6 +23,6 @@ class Speedrun(commands.Cog):
def setup(bot: commands.Bot) -> None:
- """Load the Speedrun cog"""
+ """Load the Speedrun cog."""
bot.add_cog(Speedrun(bot))
log.info("Speedrun cog loaded")