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 47e05c4ef6442a40811da957dc13df35a63a25d3
parent 85ac4589e4c73f07c6f6eeb2319a20b015c3a093
Author: ashermorgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Sat, 10 Jul 2021 15:19:42 -0700

Make command prefixes case insensitive

Diffstat:
Msrc/bot.py | 6+++++-
Msrc/botUtilities.py | 6+++---
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/bot.py b/src/bot.py @@ -14,7 +14,7 @@ from src.models import getSessionMaker, EmptyCountdownError class CountdownBot(commands.Bot): def __init__(self, databaseLocation, prefixes=["c."]): # Initialize bot - commands.Bot.__init__(self, command_prefix=lambda bot, ctx: getPrefix(self.databaseSessionMaker, ctx, self.prefixes), case_insensitive=True) + commands.Bot.__init__(self, command_prefix=lambda bot, ctx: getPrefix(self.databaseSessionMaker, ctx, self.prefixes)) # Set properties self.databaseSessionMaker = getSessionMaker(databaseLocation) @@ -63,6 +63,10 @@ class CountdownBot(commands.Bot): # Run commands try: + # Make command prefixes, names, and arguments case insensitive + obj.content = obj.content.lower() + + # Execute command await self.process_commands(obj) except: pass diff --git a/src/botUtilities.py b/src/botUtilities.py @@ -206,7 +206,7 @@ def getPrefix(databaseSessionMaker, ctx, default): # Countdown channel countdown = getCountdown(session, ctx.channel.id) if (countdown and len(countdown.prefixes) > 0): - return [x.value for x in countdown.prefixes] + return [x.value.lower() for x in countdown.prefixes] # Server with countdown channels if (isinstance(ctx.channel, discord.channel.TextChannel)): @@ -214,12 +214,12 @@ def getPrefix(databaseSessionMaker, ctx, default): # Get list of prefixes prefixes = [] for countdown in serverCountdowns: - prefixes += [x.value for x in countdown.prefixes] + prefixes += [x.value.lower() for x in countdown.prefixes] if (len(prefixes) > 0): return list(dict.fromkeys(prefixes)) # Return default prefixes - return default + return [x.lower() for x in default]