예제 #1
0
    async def baseConvert(self, ctx, baseFrom: int, baseTo: int, numValue):
        alphabet = [
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
        ]

        # checks if base and values are valid and within the limits
        try:
            if len(numValue) > 20:
                await ctx.send(embed=embed.make_error_embed("Value too large.")
                               )
                return

            if baseFrom > 36 or baseFrom < 2 or baseTo > 36 or baseTo < 2:
                await ctx.send(embed=embed.make_error_embed(
                    "Please use a base between 2 and 36."))
                return

            for i in numValue:
                if (str(i) in alphabet):
                    if ((int(alphabet.index(i)) + 10) > baseFrom):
                        await ctx.send(embed=embed.make_error_embed(
                            f"Invalid value for base {baseFrom}."))
                        return
                try:
                    if int(i) > baseFrom:
                        await ctx.send(embed=embed.make_error_embed(
                            f"Invalid value for base {baseFrom}."))
                        return
                except:
                    pass
        except:
            await ctx.send(embed=embed.make_error_embed("Error"))
            return

        # converts value to base 10
        x = len(numValue)
        base10Value = 0
        for num in numValue:
            x = x - 1
            if num.upper() in alphabet:
                base10Value += (alphabet.index(num) + 10) * (baseFrom**x)
            else:
                base10Value += int(num) * (baseFrom**x)

        # successive division to get converted value
        digits = []
        while base10Value > 0:
            digits.insert(0, base10Value % baseTo)
            base10Value = base10Value // baseTo

        # turns array of digits into proper string
        finalValue = ""
        for i in digits:
            if i > 9:
                finalValue += alphabet[i - 10]
            else:
                finalValue += str(i)

        await ctx.send(finalValue)  # prints result
예제 #2
0
    async def send_command_help(self, command):
        prefix = dbQuery.prefix(self.context.guild.id)

        try:
            await command.can_run(self.context)
        except:
            await self.context.send(embed=embed.make_error_embed("Command not found"))
            return

        try:
            if command.parent == None:
                name = f"{command.name}"
                randomVar2 = True
            else:
                name = f"{command.parent} {command.name}"
                randomVar2 = dbQuery.command(self.context.guild.id, command.parent)

            randomVar = dbQuery.command(self.context.guild.id, name) # gets true/false value of command for guild
            if randomVar and randomVar2: # if command is enabled in guild
                alias = commandList(command.aliases)

                await self.context.send(embed=embed.make_embed_fields_ninl(command.name, command.description, ("Usage", f"`{prefix}{command.usage}`"), ("Aliases", alias)))
            else:
                await self.context.send(embed=embed.make_error_embed("Command not found"))
        except:
            await self.context.send(embed=embed.make_error_embed("Command not found"))
예제 #3
0
    async def rank(self, ctx, *, user: discord.Member = None):
        try:
            if not user:
                userID = int(ctx.author.id)
                userDisplay = str(ctx.author)
                userAvatar = ctx.author.avatar
                userColor = ctx.author.color
            else:
                userID = int(user.id)
                userDisplay = str(user)
                userAvatar = user.avatar
                userColor = user.color
            data = dbQuery.leaderboard(ctx.guild.id, userID)

            if data[4] == "":
                await ctx.send(embed=embed.make_error_embed("User unavailable."))

            emb = discord.Embed(description=f"Rank Info", color=userColor)
            emb.set_author(name=userDisplay, icon_url=f'https://cdn.discordapp.com/avatars/{userID}/{userAvatar}.png', url=f'https://applesauce.site/member.php?member={userID}')
            emb.add_field(name='Level', value=data[4], inline=False)
            emb.add_field(name='XP Needed for Next Level', value=data[6], inline=False)
            emb.add_field(name='Total XP', value=data[5], inline=False)
            emb.add_field(name='Message Count', value=data[8], inline=False)
            emb.set_footer(text=f'Click name for profile.')
            await ctx.send(embed=emb)
        except:
            await ctx.send(embed=embed.make_error_embed("User unavailable."))
예제 #4
0
 async def archiveRole(self, ctx, role):
     try:
         dbInsert.archiveRole(ctx.guild.id, role)
         await ctx.send(
             embed=embed.make_embed("Archiving", f"Role: <@&{int(role)}>"))
     except:
         await ctx.send(embed=embed.make_error_embed("Invalid role ID"))
예제 #5
0
 async def archiveChannel(self, ctx, channel):
     try:
         dbInsert.archiveChannel(ctx.guild.id, channel)
         await ctx.send(embed=embed.make_embed(
             "Archiving", f"Channel: <#{int(channel)}>"))
     except:
         await ctx.send(embed=embed.make_error_embed("Invalid channel ID"))
예제 #6
0
 async def archivePins(self, ctx, value: bool):
     try:
         dbInsert.archivePins(ctx.guild.id, value)
         await ctx.send(embed=embed.make_embed(
             "Archiving", f"Archiving pins set to {value}"))
     except:
         await ctx.send(
             embed=embed.make_error_embed("Error. Please try again."))
예제 #7
0
    async def send_group_help(self, group):
        prefix = dbQuery.prefix(self.context.guild.id)

        try:
            await group.can_run(self.context)
        except:
            await self.context.send(embed=embed.make_error_embed("Command not found"))
            return
            
        try:
            randomVar = dbQuery.command(self.context.guild.id, group.name) # gets true/false value of command for guild
            if randomVar == True: # if command is enabled in guild
                subcmds = ""
                if group.commands != []:
                    for command in group.commands:
                        try:
                            name = f"{group.name} {command.name}"
                            randomVar2 = dbQuery.command(self.context.guild.id, name)
                            if randomVar2 == True:
                                subcmds = subcmds + '`' + command.name + '`' + ', '
                        except:
                            pass
                    if subcmds != "":
                        subcmds = subcmds[:-2]
                    else:
                        subcmds = "None"
                else:
                    subcmds = "None"

                alias = commandList(group.aliases)

                await self.context.send(embed=embed.make_embed_fields_ninl(group.name, group.description, ("Usage", f"`{prefix}{group.usage}`"), ("Aliases", alias), ("Subcommands", subcmds)))
            else:
                await self.context.send(embed=embed.make_error_embed("Command not found"))
        except:
            await self.context.send(embed=embed.make_error_embed("Command not found"))
예제 #8
0
 async def send_cog_help(self, cog):
     await self.context.send(embed=embed.make_error_embed("Command not found"))
예제 #9
0
 async def subcommand_not_found(self, command, string):
     await self.context.send(embed=embed.make_error_embed("Command not found"))
예제 #10
0
    async def archive(self, ctx, messageID):
        conf = dbQuery.archive(ctx.guild.id)
        if conf[4] == True:
            try:
                data = await ctx.fetch_message(messageID)
                current_date = datetime.datetime.utcfromtimestamp(
                    int(time.time()))
                try:
                    channelID = conf[1]
                    channel = self.bot.get_channel(channelID)
                except:
                    await ctx.send(embed=embed.make_error_embed(
                        "No archiving channel set. Set one using `archiveChannel`"
                    ))

                # if message was an embed
                try:
                    embed2 = data.embeds[0]
                    embed2.timestamp = current_date
                    embed2.set_footer(
                        text=
                        f'Embedded message sent in <#{self.bot.get_channel(int(data.channel.id))}>'
                    )
                    await channel.send(embed=embed2)
                    return
                except:
                    pass

                # if message isn't an embed
                embed = discord.Embed(description=f"{data.content}",
                                      color=0xc1c100,
                                      timestamp=current_date)
                try:
                    attachmentURL = data.attachments[0].url
                    embed.set_image(url=attachmentURL)
                except:
                    pass

                try:
                    roleID = conf[2]
                    role = ctx.guild.get_role(roleID)
                    member = ctx.guild.get_member(data.author.id)
                    if member != self.bot.user:
                        await member.add_roles(role, atomic=True)
                except:
                    pass

                embed.set_footer(
                    text=
                    f'Sent in #{self.bot.get_channel(int(data.channel.id))}')
                embed.set_author(
                    name=data.author.name,
                    icon_url=
                    f'https://cdn.discordapp.com/avatars/{data.author.id}/{data.author.avatar}.png',
                    url=
                    f'https://discordapp.com/channels/{data.guild.id}/{data.channel.id}/{data.id}'
                )
                await channel.send(embed=embed)
                await ctx.message.add_reaction("📌")
            except:
                await ctx.send(embed=embed.make_error_embed(
                    "Error occured while trying to archive. Please try again.")
                               )