-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] Kaylee's Cog: Poll #6
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import discord | ||
| import logging | ||
| from discord.ext import commands | ||
| from discord import app_commands | ||
|
|
||
| from frontend import config_colors as colors | ||
| from config import settings | ||
|
|
||
| #change everything with "Ping" | ||
| class KayleeCog(commands.Cog): | ||
| def __init__(self, bot: commands.Bot): | ||
| self.bot = bot | ||
| self.logger = logging.getLogger( | ||
| f"discord.cog.{self.__class__.__name__.lower()}" | ||
| ) | ||
|
|
||
| @app_commands.guilds(discord.Object(id=settings.DEBUG_GUILD_ID)) | ||
| @app_commands.command(name="poll", description="Custom poll with 3 choices") | ||
| async def poll(self, interaction: discord.Interaction, question: str, choice_1: str, choice_2: str, choice_3: str): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Consider adding input validation for the poll fields Currently, empty or duplicate choices can be submitted. Please ensure |
||
| choices = [choice_1, choice_2, choice_3] | ||
| emojis = ["1️⃣", "2️⃣", "3️⃣"] | ||
|
|
||
| #description string creation | ||
| descriptions = [] | ||
| for i in range(3): | ||
| descrip = emojis[i] + " " + choices[i] | ||
| descriptions.append(descrip) | ||
| message = "\n".join(descriptions) #combine all into one string | ||
|
|
||
|
|
||
| #description embed | ||
| embed = discord.Embed( | ||
| title = "Poll: " + question, | ||
| description = message, | ||
| #color = colors.POLL, #couldn't get it to work :( gave me errors | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Remove or properly re-enable the commented-out color Uncomment and fix if Suggested implementation: embed = discord.Embed(
title = "Poll: " + question,
description = message,
color = colors.POLL,
)If
|
||
| ) | ||
|
Comment on lines
+26
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Use f-string instead of string concatenation [×3] ( |
||
| self.logger.info(message) #logs message | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Include more context in the log entry Logging only the options string may not provide enough information for debugging. Log the question and choices for better context. Suggested implementation: self.logger.info(
"Poll created | Question: %r | Choices: %r | Message: %r",
question,
choices if 'choices' in locals() else 'N/A',
message
) #logs messageIf the variable |
||
| await interaction.response.send_message(embed=embed) #replies to command with the embed | ||
|
|
||
| #adding emoji reactions for voting | ||
| msg = await interaction.original_response() #get the reply message | ||
| for i in range(3): | ||
| await msg.add_reaction(emojis[i]) #reacts to that msg with each emoji | ||
|
|
||
|
|
||
| async def setup(bot: commands.Bot): | ||
| await bot.add_cog(KayleeCog(bot)) | ||
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.
suggestion: Remove or clarify the leftover comment
The
#change everything with "Ping"comment appears to be an outdated TODO. Please remove it or update it to reflect the current intent.