Skip to content

Commit

Permalink
Added megarace boost ping, cache stores 10 minutes again, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MirielCH committed Aug 14, 2024
1 parent 624373f commit 177c287
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 23 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.1 (12 Aug 2024)
3.1.2 (14 Aug 2024)
11 changes: 1 addition & 10 deletions cogs/cooldowns.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async def on_message(self, message: discord.Message) -> None:
cooldowns.append(['card-hand', card_hand_timestring.lower(), card_hand_message])
else:
ready_commands.append('card-hand')
if user_settings.alert_hunt.enabled:
if user_settings.alert_hunt.enabled and not user_settings.hunt_reminders_combined:
hunt_match = re.search(r'hunt(?: hardmode)?`\*\* \(\*\*(.+?)\*\*', message_fields.lower())
if hunt_match:
user_command = await functions.get_slash_command(user_settings, 'hunt')
Expand All @@ -186,15 +186,6 @@ async def on_message(self, message: discord.Message) -> None:
else:
user_command = f"{user_command} `hardmode`".replace('` `', ' ')
hunt_timestring = hunt_match.group(1)
if ('together' in user_settings.last_hunt_mode
and user_settings.partner_donor_tier < user_settings.user_donor_tier):
time_left = await functions.parse_timestring_to_timedelta(hunt_timestring.lower())
partner_donor_tier = 3 if user_settings.partner_donor_tier > 3 else user_settings.partner_donor_tier
user_donor_tier = 3 if user_settings.user_donor_tier > 3 else user_settings.user_donor_tier
time_difference = ((60 * settings.DONOR_COOLDOWNS[partner_donor_tier])
- (60 * settings.DONOR_COOLDOWNS[user_donor_tier]))
time_left_seconds = time_left.total_seconds() + time_difference
hunt_timestring = await functions.parse_timedelta_to_timestring(timedelta(seconds=time_left_seconds))
hunt_message = user_settings.alert_hunt.message.replace('{command}', user_command)
cooldowns.append(['hunt', hunt_timestring.lower(), hunt_message])
else:
Expand Down
64 changes: 61 additions & 3 deletions cogs/horse_festival.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,14 @@ async def on_message(self, message: discord.Message) -> None:
user_name_match = re.search(regex.NAME_FROM_MESSAGE_START, message_field0_name)
if not user_name_match:
await functions.add_warning_reaction(message)
await errors.log_error('User not found in megarace boost message.', message)
await errors.log_error('User not found in megarace boost done message.', message)
return
user_name = user_name_match.group(1)
guild_users = await functions.get_guild_member_by_name(message.guild, user_name)
if not guild_users: return
if len(guild_users) > 1:
await functions.add_warning_reaction(message)
await errors.log_error(f'User {user_name} not unique in megarace boost message. Found {guild_users}.', message)
await errors.log_error(f'User {user_name} not unique in megarace boost done message. Found {guild_users}.', message)
return
user = guild_users[0]
try:
Expand All @@ -409,7 +409,7 @@ async def on_message(self, message: discord.Message) -> None:
timestring_match = await functions.get_match_from_patterns(search_patterns, message_field0_value.lower())
if not timestring_match:
await functions.add_warning_reaction(message)
await errors.log_error('Timestring not found in megarace boost message.', message)
await errors.log_error('Timestring not found in megarace boost done message.', message)
return
time_left = await functions.calculate_time_left_from_timestring(message, timestring_match.group(1))
try:
Expand All @@ -431,6 +431,64 @@ async def on_message(self, message: discord.Message) -> None:
await reminder.update(end_time=new_end_time)
await functions.add_reminder_reaction(message, reminder, user_settings)

search_strings = [
'megaraceboost',
]
if any(search_string in message_field0_name.lower() for search_string in search_strings):
user_id = user_name = None
user = await functions.get_interaction_user(message)
if user is None:
user_name_match = re.search(regex.NAME_FROM_MESSAGE_START, message_field0_name)
if not user_name_match:
await functions.add_warning_reaction(message)
await errors.log_error('User not found in megarace boost message.', message)
return
user_name = user_name_match.group(1)
user_command_message = (
await messages.find_message(message.channel.id, user_name=user_name)
)
if user_command_message is None:
await functions.add_warning_reaction(message)
await errors.log_error('Couldn\'t find a user command for the megarace boost message.', message)
return
user = user_command_message.author
try:
user_settings: users.User = await users.get_user(user.id)
except exceptions.FirstTimeUserError:
return
if not user_settings.bot_enabled or not user_settings.megarace_helper_enabled: return
answer = f'Hey! A **megarace boost** just appeared!'
answer = f'{answer} {user.mention}' if user_settings.ping_after_message else f'{user.mention} {answer}'
await message.channel.send(answer)

search_strings = [
'did not pass through the boost',
]
if any(search_string in message_field0_name.lower() for search_string in search_strings):
user_id = user_name = None
user = await functions.get_interaction_user(message)
if user is None:
user_name_match = re.search(regex.NAME_FROM_MESSAGE_START, message_field0_name)
if not user_name_match:
await functions.add_warning_reaction(message)
await errors.log_error('User not found in megarace boost missed message.', message)
return
user_name = user_name_match.group(1)
user_command_message = (
await messages.find_message(message.channel.id, user_name=user_name)
)
if user_command_message is None:
await functions.add_warning_reaction(message)
await errors.log_error('Couldn\'t find a user command for the megarace boost missed message.', message)
return
user = user_command_message.author
try:
user_settings: users.User = await users.get_user(user.id)
except exceptions.FirstTimeUserError:
return
if not user_settings.bot_enabled or not user_settings.reactions_enabled: return
await message.add_reaction(emojis.PEPE_LAUGH)

# Megarace helper
if '— megarace' in message_author.lower():
user_name = user_id = None
Expand Down
7 changes: 0 additions & 7 deletions cogs/hunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ async def on_message(self, message: discord.Message) -> None:
return
except exceptions.NoDataFoundError:
pass
else:
try:
hunt_partner_reminder = await reminders.get_user_reminder(interaction_user.id, 'hunt-partner')
except exceptions.NoDataFoundError:
hunt_partner_reminder = None
if hunt_partner_reminder:
time_left = max(time_left, hunt_partner_reminder.end_time - utils.utcnow())
if time_left < timedelta(0): return
time_left_seconds = time_left.total_seconds()
time_left = timedelta(seconds=ceil(time_left_seconds))
Expand Down
4 changes: 2 additions & 2 deletions cogs/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ async def reset_trade_daily_done(self) -> None:
for user_settings in all_user_settings:
if user_settings.trade_daily_done != 0: await user_settings.update(trade_daily_done=0)

@tasks.loop(minutes=5)
@tasks.loop(minutes=10)
async def delete_old_messages_from_cache(self) -> None:
"""Task that deletes messages from the message cache that are older than 5 minutes"""
"""Task that deletes messages from the message cache that are older than 10 minutes"""
deleted_messages_count = await messages.delete_old_messages(timedelta(minutes=5))
if settings.DEBUG_MODE:
logs.logger.debug(f'Deleted {deleted_messages_count} messages from message cache.')
Expand Down
1 change: 1 addition & 0 deletions cogs/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ async def on_message(self, message: discord.Message) -> None:
'chocolate box', #All languages, artifacts
'bunny mask', #All languages, artifacts
'cowboy boots', #All languages, artifacts
'`boost`', #All languages, boost from party popper
]
search_strings = [
'** got ', #English
Expand Down
1 change: 1 addition & 0 deletions content/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ async def embed_settings_helpers(bot: bridge.AutoShardedBot, ctx: discord.Applic
seasonal_helpers = (
f'{emojis.BP} **Megarace Helper**: {await functions.bool_to_text(user_settings.megarace_helper_enabled)}\n'
f'{emojis.DETAIL} _Provides the optimal answers for the horse festival megarace._\n'
f'{emojis.DETAIL} _Pings you when a megarace boost appears._\n'
f'{emojis.BP} **Pumpkin bat helper**: '
f'{await functions.bool_to_text(user_settings.halloween_helper_enabled)}\n'
f'{emojis.DETAIL} _Provides the answers for the halloween boss._\n'
Expand Down

0 comments on commit 177c287

Please sign in to comment.