diff options
author | Roman Gräf <romangraef@loves.dicksinhisan.us> | 2020-12-05 01:52:04 +0100 |
---|---|---|
committer | Roman Gräf <romangraef@loves.dicksinhisan.us> | 2020-12-05 01:52:04 +0100 |
commit | 9f23c0145e7a8118033e31ef1cc915a7e7f42de8 (patch) | |
tree | 494ed2eeaac6144463d02b18ee676dc4d59d1d91 | |
parent | 5c1651f902f0e8553d1e19feaacd53e32ec2d558 (diff) | |
download | RedCog-MinecraftTrivia-9f23c0145e7a8118033e31ef1cc915a7e7f42de8.tar.gz RedCog-MinecraftTrivia-9f23c0145e7a8118033e31ef1cc915a7e7f42de8.tar.bz2 RedCog-MinecraftTrivia-9f23c0145e7a8118033e31ef1cc915a7e7f42de8.zip |
config opts
-rw-r--r-- | minecrafttrivia/game.py | 7 | ||||
-rw-r--r-- | minecrafttrivia/trivia_interface_cog.py | 83 | ||||
-rw-r--r-- | minecrafttrivia/utils.py | 2 |
3 files changed, 69 insertions, 23 deletions
diff --git a/minecrafttrivia/game.py b/minecrafttrivia/game.py index 3e8f725..e2373e6 100644 --- a/minecrafttrivia/game.py +++ b/minecrafttrivia/game.py @@ -36,14 +36,15 @@ class OngoingGame(ABC): async def start_signup(self): self.phase = GamePhase.SIGNUP + join_timeout = await self.config.join_timeout() embed = discord.Embed( title="Signups opened for new game of Minecraft trivia", - description="React to this message in order to join. You have 30 seconds to signup.", + description=f"React to this message in order to join. You have {join_timeout} seconds to signup.", ) embed.timestamp = datetime.now() self.signup_message = await self.channel.send(embed=embed) await self.signup_message.add_reaction(constants.POSITIVE_REACTION) - await asyncio.sleep(await self.config.join_timeout()) + await asyncio.sleep(join_timeout) embed.description = "Signups are now closed. Wait for the game to finish to start a new one." await self.signup_message.edit(embed=embed) self.participants = await utils.get_participants((await self.channel.fetch_message(self.signup_message.id)).reactions) @@ -62,7 +63,7 @@ class OngoingGame(ABC): await self.channel.send(embed=embed) async def gameloop(self): - for i in range(2):#todo + for i in range(await self.config.round_count()): await self.single_round(i) await self.conclude_game() diff --git a/minecrafttrivia/trivia_interface_cog.py b/minecrafttrivia/trivia_interface_cog.py index b27f789..63553f8 100644 --- a/minecrafttrivia/trivia_interface_cog.py +++ b/minecrafttrivia/trivia_interface_cog.py @@ -2,7 +2,7 @@ import typing import discord from discord.ext.commands import guild_only -from redbot.core import commands, Config +from redbot.core import commands, Config, checks from redbot.core.bot import Red from . import utils @@ -17,6 +17,7 @@ class TriviaInterfaceCog(commands.Cog): self.config.register_guild( join_timeout=30, guess_timeout=60, + round_count=10, total_scores={}, high_scores={}, ) @@ -32,24 +33,68 @@ class TriviaInterfaceCog(commands.Cog): self.active_games_per_channel[channel.id] = game return game - @commands.command(aliases=["mctrivia", "mct"]) + @commands.group(aliases=["mctrivia", "mct"], invoke_without_command=True) @guild_only() - async def minecrafttrivia(self, ctx: commands.GuildContext, action: str = "new"): + async def minecrafttrivia(self, ctx: commands.GuildContext): """Starts a game of minecraft trivia""" game = self.get_game(ctx.channel) - 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)) - )) + if game: + return await ctx.send("Game already started.") + game = self.create_game(ctx.bot, ctx.channel) + await game.start_signup() + + @minecrafttrivia.group(aliases=["config"], invoke_without_command=True) + @guild_only() + @checks.admin() + async def set(self, ctx: commands.GuildContext): + await ctx.send("Available config options: join_timeout guess_timeout round_count") + + @set.command(aliases=["join"]) + @guild_only() + @checks.admin() + async def join_timeout(self, ctx: commands.GuildContext, to: int = None): + c = self.config.guild(ctx.guild) + if to: + await c.join_timeout.set(to) + await ctx.send(f"Set `join_timeout` to `{to}`") + else: + await ctx.send(f"`join_timeout` is `{await c.join_timeout()}`") + + @set.command(aliases=["guess"]) + @guild_only() + @checks.admin() + async def guess_timeout(self, ctx: commands.GuildContext, to: int = None): + c = self.config.guild(ctx.guild) + if to: + await c.guess_timeout.set(to) + await ctx.send(f"Set `guess_timeout` to `{to}`") + else: + await ctx.send(f"`guess_timeout` is `{await c.guess_timeout()}`") + + @set.command(aliases=["rounds"]) + @guild_only() + @checks.admin() + async def round_count(self, ctx: commands.GuildContext, to: int = None): + c = self.config.guild(ctx.guild) + if to: + await c.round_count.set(to) + await ctx.send(f"Set `round_count` to `{to}`") + else: + await ctx.send(f"`round_count` is `{await c.round_count()}`") + + @minecrafttrivia.command(aliases=["high"]) + @guild_only() + async def highscore(self, ctx: commands.GuildContext): + 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)))) + + @minecrafttrivia.command(aliases=["lead", "total"]) + @guild_only() + async def leaderboard(self, ctx: commands.GuildContext): + 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)) + )) diff --git a/minecrafttrivia/utils.py b/minecrafttrivia/utils.py index 8bb4730..89f650d 100644 --- a/minecrafttrivia/utils.py +++ b/minecrafttrivia/utils.py @@ -17,7 +17,7 @@ async def get_participants(reactions: typing.List[discord.Reaction]) -> typing.L def format_leaderboard(points: typing.List[typing.Tuple[int, typing.Tuple[typing.Union[discord.User, int], int]]]) -> str: - return "\n".join(f"**{rank + 1}.** {user.mention if hasattr(user, 'mention') else '<@' + str(user) + '>'} - {points}" for rank, (user, points) in points) + return "\n".join(f"**{rank + 1}.** {user.mention if hasattr(user, 'mention') else '<@' + str(user) + '>'} - {points}" for rank, (user, points) in points[:20]) _T = typing.TypeVar("_T", discord.User, int) |