Beispiel #1
0
    async def remindme(self, ctx, time: utils.human_timedelta, reminder: str):
        """Schedules a reminder for the future. The bot will send a direct
        message to remind you at the approriate time.

        To avoid abuse, can only schedule events up to 1 year into the future.

        Examples:
            ~remindme 30m Mow the lawn!
            ~remindme 6h Poke Bob about dinner.
            ~remindme 90d Send mom Mother's Day gift.
        """
        if time > timedelta(days=365):
            await ctx.send(
                "Cannot schedule reminders more than 1 year in advance!",
                delete_after=90)

        action = proto.Action()
        action.user_id = ctx.author.id
        action.direct_message.content = f"Reminder: {reminder}"

        scheduled_time = datetime.utcnow() + time
        ctx.bot.action_manager.schedule(scheduled_time, action)
        await ctx.send(
            f"You will be reminded via direct message at {scheduled_time}.",
            delete_after=90)
Beispiel #2
0
    async def apply_rule(self, rule, message, reasons):
        if message.guild is None:
            return

        tasks = []
        action_taken = ""
        mention_mod = rule.notify_moderator
        reasons_block = f"\n```\n{format.vertical_list(reasons)}\n```"
        guild = message.guild

        if rule.notify_moderator:
            action_taken = "Message filter found notable message:"
        if rule.delete_message:
            permissions = message.channel.permissions_for(guild.me)
            if permissions.manage_messages:
                if rule.notify_moderator:
                    action_taken = "Message filter deleted message:"

                dm = (f"[{guild.name}] Your message was deleted for "
                      f"the following reasons: {reasons_block}")

                async def delete():
                    await message.delete()
                    if not message.author.bot and \
                       message.author != self.bot.user:
                        await message.author.send(dm)

                tasks.append(delete())
            else:
                mention_mod = True
                action_taken = (f"Attempted to delete, but don't have "
                                f"`Manage Messages` in "
                                f"{message.channel.mention}.")
        if rule.additional_actions:
            actions = []
            for action_template in rule.additional_actions:
                action = proto.Action()
                action.CopyFrom(action_template)
                action.guild_id = guild.id
                action.user_id = message.author.id
                if not action.HasField('reason'):
                    action.reason = f"Triggered message filter: '{rule.name}'"
                actions.append(action)
            tasks.append(self.bot.action_manager.sequentially_execute(actions))

        if mention_mod or action_taken:
            text = action_taken + reasons_block
            if mention_mod:
                _, mention_text = await utils.mention_random_online_mod(
                    self.bot, guild)
                text = mention_text + " " + text
            embed = embed_utils.message_to_embed(message)
            tasks.append(guild.modlog.send(content=text, embed=embed))

        try:
            await asyncio.gather(*tasks)
        except discord.Forbidden:
            pass
Beispiel #3
0
def invert_action(action: proto.Action) -> proto.Action:
    new_action = proto.Action()
    new_action.CopyFrom(action)

    if action.HasField('reason'):
        new_action.reason = 'Undo: ' + action.reason
    new_action.ClearField('duration')

    try:
        INVERT_MAPPING[action.WhichOneof('details')](new_action)
    except KeyError:
        raise ValueError('Provided action cannot be inverted.')

    return new_action
Beispiel #4
0
def create_action(member):
    return proto.Action(user_id=member.id, guild_id=member.guild.id)