aboutsummaryrefslogtreecommitdiff
path: root/minecrafttrivia/trivia_interface_cog.py
diff options
context:
space:
mode:
authorRoman Gräf <romangraef@loves.dicksinhisan.us>2020-12-05 00:46:55 +0100
committerRoman Gräf <romangraef@loves.dicksinhisan.us>2020-12-05 00:46:55 +0100
commitab659c3f1f2d0cbb3705400622678125dd6f4369 (patch)
treec3cc613c57e79a33ae0678c34ecc7e9c8dacddb0 /minecrafttrivia/trivia_interface_cog.py
parent987f3bc618574ea52ea551dd31d131a2d523d7dc (diff)
downloadRedCog-MinecraftTrivia-ab659c3f1f2d0cbb3705400622678125dd6f4369.tar.gz
RedCog-MinecraftTrivia-ab659c3f1f2d0cbb3705400622678125dd6f4369.tar.bz2
RedCog-MinecraftTrivia-ab659c3f1f2d0cbb3705400622678125dd6f4369.zip
bug fixes and leaderboards
Diffstat (limited to 'minecrafttrivia/trivia_interface_cog.py')
-rw-r--r--minecrafttrivia/trivia_interface_cog.py43
1 files changed, 33 insertions, 10 deletions
diff --git a/minecrafttrivia/trivia_interface_cog.py b/minecrafttrivia/trivia_interface_cog.py
index 939bad0..b27f789 100644
--- a/minecrafttrivia/trivia_interface_cog.py
+++ b/minecrafttrivia/trivia_interface_cog.py
@@ -2,31 +2,54 @@ import typing
import discord
from discord.ext.commands import guild_only
-from redbot.core import commands
+from redbot.core import commands, Config
from redbot.core.bot import Red
-from .game import OngoingGame, CraftingGame
+from . import utils
+from .game import OngoingGame, CraftingGame, GamePhase
class TriviaInterfaceCog(commands.Cog):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- self.active_games_per_channel: typing.Dict[int,] = {}
+ self.config = Config.get_conf(self, identifier=262200644)
+ self.config.register_global(version=0)
+ self.config.register_guild(
+ join_timeout=30,
+ guess_timeout=60,
+ total_scores={},
+ high_scores={},
+ )
+ self.active_games_per_channel: typing.Dict[int, OngoingGame] = {}
def get_game(self, channel: discord.TextChannel) -> typing.Optional[OngoingGame]:
- return channel.id in self.active_games_per_channel and self.active_games_per_channel[channel.id]
+ game = channel.id in self.active_games_per_channel and self.active_games_per_channel[channel.id]
+ if game and game.phase != GamePhase.FINISHED:
+ return game
def create_game(self, bot: Red, channel: discord.TextChannel) -> OngoingGame:
- game = CraftingGame(bot, channel)
+ game = CraftingGame(bot, self.config, channel)
self.active_games_per_channel[channel.id] = game
return game
@commands.command(aliases=["mctrivia", "mct"])
@guild_only()
- async def minecrafttrivia(self, ctx: commands.GuildContext):
+ async def minecrafttrivia(self, ctx: commands.GuildContext, action: str = "new"):
"""Starts a game of minecraft trivia"""
game = self.get_game(ctx.channel)
- if game:
- return await ctx.send("Game already started.")
- game = self.create_game(ctx.bot, ctx.channel)
- await game.start_signup()
+ if action == "new":
+ if game:
+ return await ctx.send("Game already started.")
+ game = self.create_game(ctx.bot, ctx.channel)
+ await game.start_signup()
+ elif action[:4] == "high":
+ high_scores = await self.config.guild(ctx.guild).high_scores()
+ await ctx.send(embed=discord.Embed(
+ title=f"MC Trivia Highscores for {ctx.guild.name}",
+ description=utils.format_leaderboard(utils.create_leaderboard(high_scores))))
+ elif action[:4] == "lead":
+ total_scores = await self.config.guild(ctx.guild).total_scores()
+ await ctx.send(embed=discord.Embed(
+ title=f"MC Trivia Leaderboard for {ctx.guild.name}",
+ description=utils.format_leaderboard(utils.create_leaderboard(total_scores))
+ ))