diff --git a/ccrole/ccrole.py b/ccrole/ccrole.py index d2e4fc1..b07897b 100644 --- a/ccrole/ccrole.py +++ b/ccrole/ccrole.py @@ -1,14 +1,11 @@ import asyncio -import json import re -from typing import Any import discord from discord.ext.commands.view import StringView -from redbot.core import Config, checks -from redbot.core import commands +from redbot.core import Config, checks, commands from redbot.core.bot import Red -from redbot.core.utils.chat_formatting import pagify, box +from redbot.core.utils.chat_formatting import box, pagify class CCRole(commands.Cog): @@ -236,10 +233,30 @@ class CCRole(commands.Cog): await ctx.send("Command list DM'd") @commands.Cog.listener() - async def on_command_error(self, ctx: commands.Context, exception): + async def on_message_without_command(self, message: discord.Message): + + """Filtering credit to redbot.cogs.customcom's listener""" + ########### + is_private = isinstance(message.channel, discord.abc.PrivateChannel) + + # user_allowed check, will be replaced with self.bot.user_allowed or + # something similar once it's added + user_allowed = True + + if len(message.content) < 2 or is_private or not user_allowed or message.author.bot: + return + + ctx = await self.bot.get_context(message) + + if ctx.prefix is None: + return + ########### + # Thank you Cog-Creators + cmd = ctx.invoked_with + cmd = cmd.lower() # Continues the proud case_insentivity tradition of ccrole guild = ctx.guild - message = ctx.message + # message = ctx.message # Unneeded since switch to `on_message_without_command` from `on_command_error` cmdlist = self.config.guild(guild).cmdlist # cmd = message.content[len(prefix) :].split()[0].lower() diff --git a/tts/tts.py b/tts/tts.py index 02f8b8e..e00bfa7 100644 --- a/tts/tts.py +++ b/tts/tts.py @@ -12,7 +12,8 @@ class TTS(Cog): Send Text-to-Speech messages """ - def __init__(self, bot: Red): + def __init__(self, bot: Red, *args, **kwargs): + super().__init__(*args, **kwargs) self.bot = bot self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True) @@ -28,6 +29,7 @@ class TTS(Cog): Send Text to speech messages as an mp3 """ mp3_fp = io.BytesIO() - tts = gTTS(text, "en") + tts = gTTS(text, lang="en") tts.write_to_fp(mp3_fp) - await ctx.send(file=discord.File(mp3_fp.getvalue(), "text.mp3")) + mp3_fp.seek(0) + await ctx.send(file=discord.File(mp3_fp, "text.mp3"))