|
| 1 | +import discord |
| 2 | +from discord.ext import commands |
| 3 | +from discord import app_commands |
| 4 | +from util.state import StateBot |
| 5 | +from util.embeds import Embeds |
| 6 | +from util.views import JudgeView |
| 7 | +from random import shuffle |
| 8 | +from datetime import date, timedelta |
| 9 | + |
| 10 | + |
| 11 | +class Commands(commands.Cog): |
| 12 | + def __init__(self, bot): |
| 13 | + self.bot: StateBot = bot |
| 14 | + self.TOTAL_SUBMISSIONS = 2 |
| 15 | + |
| 16 | + def get_judge(self) -> list[str, str]: |
| 17 | + """Returns the judge for the week |
| 18 | +
|
| 19 | + Returns: |
| 20 | + list[str, str]: the name of the judge, then their id |
| 21 | + """ |
| 22 | + NAMES = ["Souren", "Kevin", "Ken", "Artom", "Andrew"] |
| 23 | + IDS = [ |
| 24 | + "290550631591182336", |
| 25 | + "183383346569543681", |
| 26 | + "290630197458501633", |
| 27 | + "161921661346643968", |
| 28 | + "196069761082327041", |
| 29 | + ] |
| 30 | + start_monday: date = date(2025, 6, 9) |
| 31 | + nearest_monday = date.today() + timedelta((7 - date.today().weekday()) % 7) |
| 32 | + day_delta = nearest_monday - start_monday |
| 33 | + week_delta = day_delta.days // 7 |
| 34 | + return [NAMES[week_delta % len(NAMES)], IDS[week_delta % len(IDS)]] |
| 35 | + |
| 36 | + @app_commands.command(name="submit", description="submit a song to music monday") |
| 37 | + @app_commands.describe(song="The spotify link for the song") |
| 38 | + async def submit_song(self, interaction: discord.Interaction, song: str): |
| 39 | + if song.find("spotify") == -1: |
| 40 | + return await interaction.response.send_message( |
| 41 | + embed=Embeds.error( |
| 42 | + "Link did not contain the word 'spotify', are you sure you submitted a spotify link?" |
| 43 | + ), |
| 44 | + ephemeral=True, |
| 45 | + ) |
| 46 | + |
| 47 | + self.bot.state.add_submission(interaction.user.id, song) |
| 48 | + |
| 49 | + if self.TOTAL_SUBMISSIONS == len(self.bot.state.get_all_submissions()): |
| 50 | + await interaction.channel.send( |
| 51 | + content=f"<@{self.get_judge()[1]}>, all songs have been submitted, you can now judge with `/submissions`" |
| 52 | + ) |
| 53 | + |
| 54 | + return await interaction.response.send_message( |
| 55 | + embed=Embeds.emphasis(title="Submission received", body="Thank you!") |
| 56 | + ) |
| 57 | + |
| 58 | + @app_commands.command( |
| 59 | + name="submissions", |
| 60 | + description="lists submissions blind if 4 have been given, otherwise errors", |
| 61 | + ) |
| 62 | + async def list_submissions(self, interaction: discord.Interaction): |
| 63 | + subs = self.bot.state.get_all_submissions() |
| 64 | + if len(subs) < self.TOTAL_SUBMISSIONS: |
| 65 | + return await interaction.response.send_message( |
| 66 | + embed=Embeds.error( |
| 67 | + f"We aren't at {self.TOTAL_SUBMISSIONS} submissions yet! So far we have {len(subs)}" |
| 68 | + ), |
| 69 | + ephemeral=True, |
| 70 | + ) |
| 71 | + |
| 72 | + word_map = ["one", "two", "three", "four"] |
| 73 | + |
| 74 | + # randomize the order of the songs |
| 75 | + userIds = list(subs.keys()) |
| 76 | + shuffle(userIds) |
| 77 | + |
| 78 | + for [idx, userId] in enumerate(userIds): |
| 79 | + await interaction.channel.send(content=f":{word_map[idx]}: {subs[userId]}") |
| 80 | + return await interaction.response.send_message( |
| 81 | + content="Judge, please vote for your favourite this song this week!", |
| 82 | + view=JudgeView(subs, userIds), |
| 83 | + ) |
| 84 | + |
| 85 | + @app_commands.command(name="reveal", description="Reveals who submitted what song") |
| 86 | + async def reveal_submissions(self, interaction: discord.Interaction): |
| 87 | + subs = self.bot.state.get_all_submissions() |
| 88 | + for userId in subs: |
| 89 | + await interaction.channel.send(f"<@{userId}> {subs[userId]}") |
| 90 | + await interaction.channel.send( |
| 91 | + embed=Embeds.info( |
| 92 | + title="Here is who sent each song", |
| 93 | + body="Congrats on another successful music monday", |
| 94 | + ) |
| 95 | + ) |
| 96 | + |
| 97 | + ## debug commands |
| 98 | + |
| 99 | + @app_commands.command( |
| 100 | + name="clearall", description="clears ALL submissions (debug command)" |
| 101 | + ) |
| 102 | + async def clearall_debug(self, interaction: discord.Interaction): |
| 103 | + return await interaction.response.send_message( |
| 104 | + embed=Embeds.info(title="Removed all submissions", body=":wave:") |
| 105 | + ) |
| 106 | + |
| 107 | + @app_commands.command( |
| 108 | + name="whojudge", description="Who is the judge this week (debugcommand)" |
| 109 | + ) |
| 110 | + async def whojudge_debug(self, interaction: discord.Interaction): |
| 111 | + return await interaction.response.send_message( |
| 112 | + embed=Embeds.info( |
| 113 | + title="The next judge is", body=f"# {self.get_judge()[0]}!" |
| 114 | + ) |
| 115 | + ) |
| 116 | + |
| 117 | + |
| 118 | +async def setup(bot): |
| 119 | + await bot.add_cog(Commands(bot)) |
0 commit comments