Skip to content

add new admin secret santa commands#37

Merged
johnvictorfs merged 4 commits into
masterfrom
update-admin-secret-santa-commands
Dec 8, 2025
Merged

add new admin secret santa commands#37
johnvictorfs merged 4 commits into
masterfrom
update-admin-secret-santa-commands

Conversation

@johnvictorfs

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds new admin commands for managing the Secret Santa (Amigo Secreto) feature, including automated assignment of participants and changing authorization from owner-only to admin-accessible commands.

  • Changed command authorization from @commands.is_owner() to @commands.check(is_admin) to allow admin users to execute commands
  • Added roll_amigo_secreto command to automatically assign Secret Santa participants with retry logic
  • Implemented helper methods clear_secret_santa(), roll_secret_santa(), and random_person_to() for managing assignments

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bot/cogs/amigosecreto.py
Comment on lines +128 to +129
receiving=False
).filter(

Copilot AI Dec 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter receiving=False is redundant on line 127 since it's already applied again in line 130. You can simplify this by removing the first .filter(receiving=False) and using just:

random_person: AmigoSecretoPerson = AmigoSecretoPerson.objects.filter(
    Q(receiving=False) & ~Q(id=pk) & ~Q(id__in=exclude)
).order_by('?').first()
Suggested change
receiving=False
).filter(

Copilot uses AI. Check for mistakes.
Comment thread bot/cogs/amigosecreto.py
Comment on lines +133 to +135
random_person.receiving = True
random_person.save()

Copilot AI Dec 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query result could be None if no valid person is found (e.g., in edge cases or when the last person to be assigned has no valid recipient). Attempting to set random_person.receiving = True on line 133 will raise an AttributeError. You should add a null check and handle this error case appropriately:

random_person = AmigoSecretoPerson.objects.filter(...).first()
if not random_person:
    raise Exception("No valid recipient found for Secret Santa assignment")
random_person.receiving = True
random_person.save()
Suggested change
random_person.receiving = True
random_person.save()
if not random_person:
raise Exception("No valid recipient found for Secret Santa assignment")
random_person.receiving = True
random_person.save()

Copilot uses AI. Check for mistakes.
Comment thread bot/cogs/amigosecreto.py Outdated
Comment on lines +161 to +162
except Exception:
attempts += 1

Copilot AI Dec 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bare except Exception catches all exceptions without logging or understanding what went wrong. This makes debugging difficult. Consider at least logging the exception or catching more specific exceptions:

except Exception as e:
    attempts += 1
    self.bot.logger.error(f"Error rolling secret santa: {e}")
    await ctx.author.send('Erro ao montar Amigo Secreto, limpando e tentando novamente')
    self.clear_secret_santa()
Suggested change
except Exception:
attempts += 1
except Exception as e:
attempts += 1
self.bot.logger.error(f"Error rolling secret santa: {e}", exc_info=True)

Copilot uses AI. Check for mistakes.
Comment thread bot/cogs/amigosecreto.py
@commands.check(is_admin)
@commands.command()
async def roll_amigo_secreto(self, ctx: Context):
secret_santa_state: AmigoSecretoState = AmigoSecretoState.object()

Copilot AI Dec 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent method call: AmigoSecretoState.object() is called here, but elsewhere in the same file (lines 76, 177, 190) AmigoSecretoState.objects.first() is used. The method should be consistent throughout the file. Based on the pattern used in admin.py (line 512), .object() appears to be a custom method, but you should verify this is the correct method to use.

Suggested change
secret_santa_state: AmigoSecretoState = AmigoSecretoState.object()
secret_santa_state: AmigoSecretoState = AmigoSecretoState.objects.first()

Copilot uses AI. Check for mistakes.
Comment thread bot/cogs/amigosecreto.py Outdated
for person in AmigoSecretoPerson.objects.filter(giving_to_user=None).all():
random = self.random_person_to(person.id, exclude)

self.logger.info(person.user.ingame_name + ' is giving to ' + random.user.ingame_name)

Copilot AI Dec 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.logger is not defined in this class. The AmigoSecreto class does not initialize a logger in its __init__ method. You need to either:

  1. Add self.logger = logging.getLogger("amigosecreto") in the __init__ method, or
  2. Use the bot's logger, or
  3. Remove this logging statement

Other cogs in the codebase (e.g., authentication.py, error_handler.py) initialize their loggers in __init__.

Copilot uses AI. Check for mistakes.
Comment thread bot/cogs/amigosecreto.py Outdated
Comment on lines +110 to +116
random = self.random_person_to(person.id, exclude)

self.logger.info(person.user.ingame_name + ' is giving to ' + random.user.ingame_name)

person.giving_to_user = random.user
person.save()
exclude.append(random.id)

Copilot AI Dec 8, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name random shadows the built-in Python module name. Consider renaming it to something more descriptive like random_recipient or target_person.

Suggested change
random = self.random_person_to(person.id, exclude)
self.logger.info(person.user.ingame_name + ' is giving to ' + random.user.ingame_name)
person.giving_to_user = random.user
person.save()
exclude.append(random.id)
random_recipient = self.random_person_to(person.id, exclude)
self.logger.info(person.user.ingame_name + ' is giving to ' + random_recipient.user.ingame_name)
person.giving_to_user = random_recipient.user
person.save()
exclude.append(random_recipient.id)

Copilot uses AI. Check for mistakes.
@johnvictorfs
johnvictorfs merged commit e152cfb into master Dec 8, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants