async def setstarlimit(self, ctx, count_='1'):
     try:
         count_ = int(count_)
     except ValueError:
         ctx.command.reset_command(ctx)
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> Star limit must be a number not letters!',
             colour=discord.Colour.red()))
     if count_ < 0:
         return await ctx.send(embed=discord.Embed(description=''))
     board = db.record('SELECT star_channel FROM guild WHERE GuildID = ?',
                       ctx.guild.id) or (None, )
     if not board[0]:
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> Please setup a starboard using command `-Setboard` before using this command!',
             colour=discord.Colour.red()))
     else:
         db.execute('UPDATE guild SET star_count = ? WHERE GuildID = ?',
                    count_, ctx.guild.id)
         db.commit()
         await ctx.send(embed=discord.Embed(
             description=
             '<a:Passed:757652583392215201> New Starboard limit is {}.'.
             format(count_),
             colour=discord.Colour.green()))
 async def setboard(self, ctx, channel: discord.TextChannel = None):
     if not channel:
         ctx.command.reset_command(ctx)
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> Please mention a channel, If you wish to remove your starboard mention that channel! You can view your configs by using command `-Starboard`',
             colour=discord.Colour.red()))
     channel_ = db.record(
         'SELECT star_channel FROM guild WHERE GuildID = ?',
         ctx.guild.id) or (None, )
     if channel_[0] == channel.id:
         db.execute('UPDATE guild SET star_channel = ? WHERE GuildID = ?',
                    None, ctx.guild.id)
         db.commit()
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:Passed:757652583392215201> Removed starboard from this server!',
             colour=discord.Colour.green()))
     db.execute('UPDATE guild SET star_channel = ? WHERE GuildID = ?',
                channel.id, ctx.guild.id)
     db.commit()
     await ctx.send(embed=discord.Embed(
         description=
         '<a:Passed:757652583392215201> New Starboard has been set for {}'.
         format(channel.mention),
         colour=discord.Colour.green()))
    async def set_ticket(self,
                         ctx,
                         channel: discord.TextChannel = None,
                         helper: discord.Role = None,
                         category: discord.CategoryChannel = None,
                         *,
                         notes: str = None) -> None:
        if not channel:
            return await ctx.send(embed=discord.Embed(
                description=
                '<a:nope:787764352387776523> Provide the channel were the Tickets will be created at!',
                colour=discord.Colour.red()))
        if not helper:
            return await ctx.send(embed=discord.Embed(
                description=
                '<a:nope:787764352387776523> Provide the minimum role for a user to help in the ticket channels!',
                colour=discord.Colour.red()))
        embed = discord.Embed(
            title='Tickets!',
            description='React to the message below to open a ticket!',
            colour=discord.Colour.teal(),
            timestamp=ctx.message.created_at)
        if category:
            embed.add_field(name='Info:',
                            value=f'''
            Once your **Ticket** has been opened, You will be redirected to {category.mention}.
            Please wait patiently for a user to come help you!

            **ADDITIONS:**

            Users with roles {helper.mention} and higher can only help you.
            **Notes:** {'None Provided.' if not notes else notes}
            ''')
        else:
            embed.add_field(name='Info:',
                            value=f'''
            Once your **Ticket** has been opened, You will be redirected to the top of your server.
            Please wait patiently for a user to come help you!

            **ADDITIONS**:
            
            Users with roles **{helper.name}** and higher can only help you.
            **Notes:** {'None Provided.' if not notes else notes}
            ''')
        embed.set_footer(text='Opened Tickets',
                         icon_url=self.bot.user.avatar_url)
        embed.set_thumbnail(
            url='https://cdn.onlinewebfonts.com/svg/img_63409.png')
        msg = await ctx.send(embed=embed)
        await msg.add_reaction('📩')
        try:
            db.execute(
                'INSERT INTO tickets (GuildID, TicketChannel, TicketMessage, TMC, HelperRole) VALUES (?, ?, ?, ?, ?)',
                ctx.guild.id, category.id, msg.id, channel.id, helper.name)
        except sqlite3.IntegrityError:
            db.execute(
                'UPDATE tickets SET TicketChannel = ?, TicketMessage = ?, TMC = ?, HelperRole = ? WHERE GuildID = ?',
                category.id, msg.id, channel.id, helper.name, ctx.guild.id)
        db.commit()
示例#4
0
def get_prefix(bot,message):
    if isinstance(message.channel, discord.DMChannel):
        return
    prefix = db.record(
        'SELECT prefix FROM guild WHERE GuildID = ?', message.guild.id) or None
    if not prefix:
        db.execute('INSERT INTO guild (GuildID) VALUES (?)', message.guild.id)
        db.commit()
        prefix = '-'
    else:
        prefix = prefix[0]
    return commands.when_mentioned_or(prefix)(bot, message)
 async def on_raw_reaction_add(self, payload):
     if payload.emoji.name == '🔒' and not payload.member.bot:
         message = await self.bot.get_channel(
             payload.channel_id).fetch_message(payload.message_id)
         if not message.embeds:
             return
         dict_ = message.embeds[0].to_dict()
         if dict_['color'] != 1752220 and len(
                 dict_['title'].split('#')) != 2:
             return
         if not str(payload.member) == dict_['title'].split("'")[0]:
             return
         channel = self.bot.get_channel(payload.channel_id)
         await channel.delete()
     if not payload.emoji.name == '📩':
         return
     category, message, root, count, role = db.record(
         'SELECT TicketChannel, TicketMessage, TMC, Count, HelperRole FROM tickets WHERE GuildID = ?',
         payload.guild_id) or (None, None, None, 0, None)
     if not message or not root or payload.member.bot:
         return
     ticket_message = await self.bot.get_channel(root).fetch_message(message
                                                                     )
     if payload.member != self.bot.user:
         await ticket_message.remove_reaction(payload.emoji, payload.member)
     guild: discord.Guild = self.bot.get_guild(payload.guild_id)
     helper: discord.Role = discord.utils.get(guild.roles, name=role)
     if not category:
         channel = await guild.create_text_channel(
             name='ticket-{}'.format(count),
             overwrites=over(payload.member, helper),
             reason='Ticket Opened by {}'.format(payload.member))
     else:
         category: discord.CategoryChannel = self.bot.get_channel(category)
         channel = await category.create_text_channel(
             name='ticket-{}'.format(count),
             overwrites=over(payload.member, helper),
             reason='Ticket Opened by {}'.format(payload.member))
     db.execute('UPDATE tickets SET Count = Count + 1 WHERE GuildID = ?',
                payload.guild_id)
     db.commit()
     msg = await channel.send(
         embed=discord.Embed(title="{}'s Ticket:".format(payload.member),
                             description=f'''
         This is your support ticket, State your problems here and a user with the role {helper.mention} will be with you.
         To close this ticket react with a \🔒 to close this ticket.
         ''',
                             colour=discord.Colour.teal()))
     await msg.add_reaction('🔒')
 async def remove_tickets(self, ctx):
     is_active = db.record(
         'SELECT TicketMessage FROM tickets WHERE GuildID = ?',
         ctx.guild.id) or (None, )
     if not is_active[0]:
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> You have not got any running tickets for this sever!.',
             colour=discord.Colour.red()))
     db.execute('DELETE FROM tickets WHERE GuildID = ?', ctx.guild.id)
     db.commit()
     await ctx.send(embed=discord.Embed(
         description=
         '<a:Passed:757652583392215201> Tickets is no longer active with your server!',
         colour=discord.Colour.green()))
 async def delwarn(self, ctx, user: discord.Member = None, warn: str = '0'):
     if warn == '0':
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> Need to provide a warn number!',
             colour=discord.Colour.red()))
     try:
         warn = int(warn)
     except ValueError:
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> Number provided must be a number not letters!',
             colour=discord.Colour.red()))
     if not user:
         return await ctx.send(embed=discord.Embed(
             description='<a:nope:787764352387776523> Provide a member!',
             colour=discord.Colour.red()))
     warns = db.record('SELECT warnings FROM guild WHERE GuildID = ?',
                       ctx.guild.id) or (None, )
     if not warns[0]:
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> User doesnt have any warns!',
             colour=discord.Colour.red()))
     warns = json.loads(warns[0])
     if len(warns[str(user.id)]) < warn or warn < 1:
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> Warn number was not found!',
             colour=discord.Colour.red()))
     if user == ctx.author:
         return await ctx.send(embed=discord.Embed(
             description=
             '<a:nope:787764352387776523> Cannot remove your own warns!'))
     del warns[str(user.id)][str(warn)]
     if len(warns[str(user.id)]) == 0:
         del warns[str(user.id)]
     stringed = json.dumps(warns)
     db.execute('UPDATE guild SET warnings = ? WHERE GuildID = ?', stringed,
                ctx.guild.id)
     db.commit()
     await ctx.send(embed=discord.Embed(
         description=
         '<a:Passed:757652583392215201> Deleted warning number **{}** for user **{}**.'
         .format(warn, user),
         colour=discord.Colour.green()))
    async def warn(self,
                   ctx,
                   user: discord.Member = None,
                   *,
                   reason: str = None):
        if not user:
            return await ctx.send(embed=discord.Embed(
                description=
                '<a:nope:787764352387776523> Need to provide a user to warn!',
                colour=discord.Colour.red()),
                                  mention_author=False)
        if user.top_role > ctx.author.top_role:
            return await ctx.message.reply(embed=discord.Embed(
                description=
                '<a:nope:787764352387776523> Cannot warn members with a higher role then you!',
                colour=discord.Colour.red()),
                                           mention_author=False)
        if user == ctx.author:
            return await ctx.message.reply(embed=discord.Embed(
                description='<a:nope:787764352387776523> Cannot warn yourself!',
                colour=discord.Colour.red()),
                                           mention_author=False)
        if not reason:
            return await ctx.message.reply(embed=discord.Embed(
                description=
                '<a:nope:787764352387776523> Need to provide a reason for the warn!',
                colour=discord.Colour.red()),
                                           mention_author=False)

        action = db.record('SELECT ModAction FROM guild WHERE GuildID = ?',
                           ctx.guild.id) or (0, )
        current_warns = db.record(
            'SELECT warnings FROM guild WHERE GuildID = ?',
            ctx.guild.id) or (None, )
        if not current_warns[0]:
            former = {
                user.id: {
                    1: {
                        'moderator':
                        str(ctx.author),
                        'reason':
                        reason,
                        'warned_at':
                        datetime.datetime.utcnow().strftime(
                            '%d/%m/%Y - %I:%M %p'),
                        'num':
                        action[0] + 1
                    }
                }
            }
            stringed = json.dumps(former)
            db.execute('UPDATE guild SET warnings = ? WHERE GuildID = ?',
                       stringed, ctx.guild.id)
            await ctx.message.reply(embed=discord.Embed(
                description=
                '<a:Passed:757652583392215201> **Successfully** logged warning for {}'
                .format(user.mention),
                colour=discord.Colour.green()))
        else:
            data = current_warns[0]
            dict_ = json.loads(data)
            if str(user.id) not in dict_:
                dict_[str(user.id)] = {
                    1: {
                        'moderator':
                        str(ctx.author),
                        'reason':
                        reason,
                        'warned_at':
                        datetime.datetime.utcnow().strftime(
                            '%d/%m/%Y - %I:%M %p'),
                        'num':
                        action[0] + 1
                    }
                }
            else:
                dict_[str(user.id)][str(len(dict_[str(user.id)]) + 1)] = {
                    'moderator':
                    str(ctx.author),
                    'reason':
                    reason,
                    'warned_at':
                    datetime.datetime.utcnow().strftime('%d/%m/%Y - %I:%M %p'),
                    'num':
                    action[0] + 1
                }
            stringed = json.dumps(dict_)
            db.execute('UPDATE guild SET warnings = ? WHERE GuildID = ?',
                       stringed, ctx.guild.id)
            db.execute('UPDATE guild SET ModAction = ? WHERE GuildID = ?',
                       action[0] + 1, ctx.guild.id)
            await ctx.message.reply(embed=discord.Embed(
                description=
                '<a:Passed:757652583392215201> **Successfully** warned **{}**'.
                format(user),
                colour=discord.Colour.green()))
        db.commit()
 async def on_raw_reaction_add(self, payload):
     global count
     if payload.emoji.name == 'тнР':
         channel = db.record(
             'SELECT star_channel FROM guild WHERE GuildID = ?',
             payload.guild_id) or (None, )
         if not channel[0]:
             return
         message = await self.bot.get_channel(
             payload.channel_id).fetch_message(payload.message_id)
         if payload.member.id == message.author.id or message.author.bot or channel[
                 0] == payload.channel_id:
             return await message.remove_reaction(payload.emoji,
                                                  payload.member)
         star_message = db.record(
             'SELECT StarMessage FROM starboard WHERE RootMessage = ?',
             message.id) or (None, )
         star_limit = db.record(
             'SELECT star_count FROM guild WHERE GuildID = ?',
             payload.guild_id) or (0, )
         for reaction in message.reactions:
             if reaction.emoji == 'тнР':
                 count = reaction.count
                 break
             else:
                 count = 0
         if count == 0:
             db.execute('DELETE FROM starboard WHERE RootMessage = ?',
                        message.id)
             return db.commit()
         star_limit = 0 if not star_limit[0] else star_limit[0]
         if count < star_limit:
             return
         star_channel = self.bot.get_channel(channel[0])
         embed, mes = create_embed(message, count)
         if not star_message[0]:
             try:
                 star_mes = await star_channel.send(content=mes,
                                                    embed=embed)
             except discord.errors.HTTPException:
                 embed = discord.Embed(
                     description='[Original Message]({})'.format(
                         message.jump_url),
                     colour=discord.Colour.red()).set_author(
                         icon_url=message.author.avatar_url,
                         name=message.author)
                 embed.set_footer(
                     text='Missing Field, Cannot Load Original Message!',
                     icon_url=self.bot.user.avatar_url)
                 star_mes = await star_channel.send(embed=embed,
                                                    content=mes)
             db.execute(
                 'INSERT INTO starboard (RootMessage, StarMessage) VALUES (?, ?)',
                 message.id, star_mes.id)
             db.commit()
         else:
             star_message = await star_channel.fetch_message(star_message[0]
                                                             )
             try:
                 await star_message.edit(content=mes, embed=embed)
             except discord.errors.HTTPException:
                 embed = discord.Embed(
                     description='[Original Message]({})'.format(
                         message.jump_url),
                     colour=discord.Colour.red()).set_author(
                         icon_url=message.author.avatar_url,
                         name=message.author)
                 embed.set_footer(
                     text='Missing Field, Cannot Load Original Message!',
                     icon_url=self.bot.user.avatar_url)
                 await star_message.edit(embed=embed, content=mes)