Esempio n. 1
0
    async def add_user_to_twitch_alert(self, ctx, twitch_username,
                                       channel: discord.TextChannel, *custom_live_message):
        """
        Add a Twitch user to a Twitch Alert
        :param ctx: The discord context of the command
        :param twitch_username: The Twitch Username of the user being added (lowercase)
        :param channel: The channel ID where the twitch alert is being used
        :param custom_live_message: the custom live message for this user's alert
        :return:
        """
        channel_id = channel.id
        twitch_username = str.lower(twitch_username)
        if not re.search(TWITCH_USERNAME_REGEX, twitch_username):
            raise discord.errors.InvalidArgument(
                "The given twitch_username is not a valid username (please use lowercase)")

        # Check the channel specified is in this guild
        if not is_channel_in_guild(self.bot, ctx.message.guild.id, channel_id):
            await ctx.send(embed=error_embed("The channel ID provided is either invalid, or not in this server."))
            return

        default_message = self.ta_database_manager.new_ta(ctx.message.guild.id, channel_id)

        # Setting the custom message as required
        if custom_live_message is not None and custom_live_message != (None,):
            custom_message = " ".join(custom_live_message)
            default_message = custom_message
            if len(default_message) > 1000:
                await ctx.send(embed=error_embed(
                    "custom_message is too long, try something with less than 1000 characters"))
                return
        else:
            custom_message = None

        self.ta_database_manager.add_user_to_ta(channel_id, twitch_username, custom_message, ctx.message.guild.id)

        # Response Message
        new_embed = discord.Embed(title="Added User to Twitch Alert", colour=KOALA_GREEN,
                                  description=f"Channel: {channel_id}\n"
                                              f"User: {twitch_username}\n"
                                              f"Message: {default_message}")

        await ctx.send(embed=new_embed)
Esempio n. 2
0
    async def edit_default_message(self, ctx, channel: discord.TextChannel, *default_live_message):
        """
        Edit the default message put in a Twitch Alert Notification
        :param ctx: The discord context of the command
        :param channel: The channel where the twitch alert is being used
        :param default_live_message: The default live message of users within this Twitch Alert,
        leave empty for program default
        :return:
        """
        channel_id = channel.id

        if not is_channel_in_guild(self.bot, ctx.message.guild.id, channel_id):
            await ctx.send(embed=error_embed("The channel ID provided is either invalid, or not in this server."))
            return

        # Assigning default message if provided
        if default_live_message is not None and default_live_message != (None,):
            default_message = " ".join(default_live_message)
            if len(default_message) > 1000:
                await ctx.send(embed=error_embed(
                    "custom_message is too long, try something with less than 1000 characters"))
                return

        else:
            default_message = None

        # Creates a new Twitch Alert with the used guild ID and default message if provided
        default_message = self.ta_database_manager.new_ta(ctx.message.guild.id, channel_id, default_message,
                                                          replace=True)

        # Returns an embed with information altered
        new_embed = discord.Embed(title="Default Message Edited", colour=KOALA_GREEN,
                                  description=f"Guild: {ctx.message.guild.id}\n"
                                              f"Channel: {channel_id}\n"
                                              f"Default Message: {default_message}")
        await ctx.send(embed=new_embed)
Esempio n. 3
0
    async def list_twitch_alert(self, ctx: discord.ext.commands.Context, channel: discord.TextChannel):
        """
        Shows all current TwitchAlert users and teams in a channel
        :param ctx:
        :param channel: The discord channel ID of the Twitch Alert
        """
        if not channel:
            channel = ctx.channel

        channel_id = channel.id

        if not is_channel_in_guild(self.bot, ctx.message.guild.id, channel_id):
            await ctx.send(embed=error_embed("The channel ID provided is either invalid, or not in this server."))
            return
        embed = discord.Embed()
        embed.title = "Twitch Alerts"
        embed.colour = KOALA_GREEN
        embed.set_footer(text=f"Channel ID: {channel_id}")

        results = self.ta_database_manager.get_users_in_ta(channel_id)
        if results:
            users = ""
            for result in results:
                users += f"{result.twitch_username}\n"
            embed.add_field(name=":bust_in_silhouette: Users", value=users)
        else:
            embed.add_field(name=":bust_in_silhouette: Users", value="None")

        results = self.ta_database_manager.get_teams_in_ta(channel_id)
        if results:
            teams = ""
            for result in results:
                teams += f"{result.twitch_team_name}\n"
            embed.add_field(name=":busts_in_silhouette: Teams", value=teams)
        else:
            embed.add_field(name=":busts_in_silhouette: Teams", value="None")

        await ctx.send(embed=embed)
Esempio n. 4
0
    async def remove_team_from_twitch_alert(self, ctx, team_name, channel: discord.TextChannel):
        """
        Removes a team from a Twitch Alert
        :param ctx: the discord context
        :param team_name: The Twitch team being added (lowercase)
        :param channel: The discord channel ID of the Twitch Alert
        :return:
        """

        channel_id = channel.id

        # Check the channel specified is in this guild
        if not is_channel_in_guild(self.bot, ctx.message.guild.id, channel_id):
            await ctx.send(embed=error_embed("The channel ID provided is either invalid, or not in this server."))
            return

        await self.ta_database_manager.remove_team_from_ta(channel_id, team_name)
        # Response Message
        new_embed = discord.Embed(title="Removed Team from Twitch Alert", colour=KOALA_GREEN,
                                  description=f"Channel: {channel_id}\n"
                                              f"Team: {team_name}")

        await ctx.send(embed=new_embed)
Esempio n. 5
0
    async def view_default_message(self, ctx, channel: discord.TextChannel):
        """
        Shows the current default message for Twitch Alerts
        :param ctx: The discord context of the command
        :param channel: The channel where the twitch alert is being used
        leave empty for program default
        :return:
        """
        channel_id = channel.id

        if not is_channel_in_guild(self.bot, ctx.message.guild.id, channel_id):
            await ctx.send(embed=error_embed("The channel ID provided is either invalid, or not in this server."))
            return

        # Creates a new Twitch Alert with the used guild ID and default message if provided
        default_message = self.ta_database_manager.get_default_message(channel_id)

        # Returns an embed with information altered
        new_embed = discord.Embed(title="Default Message", colour=KOALA_GREEN,
                                  description=f"Guild: {ctx.message.guild.id}\n"
                                              f"Channel: {channel_id}\n"
                                              f"Default Message: {default_message}")
        # new_embed.set_footer(text=f"Twitch Alert ID: {new_id}")
        await ctx.send(embed=new_embed)
Esempio n. 6
0
async def on_command_error(ctx, error: Exception):
    if error.__class__ in [commands.MissingRequiredArgument,
                           commands.CommandNotFound]:
        await ctx.send(embed=error_embed(description=error))
    if error.__class__ in [commands.CheckFailure]:
        await ctx.send(embed=error_embed(error_type=str(type(error).__name__),
                                         description=str(error)+"\nPlease ensure you have administrator permissions, "
                                                                "and have enabled this extension."))
    elif isinstance(error, commands.CommandOnCooldown):
        await ctx.send(embed=error_embed(description=f"{ctx.author.mention}, this command is still on cooldown for "
                                                     f"{str(error.retry_after)}s."))
    elif isinstance(error, commands.errors.ChannelNotFound):
        await ctx.send(embed=error_embed(description=f"The channel ID provided is either invalid, or not in this server."))
    elif isinstance(error, commands.CommandInvokeError):
        # logger.warning("CommandInvokeError(%s), guild_id: %s, message: %s", error.original, ctx.guild.id, ctx.message)
        await ctx.send(embed=error_embed(description=error.original))
    else:
        logger.error(f"Unexpected Error in guild %s : %s", ctx.guild.name, error, exc_info=error)
        await ctx.send(embed=error_embed(
            description=f"An unexpected error occurred, please contact an administrator Timestamp: {time.time()}")) # FIXME: better timestamp
        raise error