Skip to content

Commit

Permalink
Grant XP On Scheduled Event *Start* (#581)
Browse files Browse the repository at this point in the history
* award xp when events *start*, misc bug fixes

* cleanup
  • Loading branch information
zmattingly authored Jan 23, 2025
1 parent 867626e commit 5161e11
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 27 deletions.
4 changes: 2 additions & 2 deletions charts/agimus/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: agimus
description: A helm chart for a discord bot that also runs a mysql db
type: application
version: v2.12.15
appVersion: v2.12.15
version: v2.12.16
appVersion: v2.12.16
47 changes: 32 additions & 15 deletions cogs/wishlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ async def handle_wishlist_reaction_toggle(self, payload):
user_badge_names = [b['badge_name'] for b in await db_get_user_badges(payload.user_id)]
user_wishlist_badge_names = [b['badge_name'] for b in await db_get_user_wishlist_badges(payload.user_id)]
user_locked_badge_names = [b['badge_name'] for b in await db_get_user_locked_badges(payload.user_id)]
special_badge_names = [b['badge_name'] for b in await db_get_special_badges()]

if payload.event_type == "REACTION_ADD" and badge_name not in user_badge_names and badge_name not in user_wishlist_badge_names:
if payload.event_type == "REACTION_ADD" and badge_name not in user_badge_names and badge_name not in user_wishlist_badge_names and badge_name not in special_badge_names:
logger.info(f"Adding {Style.BRIGHT}{badge_name}{Style.RESET_ALL} to {Style.BRIGHT}{member.display_name}'s wishlist{Style.RESET_ALL} via react")
await db_add_badge_name_to_users_wishlist(member.id, badge_name)
if user["receive_notifications"]:
Expand All @@ -218,7 +219,7 @@ async def handle_wishlist_reaction_toggle(self, payload):
logger.info(f"Unable to send wishlist add react confirmation message to {member.display_name}, they have their DMs closed.")
pass

if payload.event_type == "REACTION_ADD" and badge_name in user_badge_names and badge_name not in user_locked_badge_names:
if payload.event_type == "REACTION_ADD" and badge_name in user_badge_names and badge_name not in user_locked_badge_names and badge_name not in special_badge_names:
logger.info(f"Locking {Style.BRIGHT}{badge_name}{Style.RESET_ALL} in {Style.BRIGHT}{member.display_name}'s inventory{Style.RESET_ALL} via react")
badge_info = await db_get_badge_info_by_name(badge_name)
badge_filename = badge_info['badge_filename']
Expand Down Expand Up @@ -398,7 +399,10 @@ async def matches(self, ctx:discord.ApplicationContext):
# In this case, keep track and if so display a different result message at the bottom
all_dismissed = True

if len(exact_matches_aggregate.keys()):
match_count = len(exact_matches_aggregate.keys())

if match_count:
dismissal_count = 0
for user_id in exact_matches_aggregate.keys():
user = await bot.current_guild.fetch_member(user_id)

Expand All @@ -416,6 +420,7 @@ async def matches(self, ctx:discord.ApplicationContext):
dismissal_has = json.loads(dismissal.get('has'))
dismissal_wants = json.loads(dismissal.get('wants'))
if has_badges_names == dismissal_has and wants_badges_names == dismissal_wants:
dismissal_count = dismissal_count + 1
continue
else:
await db_delete_wishlist_dismissal(author_discord_id, user_id)
Expand Down Expand Up @@ -496,26 +501,26 @@ async def matches(self, ctx:discord.ApplicationContext):
)
await paginator.respond(ctx.interaction, ephemeral=True)

all_dismissed = False
all_dismissed = match_count == dismissal_count
else:
await acknowledgement_followup.edit(
embed=discord.Embed(
title="Wishlist Matches Listed!",
description="BEHOLD!",
title="No Wishlist Matches Found",
description="Please check back later!",
color=discord.Color.blurple()
)
)
return

else:
if not all_dismissed:
await acknowledgement_followup.edit(
embed=discord.Embed(
title="No Wishlist Matches Found",
description="Please check back later!",
title="Wishlist Matches Listed!",
description="BEHOLD!",
color=discord.Color.blurple()
)
)
return

if all_dismissed:
else:
await acknowledgement_followup.edit(
embed=discord.Embed(
title="All Wishlist Matches Dismissed",
Expand Down Expand Up @@ -887,13 +892,24 @@ async def add(self, ctx:discord.ApplicationContext, badge:str):
)
return

special_badge_names = [b['badge_name'] for b in await db_get_special_badges()]
if badge in special_badge_names:
await ctx.followup.send(
embed=discord.Embed(
title="Invalid Badge Selection!",
description=f"Unable to complete your request, **{badge}** is a ✨ *special badge* ✨ and cannot be acquired via trading!",
color=discord.Color.red()
)
)
return

# Check to make sure the badge is not already present in their wishlist
existing_wishlist_badges = [b['badge_name'] for b in await db_get_user_wishlist_badges(user_discord_id)]
if badge in existing_wishlist_badges:
await ctx.followup.send(
embed=discord.Embed(
title="Badge Already Present in Wishlist!",
description=f"Unable to complete your request, {badge} is already present in your Wishlist.",
description=f"Unable to complete your request, **{badge}** is already present in your Wishlist.",
color=discord.Color.red()
)
)
Expand All @@ -905,7 +921,7 @@ async def add(self, ctx:discord.ApplicationContext, badge:str):
await ctx.followup.send(
embed=discord.Embed(
title="Badge Already Present in Inventory!",
description=f"Unable to complete your request, {badge} is already present in your Inventory. No need to wish for it!",
description=f"Unable to complete your request, **{badge}** is already present in your Inventory. No need to wish for it!",
color=discord.Color.red()
)
)
Expand Down Expand Up @@ -1001,9 +1017,10 @@ async def add_set(self, ctx:discord.ApplicationContext, category:str, selection:

existing_user_badges = [b['badge_filename'] for b in await db_get_user_badges(user_discord_id)]
existing_wishlist_badges = [b['badge_filename'] for b in await db_get_user_wishlist_badges(user_discord_id)]
special_badges = [b['badge_filename'] for b in await db_get_special_badges()]

# Filter out those badges that are already present in the Wishlist and user's Inventory
valid_badges = [b['badge_filename'] for b in all_set_badges if b['badge_filename'] not in existing_user_badges and b['badge_filename'] not in existing_wishlist_badges]
valid_badges = [b['badge_filename'] for b in all_set_badges if b['badge_filename'] not in existing_user_badges and b['badge_filename'] not in existing_wishlist_badges and b['badge_filename'] not in special_badges]

# If there are no badges to add, error to user
if not valid_badges:
Expand Down
18 changes: 13 additions & 5 deletions commands/speak.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from common import *

from utils.check_role_access import role_check

@bot.slash_command(
name="speak",
Expand Down Expand Up @@ -30,7 +30,7 @@
description="Send to a channel besides AGIMUS' speaker?",
required=False
)
@commands.has_role(config["roles"]["agimus_maintainers"])
@commands.check(role_check)
async def speak(ctx:discord.ApplicationContext, content:str, dry_run:str, channel:discord.TextChannel):
"""
make agimus talk!
Expand All @@ -39,15 +39,23 @@ async def speak(ctx:discord.ApplicationContext, content:str, dry_run:str, channe
content = content.replace("<br>", "\n")
dry_run = bool(dry_run == "yes")
if not channel:
# default to announcement channel
channel = bot.get_channel(get_channel_id(config["agimus_announcement_channel"]))
# default to current channel
channel = ctx.channel
if dry_run:
await ctx.respond(content, ephemeral=dry_run)
else:
await channel.send(content)
await ctx.respond(f"Your message has been sent to {channel.mention}!", ephemeral=True)
await ctx.respond(
embed=discord.Embed(
title="AGIMUS HAS SPOKEN!",
description=f"Your message has been sent to {channel.mention}!",
color=discord.Color.red()
),
ephemeral=True
)
except Exception as e:
logger.info(f"Something went wrong with /speak!")
logger.info(traceback.format_exc())

@speak.error
async def speak_error(ctx, error):
Expand Down
15 changes: 14 additions & 1 deletion configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,15 @@
"data": null,
"parameters": []
},
"speak": {
"allowed_roles": [
"Admiral",
"Captain"
],
"enabled": true,
"data": null,
"parameters": []
},
"spongebob": {
"blocked_channels": [
"neelixs-morale-office",
Expand Down Expand Up @@ -751,7 +760,11 @@
"sub_rosa reset": {
"allowed_roles": [
"Admiral",
"Captain"
"Captain",
"Commander",
"Lt. Commander",
"Lieutenant",
"Ensign"
],
"enabled": true,
"data": null,
Expand Down
2 changes: 1 addition & 1 deletion handlers/xp.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async def handle_event_creation_xp(event):
if type(location) == str:
# Users might create an event that isn't a VoiceChannel
return
await increment_user_xp(creator, 30, "created_event", location, event)
await increment_user_xp(creator, 45, "created_event", location, event)

# calculate_xp_for_next_level(current_level)
# current_level[required]: int
Expand Down
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ async def on_raw_reaction_add(payload):
if payload.event_type == "REACTION_ADD":
await handle_starboard_reactions(payload)

# listen to event creations (streams, pub trivia, etc)
# listen to sceheduled event updates (streams, pub trivia, etc)
@bot.event
async def on_scheduled_event_create(event):
await handle_event_creation_xp(event)
async def on_scheduled_event_update(before: discord.ScheduledEvent, after: discord.ScheduledEvent):
# Only award XP when the event starts
if before.status != after.status and after.status == discord.ScheduledEventStatus.active:
await handle_event_creation_xp(after)

# listen to server join/leave events
@bot.event
Expand Down

0 comments on commit 5161e11

Please sign in to comment.