Beispiel #1
0
    async def set_mute_duration(self, ctx, time: str = None):
        '''Set the default mute duration.'''
        guild = ctx.guild
        author = ctx.author
        mute_duration = await read('md')

        if time is None:
            if guild.id in mute_duration:
                seconds = mute_duration[guild.id]
                await ctx.send(
                    f'The current default mute duration is `{seconds}`')
            else:
                await ctx.send('No default mute duration set!')

        else:
            try:
                seconds = int(time)
                found_time = True

            except ValueError:
                found_time = False

            try:
                if not found_time:
                    time = find_date(time)
                    seconds = time.total_seconds()
                mute_duration[guild.id] = seconds
                await write('md', mute_duration)
                await self.log(
                    ctx,
                    f'<@{author.id}> set the default mute duration to {time}')

            except InvalidDate:
                await ctx.send(f'Invalid ammount of time, `{time}`.')
    async def mute(self, ctx, user: discord.Member, time=None, *argv):
        '''Mute a user so that they cannot send messages anymore.
        ```css
        Example Usage:
        ``````css
        ?mute <user> 5d bc i can // Mutes <user> for 5 days with the reason because i can.
        ``````css
        ?mute <user> bc i can // Mutes <user> permanately for reason bc i can
        ```'''

        fields = []
        guild = ctx.guild
        if time is not None:
            try:
                duration = find_date(time)
                end_date = duration + datetime.now()

                end_date = end_date.strftime('%Y-%m-%w-%W %H:%M:%S')
                mute_list = await read('muteList')
                if str(guild.id) in mute_list:
                    guild_list = mute_list[str(guild.id)]
                else:
                    guild_list = {}
                guild_list[user.id] = end_date

                mute_list[str(guild.id)] = guild_list
                await write('muteList', mute_list)
                fields.append(('**Duration:**', f'`{time}`', True))
            except InvalidDate:
                argv = list(argv)
                argv.insert(0, time)

        author = ctx.author
        if len(argv) > 0:
            reason = ' '.join(argv)
            fields.append(('**Reason:**', reason, True))

        await self.log(ctx,
                       f'<@{author.id}> muted <@{user.id}>',
                       fields=fields,
                       showauth=True)
        muted_role = await get_muted_role(guild)
        await user.add_roles(muted_role)
        embed = discord.Embed(title='**Mute**',
                              description=f'<@{user.id}> has been muted.',
                              color=0xff0000)
        await ctx.send(embed=embed)
    async def ban(self, ctx, user: discord.Member, time=None, *argv):
        '''Ban a user.
        ```css
        Example Usage:
        ```
        ```css
        ?ban <user> bc i can// Bans <user> from the guild for the reason bc i can
        ``````css
        ?ban <user> 5d bc i can // Bans <user> for 5 days with the reason bc i can'''
        fields = []
        guild = ctx.guild
        if time is not None:
            try:
                duration = find_date(time)
                end_date = duration + datetime.now()

                end_date.strftime('%Y-%m-%w-%W %H:%M:%S')
                ban_list = await read('banList')
                if guild.id in ban_list:
                    guild_list = ban_list[guild.id]
                else:
                    guild_list = {}
                guild_list[user.id] = end_date
                ban_list[guild.id] = guild_list
                await write('banList', ban_list)
                fields.append(('**Duration:**', f'`{time}`', True))
            except InvalidDate:
                argv = list(argv)
                argv.insert(0, time)

        author = ctx.author
        if len(argv) > 0:
            reason = ' '.join(argv)
            fields.append(('**Reason:**', reason, True))

        await self.log(ctx,
                       f'<@{author.id}> banned <@{user.id}>',
                       fields=fields,
                       showauth=True)
        embed = discord.Embed(title='**Ban**',
                              description=f'<@{user.id}> has been banned.',
                              color=0xff0000)
        await user.ban()
        await ctx.send(embed=embed)
Beispiel #4
0
def log_offense(author, guild, duration, message):
    full_offense_dict = spam_chart.read_cache("spamChart")
    guild_id = guild.id
    user = author.id
    timedelta = find_date(f"{str(duration)}s")
    date = datetime.datetime.now() + timedelta
    date = date.strftime("%Y-%m-%w-%W %H:%M:%S")
    if guild_id in full_offense_dict:
        guild_dict = full_offense_dict[guild.id]
    else:
        guild_dict = {}
    if user in guild_dict:
        user_dict = guild_dict[user]
    else:
        user_dict = []
    item = [author, message, guild, date]
    user_dict.append(item)
    guild_dict[user] = user_dict
    full_offense_dict[guild_id] = guild_dict
    spam_chart.cache("spamChart", full_offense_dict)

    return (len(user_dict))
Beispiel #5
0
	def __init__(self, user_id, mod_id, guild_id):

		self.user_id = user_id
		self.guild_id = guild_id
		self.mod_id = mod_id
		self.expire_date = find_date('5h')