Ejemplo n.º 1
0
 async def create(self, ctx, tag_name: commands.clean_content, *,
                  tag_value: commands.clean_content):
     tag_name = str(tag_name)
     if tag_name.lower() in ['remove', 'create']:
         return await ctx.send("Cannot make tag that is a tag command.")
     if len(tag_name.strip()
            ) > 100:  # tbh idk if this check is really a good one
         return await ctx.send("Tag name too long (100 or less characters)")
     if len(str(tag_value)) >= 1800:
         return await ctx.send("Tag value too long (1800 or less characters"
                               )
     g = mongo_setup.mod_and_logging_config.find_one(
         {'_id': ctx.guild.id}
     )  # if theres tags for ctx.guild, then the dict should be formatted like: {'tag name': {'author': user id, 'value': 'tag value'}}
     if not g:
         mongo_setup.tags.insert_one({'_id': ctx.guild.id
                                      })  # if theres no tags for ctx.guild
         g = mongo_setup.tags.find_one({'_id': ctx.guild.id})
     t = g.get(tag_name, None)  # checking if the tag is already in the dict
     if not t:
         d = {'value': tag_value, 'author': ctx.author.id}
         mongo_setup.tags.update_one({'_id': ctx.guild.id},
                                     {'$set': {
                                         tag_name: d
                                     }})
         return await ctx.send(f"Tag {tag_name} created!")
     await ctx.send(f"Tag {tag_name} already exists")
Ejemplo n.º 2
0
    async def _remove(self, ctx, channel: discord.TextChannel = None, *, target: commands.clean_content):
        """ Remove a competition from a live-scores channel
        
        Either perform ls remove <league name> in the channel you wish to delete it from, or use
        ls remove #channel <league name> to delete it from another channel."""
        # Verify we have a valid livescores channel target.
        channel = ctx.channel if channel is None else channel
        if channel.id not in {i[1] for i in self.cache}:
            return await ctx.send(f'{channel.mention} is not set as a scores channel.')

        # Verify which league the user wishes to remove.
        target = target.strip("'\",")  # Remove quotes, idiot proofing.
        leagues = self.cache[(ctx.guild.id, channel.id)]
        matches = [i for i in leagues if target.lower() in i.lower()]
        index = await embed_utils.page_selector(ctx, matches)
        if index is None:
            return  # rip.
        target = matches[index]
        
        connection = await self.bot.db.acquire()
        async with connection.transaction():
            await connection.execute(""" DELETE FROM scores_leagues WHERE (league,channel_id) = ($1,$2)""",
                                     target, channel.id)
        leagues.remove(target)
        leagues = ", ".join(leagues)
        await ctx.send(f"✅ **{target}** was deleted from the tracked leagues for {channel.mention},"
                       f" the new tracked leagues list is: ```yaml\n{leagues}```\n")
        await self.bot.db.release(connection)
        await self.update_cache()
Ejemplo n.º 3
0
 async def roll(self, ctx: Context, *, message: clean_content):
     display_name = get_name_string(ctx.message)
     if len(message) == 0:
         message = "1d6"
     message = message.strip()
     try:
         expression = DiceParser.parse_all.parse(message).or_die()
     except ParseError as e:
         await ctx.send(
             FAILURE_OUT.format(ping=display_name, body=f"```{e}```"))
         return
     except ExcessiveDiceRollsError:
         await ctx.send(
             WARNING_OUT.format(
                 ping=display_name,
                 body="_You requested an excessive number of dice rolls._",
             ))
         return
     value = expression.value
     try:
         out = SUCCESS_OUT.format(
             ping=display_name,
             body=
             f"`{repr(expression)}` | **{value}** ⟵ {clean_brackets(str(expression))}",
         )
         await ctx.send(out)
     except OutputTooLargeError:
         await ctx.send(
             WARNING_OUT.format(ping=display_name,
                                body="_Your output was too large!_"))
Ejemplo n.º 4
0
    async def _remove(self, ctx,
                      channels: commands.Greedy[discord.TextChannel], *,
                      target: commands.clean_content):
        """ Remove a competition from an existing live-scores channel """
        # Verify we have a valid livescores channel target.
        channels = await self._pick_channels(ctx, channels)

        if not channels:
            return  # rip

        all_leagues = set()
        target = target.strip("'\",")  # Remove quotes, idiot proofing.

        for c in channels:  # Fetch All partial matches
            leagues = self.cache[(ctx.guild.id, c.id)]
            all_leagues |= set(
                [i for i in leagues if target.lower() in i.lower()])

        # Verify which league the user wishes to remove.
        all_leagues = list(all_leagues)
        index = await embed_utils.page_selector(ctx, all_leagues)
        if index is None:
            return  # rip.

        target = all_leagues[index]

        for c in channels:
            if c.id not in {i[1] for i in self.cache}:
                await ctx.reply(f'{c.mention} is not set as a scores channel.',
                                mention_author=True)
                continue

            connection = await self.bot.db.acquire()
            async with connection.transaction():
                await connection.execute(
                    """ DELETE FROM scores_leagues WHERE (league,channel_id) = ($1,$2)""",
                    target, c.id)
            await self.bot.db.release(connection)
            leagues = self.cache[(ctx.guild.id, c.id)].copy()
            leagues.remove(target)

            await ctx.reply(
                f"✅ **{target}** deleted from the tracked leagues for {c.mention}",
                mention_author=False)
            await self.update_channel(c.guild.id, c.id)
            await send_leagues(ctx, c, leagues)
        await self.update_cache()
Ejemplo n.º 5
0
    async def transferccmd(self, ctx, *, arg: commands.clean_content):
        """Transfer ownership of a custom command.
        It will ask you who to give it to and you just need to @ the user when that happens.
        Only the owner/admin can transfer ownership."""
        arg = arg.strip()
        user = self.cursor.execute(
            "SELECT owner FROM custom_cmd WHERE server = ? AND cmd = ?",
            (str(ctx.guild.id), arg)).fetchone()
        if not user:
            await ctx.send("Onii-chan, that custom command doesn't exist.")
            return
        if int(
                user[0]
        ) == ctx.author.id or ctx.author.guild_permissions.administrator or int(
                user[0]) == self.bot.owner_id:

            def check(message):
                return message.author == ctx.message.author

            try:
                await ctx.send(
                    "Onii-chan, who do you want to give the command to?")
                message = await self.bot.wait_for(
                    'message',
                    timeout=self.config.customcmd_timeout,
                    check=check)
                try:
                    owner = await commands.MemberConverter().convert(
                        ctx, message.content)
                    if owner.id == int(user[0]):
                        await ctx.send(
                            "Onii-chan, that person already own this command.")
                        return
                    self.cursor.execute(
                        "UPDATE custom_cmd SET owner = ? WHERE server = ? AND cmd = ?",
                        (str(owner.id), str(ctx.guild.id), arg))
                    self.conn.commit()
                    await message.add_reaction("✅")
                except commands.BadArgument:
                    await ctx.send("Onii-chan, I can't find the user(>﹏<)")
            except asyncio.TimeoutError:
                await ctx.send("Timed out.")
        else:
            await ctx.send(
                "Onii-chan, you don't have the permission to transfer ownership of this command."
            )
Ejemplo n.º 6
0
 async def ccmdinfo(self, ctx, *, arg: commands.clean_content):
     """Returns information (current owner, author, content) about a custom command."""
     arg = arg.strip()
     info = self.cursor.execute(
         "SELECT owner, author, cmd, response FROM custom_cmd WHERE server = ? AND cmd = ?",
         (str(ctx.guild.id), arg)).fetchone()
     if not info:
         await ctx.send("Onii-chan, that custom command doesn't exist.")
         return
     embed = discord.Embed(title=f"Information for {info[2]}")
     if info[0] == info[1]:
         owner = author = ctx.guild.get_member(int(info[0]))
     else:
         owner = ctx.guild.get_member(int(info[0]))
         author = ctx.guild.get_member(int(info[1]))
     embed.add_field(name="Owner:",
                     value=owner or "Unknown owner.",
                     inline=False)
     embed.add_field(name="Author:",
                     value=author or "Unknown author.",
                     inline=False)
     embed.add_field(name="Content:", value=info[3])
     await ctx.send(embed=embed)
Ejemplo n.º 7
0
 async def delccmd(self, ctx, *, arg: commands.clean_content):
     """Delete the custom command.
     Only the owner/admin can delete the command."""
     arg = arg.strip()
     user = self.cursor.execute(
         "SELECT owner FROM custom_cmd WHERE server = ? AND cmd = ?",
         (str(ctx.guild.id), arg)).fetchone()
     if not user:
         await ctx.send("Onii-chan, that custom command doesn't exist.")
         return
     if user[0] == str(
             ctx.author.id
     ) or ctx.author.guild_permissions.administrator or user[0] == str(
             self.bot.owner_id):
         self.cursor.execute(
             "DELETE FROM custom_cmd WHERE server = ? AND cmd = ?",
             (str(ctx.guild.id), arg))
         self.conn.commit()
         await ctx.message.add_reaction("✅")
     else:
         await ctx.send(
             "Onii-chan, you don't have the permission to delete this command."
         )
Ejemplo n.º 8
0
 async def roll(self, ctx: Context, *, message: clean_content):
     display_name = get_name_string(ctx.message)
     if len(message) == 0:
         message = "1d6"
     message = message.strip()
     try:
         program = await self.parse(message)
         out = SUCCESS_OUT.format(
             ping=display_name,
             body=f"**{value(program)}** ⟵ `{clean_brackets(str(program))}`",
         )
         if len(out) > MAX_ROLLS:
             raise OutputTooLargeError
         await ctx.send(out)
     except WarningError as e:
         await ctx.send(
             WARNING_OUT.format(ping=display_name, body=f"_{e.out}_"))
     except (ParseError, RunTimeError) as e:
         await ctx.send(
             FAILURE_OUT.format(ping=display_name, body=f"```{e}```"))
     except (InternalError, Exception) as e:
         await ctx.send(
             INTERNAL_OUT.format(ping=display_name,
                                 body=f"**Internal error:**```{e}```"))