countdown-bot

A Discord bot that runs countdown games and generates analytics
git clone https://git.ashermorgan.net/countdown-bot/
Log | Files | Refs | README

commit d4707de848c55697a7d97e50ac85bfd16f1af7ec
parent ca4216078cd19c0e434b654f846ab852d814dac5
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Sat, 27 Apr 2024 19:34:42 -0700

Remove support for multiple default prefixes

Diffstat:
Mcountdown_bot/__main__.py | 2+-
Mcountdown_bot/bot.py | 6+++---
Mcountdown_bot/botUtilities.py | 6+++---
Mcountdown_bot/coreCog.py | 2+-
Mcountdown_bot/helpCog.py | 11+++++++----
5 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/countdown_bot/__main__.py b/countdown_bot/__main__.py @@ -23,5 +23,5 @@ logging.basicConfig( db_connection = psycopg.connect(os.environ.get("DATABASE"), row_factory=psycopg.rows.dict_row) # Run bot -bot = CountdownBot(db_connection, [os.environ.get("PREFIX", "!")]) +bot = CountdownBot(db_connection, os.environ.get("PREFIX", "!")) bot.run(os.environ.get("TOKEN")) diff --git a/countdown_bot/bot.py b/countdown_bot/bot.py @@ -11,10 +11,10 @@ from .botUtilities import addMessage, COLORS, CountdownNotFound, ContributorNotF class CountdownBot(commands.Bot): - def __init__(self, db_connection, prefixes): + def __init__(self, db_connection, prefix): # Set properties self.db_connection = db_connection - self.prefixes = prefixes + self.prefix = prefix self.logger = logging.getLogger(__name__) # Get intents @@ -22,7 +22,7 @@ class CountdownBot(commands.Bot): intents.message_content = True # Initialize bot - super().__init__(command_prefix=lambda bot, ctx: getPrefix(self.db_connection, ctx, self.prefixes), intents=intents) + super().__init__(command_prefix=lambda bot, ctx: getPrefix(self.db_connection, ctx, self.prefix), intents=intents) diff --git a/countdown_bot/botUtilities.py b/countdown_bot/botUtilities.py @@ -158,15 +158,15 @@ def getPrefix(conn, ctx, default): The database connection ctx : discord.ext.commands.Context The context - default : list - The default prefixes + default : string + The default prefix """ with conn.cursor() as cur: cur.execute("SELECT * FROM getServerPrefixes(%s, %s);", (ctx.channel.guild.id if ctx.channel.guild else None, ctx.channel.id)) prefixes = cur.fetchall() - return [x["prefix"] for x in prefixes] if prefixes else default + return [x["prefix"] for x in prefixes] if prefixes else [default] diff --git a/countdown_bot/coreCog.py b/countdown_bot/coreCog.py @@ -45,7 +45,7 @@ class Core(commands.Cog): # Create countdown cur.execute("CALL createCountdown(%s, %s, %s);", - (ctx.channel.id, ctx.channel.guild.id, self.bot.prefixes[0])) + (ctx.channel.id, ctx.channel.guild.id, self.bot.prefix)) # Send initial response self.bot.logger.info(f"Activated {self.bot.get_channel(ctx.channel.id)} (ID {ctx.channel.id}) as a countdown") diff --git a/countdown_bot/helpCog.py b/countdown_bot/helpCog.py @@ -19,13 +19,16 @@ class Help(commands.Cog): # Log status self.logger.info(f"Added to {guild} (ID {guild.id})") + # Get command prefix + prefix = self.bot.prefixes[0] + # Create embed embed=discord.Embed(title=":rocket: Getting Started with countdown-bot", color=COLORS["embed"]) embed.description = f"Thanks for adding me to your server! Here are some steps for getting started:\n" - embed.description += f"**1.** View help information using the `{self.bot.prefixes[0]}help` command\n" - embed.description += f"**2.** Activate a new countdown channel using the `{self.bot.prefixes[0]}activate` command\n" - embed.description += f"**3.** Change my settings using the `{self.bot.prefixes[0]}config` command\n" - embed.description += f"**4.** View countdown analytics using the `{self.bot.prefixes[0]}analytics` command\n" + embed.description += f"**1.** View help information using the `{prefix}help` command\n" + embed.description += f"**2.** Activate a new countdown channel using the `{prefix}activate` command\n" + embed.description += f"**3.** Change my settings using the `{prefix}config` command\n" + embed.description += f"**4.** View countdown analytics using the `{prefix}analytics` command\n" # Send embed await ctx.guild.system_channel.send(embed=embed)