-
Notifications
You must be signed in to change notification settings - Fork 5
add new admin secret santa commands #37
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,17 +5,17 @@ | |||||||||||||||
|
|
||||||||||||||||
| from bot.bot_client import Bot | ||||||||||||||||
| from bot.utils.tools import has_any_role, format_and_convert_date | ||||||||||||||||
| from bot.utils.checks import is_authenticated | ||||||||||||||||
| from bot.utils.checks import is_authenticated, is_pedim_or_nriver | ||||||||||||||||
| from bot.utils.context import Context | ||||||||||||||||
|
|
||||||||||||||||
| from atlantisbot_api.models import AmigoSecretoState, AmigoSecretoPerson | ||||||||||||||||
|
|
||||||||||||||||
| from django.db.models import Q | ||||||||||||||||
|
|
||||||||||||||||
| class AmigoSecreto(commands.Cog): | ||||||||||||||||
| def __init__(self, bot: Bot): | ||||||||||||||||
| self.bot = bot | ||||||||||||||||
|
|
||||||||||||||||
| @commands.is_owner() | ||||||||||||||||
| @commands.check(is_pedim_or_nriver) | ||||||||||||||||
| @commands.command() | ||||||||||||||||
| async def send_amigo_secreto_messages(self, ctx: Context, test: bool = True): | ||||||||||||||||
| query = AmigoSecretoPerson.objects.all() | ||||||||||||||||
|
|
@@ -25,7 +25,7 @@ async def send_amigo_secreto_messages(self, ctx: Context, test: bool = True): | |||||||||||||||
| "Não há nenhuma mensagem de Amigo Secreto para enviar." | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| dev = self.bot.get_user(self.bot.setting.developer_id) | ||||||||||||||||
| dev = ctx.author | ||||||||||||||||
|
|
||||||||||||||||
| if test: | ||||||||||||||||
| await dev.send("Enviando Mensagens do Amigo Secreto em Modo de Teste") | ||||||||||||||||
|
|
@@ -97,8 +97,82 @@ async def send_amigo_secreto_messages(self, ctx: Context, test: bool = True): | |||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| return await ctx.send("Todas as mensagens foram enviadas.") | ||||||||||||||||
|
|
||||||||||||||||
| @staticmethod | ||||||||||||||||
| def clear_secret_santa(): | ||||||||||||||||
| AmigoSecretoPerson.objects.all().update(receiving=False, giving_to_user=None) | ||||||||||||||||
|
|
||||||||||||||||
| def roll_secret_santa(self): | ||||||||||||||||
| exclude: list[int] = [] | ||||||||||||||||
|
|
||||||||||||||||
| person: AmigoSecretoPerson | ||||||||||||||||
| for person in AmigoSecretoPerson.objects.filter(giving_to_user=None).all(): | ||||||||||||||||
| random_recipient = self.random_person_to(person.id, exclude) | ||||||||||||||||
|
|
||||||||||||||||
| self.bot.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) | ||||||||||||||||
|
|
||||||||||||||||
| for person_id in exclude: | ||||||||||||||||
| AmigoSecretoPerson.objects.filter(id=person_id).update(receiving=True) | ||||||||||||||||
|
|
||||||||||||||||
| @staticmethod | ||||||||||||||||
| def random_person_to(pk: int, exclude: list[int]) -> AmigoSecretoPerson: | ||||||||||||||||
| """ | ||||||||||||||||
| Get random entry for Secret Santa, excluding people already receiving presents and the person giving himself | ||||||||||||||||
| """ | ||||||||||||||||
|
|
||||||||||||||||
| random_person: AmigoSecretoPerson = AmigoSecretoPerson.objects.filter( | ||||||||||||||||
| receiving=False | ||||||||||||||||
| ).filter( | ||||||||||||||||
| Q(receiving=False) & ~Q(id=pk) & ~Q(id__in=exclude) | ||||||||||||||||
| ).order_by('?').first() | ||||||||||||||||
|
|
||||||||||||||||
| random_person.receiving = True | ||||||||||||||||
| random_person.save() | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+133
to
+135
|
||||||||||||||||
| 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
AI
Dec 8, 2025
There was a problem hiding this comment.
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.
| secret_santa_state: AmigoSecretoState = AmigoSecretoState.object() | |
| secret_santa_state: AmigoSecretoState = AmigoSecretoState.objects.first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter
receiving=Falseis 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: