Exemple #1
0
async def remove_channel_mutes(channel, members, **context):
    settings = await db.settings.get(SETTINGS_KEY,
                                     channel.guild,
                                     loader=settings_loader)
    mutes = settings['mute']

    timestamp = datetime.datetime.utcnow().timestamp()

    dirty = False
    for member in members:
        try:
            member_mutes = mutes[member.id]
        except KeyError:
            continue
        try:
            expiration = member_mutes[channel.id]
        except KeyError:
            continue
        del member_mutes[channel.id]
        dirty = True

        if not member_mutes:
            del mutes[member.id]
        if expiration > timestamp:
            messages.bus(member.guild).publish('mute.remove',
                                               channel=channel,
                                               member=member,
                                               **context)
    if dirty:
        await settings.save()
Exemple #2
0
    async def execute(self, message, args):
        if len(args) < 2:
            await self.error('usage', name=self.name)
            return

        if len(message.mentions) != 1:
            await self.error('mention_number')
            return

        member = message.mentions[0]
        if member.top_role >= message.author.top_role:
            await self.error('user_permission', user=member.display_name)
            return

        reason = ' '.join(args[1:])

        try:
            await member.ban(reason=reason, delete_message_days=0)
        except discord.Forbidden:
            await self.error('bot_permission', user=member.display_name)
        else:
            logger.info('banning {member.display_name} [{member.id}]: {reason}'.format(
                        member=member, reason=reason))
            messages.bus(member.guild).publish('ban', user=message.author, member=member, reason=reason)
            await self.send(self.messages['ban'].format(user=member.display_name, reason=reason))
Exemple #3
0
 async def on_member_unban(self, guild, user):
     async for entry in guild.audit_logs(
             limit=5, action=discord.AuditLogAction.unban):
         if entry.target.id == user.id:
             break
     else:
         return
     if entry.user.id != guild.me.id:
         messages.bus(guild).publish('unban', user=entry.user, member=user)
Exemple #4
0
    async def init_guild(self, guild):
        if guild.id in self.guilds:
            return

        settings = await db.settings.get('log', guild)
        objects = []

        for kind, channel_id in settings.get('feeds', {}).items():
            channel = guild.get_channel(channel_id)
            publisher = self.publish_types[kind](guild, channel)
            messages.bus(guild).subscribe(publisher)
            objects.append(publisher)

        self.guilds[guild.id] = objects
Exemple #5
0
async def add_channel_mutes(channel, members, duration, **context):
    settings = await db.settings.get(SETTINGS_KEY,
                                     channel.guild,
                                     loader=settings_loader)
    mutes = settings['mute']

    timestamp = int(datetime.datetime.utcnow().timestamp() + duration)

    for member in members:
        mutes.setdefault(member.id, {})[channel.id] = timestamp
        messages.bus(member.guild).publish('mute.add',
                                           channel=channel,
                                           member=member,
                                           duration=duration,
                                           **context)
    await settings.save()
Exemple #6
0
async def set_readonly(channel, enable, **context):
    settings = await db.settings.get(SETTINGS_KEY,
                                     channel.guild,
                                     loader=settings_loader)
    enabled = channel.id in settings.setdefault('readonly', [])
    if enabled == enable:
        return

    if enable and not channel.permissions_for(
            channel.guild.me).manage_messages:
        raise BotPermissionDenied()

    if enable:
        settings['readonly'].append(channel.id)
    else:
        settings['readonly'].remove(channel.id)
    await settings.save()
    messages.bus(channel.guild).publish('readonly.set',
                                        channel=channel,
                                        enable=enable,
                                        **context)
Exemple #7
0
    async def on_command(self, client, message, name, args, settings, output):
        """ Run the command of the group """

        command = self.commands[name](self, client, output)

        # Check command permissions
        try:
            await self.check_permissions(client, message, command)
        except PermissionDenied as exc:
            if getattr(exc, 'message', None) is not None:
                await output.error(exc.message)
            return

        # Run command and handle errors
        logger.info('{user} [{userid}] runs {name} {args}'.format(
            user=message.author.name,
            userid=message.author.id,
            name=name,
            args=' '.join(shlex.quote(arg) for arg in args),
        ))
        messages.bus(message.channel.guild).publish('command.run',
                                                    command=command,
                                                    name=name,
                                                    args=args,
                                                    message=message,
                                                    user=message.author)

        try:
            await command.execute(message, args)
        except asyncio.CancelledError:
            raise
        except Exception:
            logger.exception(
                'Execution of command "{name}" with arguments ({args}) raised unhandled exception'
                .format(name=name, args=', '.join(repr(arg) for arg in args)))
            await output.error('Internal error')
Exemple #8
0
 async def __call__(self, message):
     await self.channel.send(
         content=message.content,
         embed=message.embeds[0] if message.embeds else None,
     )
     messages.bus(self.guild).publish('action.copy', message=message, channel=self.channel)
Exemple #9
0
 async def __call__(self, message, context=None):
     await message.author.add_roles(self.role, reason=self.reason)
     self.logger.info('granted role {guild.name} → {role.name} to {user.name} [{user.id}]'.format(
                      guild=self.guild, role=self.role, user=message.author))
     messages.bus(self.guild).publish('action.grant_role', member=message.author,
                                      role=self.role, reason=self.reason)
Exemple #10
0
 async def __call__(self, message, context=None):
     await message.pin()
     messages.bus(self.guild).publish('action.pin', message=message)