Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new command to adjust game uptime. Increase default uptime. #117

Merged
merged 5 commits into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions bot/exts/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Team(enum.Enum):

# The default settings to initialize the cache with.
DEFAULT_SETTINGS: types.MappingProxyType[str, int | float] = types.MappingProxyType({
"reaction_min": 30, "reaction_max": 120, "ducky_probability": 0.25
"reaction_min": 30, "reaction_max": 120, "ducky_probability": 0.25, "game_uptime": 15
})

# Channels where the game runs.
Expand All @@ -59,9 +59,6 @@ class Team(enum.Enum):
# Roles allowed to use the management commands.
ELEVATED_ROLES = (constants.Roles.admins, constants.Roles.moderation_team, constants.Roles.events_lead)

# Time for a reaction to be up, in seconds.
EVENT_UP_TIME = 5

QUACKSTACK_URL = "https://quackstack.pythondiscord.com/duck"


Expand All @@ -85,6 +82,8 @@ def __init__(self, bot: SirRobin):
self.guild = self.bot.get_guild(constants.Bot.guild)
self.team_roles: dict[Team, discord.Role] = {}

self.event_uptime: int = 15

self.team_game_message_id = None
self.team_game_users_already_reacted: set[int] = set()
self.chosen_team = None
Expand Down Expand Up @@ -125,6 +124,7 @@ async def cog_load(self) -> None:
if "team" not in times:
await self.set_reaction_time("team")

self.event_uptime = await self.game_settings.get("game_uptime")
self.super_game.start()

@commands.Cog.listener()
Expand All @@ -148,7 +148,7 @@ async def on_message(self, msg: discord.Message) -> None:
logger.info(f"Starting game in {msg.channel.name} for team {self.chosen_team}")
await msg.add_reaction(self.chosen_team.value.emoji)

await asyncio.sleep(EVENT_UP_TIME)
await asyncio.sleep(self.event_uptime)

await msg.clear_reaction(self.chosen_team.value.emoji)
self.team_game_message_id = self.chosen_team = None
Expand Down Expand Up @@ -273,7 +273,7 @@ async def join(self, ctx: commands.Context) -> None:
@in_whitelist(channels=ALLOWED_COMMAND_CHANNELS, redirect=ALLOWED_COMMAND_CHANNELS)
async def scores(self, ctx: commands.Context) -> None:
"""The current leaderboard of points for each team."""
current_points: list = sorted(await self.points.items(), key=lambda t: t[1])
current_points: list = sorted(await self.points.items(), key=lambda t: t[1], reverse=True)
team_scores = "\n".join(
f"{Team[team_name.upper()].value.emoji} **Team {team_name.capitalize()}**: {points}\n"
for team_name, points in current_points
Expand All @@ -299,6 +299,17 @@ async def off(self, ctx: commands.Context) -> None:
@commands.has_any_role(*ELEVATED_ROLES)
async def set_interval(self, ctx: commands.Context, min_time: int, max_time: int) -> None:
"""Set the minimum and maximum number of seconds between team reactions."""
if min_time > max_time:
await ctx.send("The minimum interval can't be greater than the maximum.")
return

game_uptime = await self.game_settings.get("game_uptime")
if min_time < game_uptime:
await ctx.send(f"Min time can't be less than the game uptime, which is {game_uptime}")
return

logger.info(f"New game intervals set to {min_time}, {max_time} by {ctx.author.name}")

await self.game_settings.set("reaction_min", min_time)
await self.game_settings.set("reaction_max", max_time)
await ctx.message.add_reaction("✅")
Expand All @@ -317,6 +328,24 @@ async def set_probability(self, ctx: commands.Context, probability: float) -> No
await self.game_settings.set("ducky_probability", probability)
await ctx.message.add_reaction("✅")

@games_command_group.command()
@commands.has_any_role(*ELEVATED_ROLES)
async def set_uptime(self, ctx: commands.Context, uptime: int) -> None:
"""Set the number of seconds for which the team game runs."""
if uptime <= 0:
await ctx.send(f"Uptime must be greater than 0, but is {uptime}")
return

current_min = await self.game_settings.get("reaction_min")
if uptime > current_min:
await ctx.send(f"Uptime can't be greater than the minimum interval, which is {current_min}")
return

await self.game_settings.set("game_uptime", uptime)
self.event_uptime = uptime
logger.info(f"game_uptime set to {uptime}s by {ctx.author.name}")
await ctx.message.add_reaction("✅")

@games_command_group.command()
@commands.has_any_role(*ELEVATED_ROLES)
async def status(self, ctx: commands.Context) -> None:
Expand Down
Loading