Пример #1
0
    async def delete(self, ctx: commands.Context, inf_id: int):
        """inf_delete_help"""
        infraction = Infraction.get_or_none(id=inf_id, guild_id=ctx.guild.id)
        if infraction is None:
            await ctx.send(
                f"{Emoji.get_chat_emoji('NO')} {Translator.translate('inf_not_found', ctx.guild.id, id=inf_id)}"
            )
        else:
            reason = infraction.reason
            target = await Utils.get_user(infraction.user_id)
            mod = await Utils.get_user(infraction.mod_id)

            async def yes():
                infraction.delete_instance()
                key = f"{ctx.guild.id}_{infraction.user_id}"
                if key in InfractionUtils.cache.keys():
                    del InfractionUtils.cache[key]
                await GearbotLogging.send_to(ctx,
                                             "YES",
                                             "inf_delete_deleted",
                                             id=inf_id)
                GearbotLogging.log_to(
                    ctx.guild.id, "MOD_ACTIONS",
                    f":wastebasket: {Translator.translate('inf_delete_log', ctx.guild.id, id=inf_id, target=str(target), target_id=target.id, mod=str(mod), mod_id=mod.id, reason=reason, user=str(ctx.author), user_id=ctx.author.id)}"
                )

            await Confirmation.confirm(
                ctx,
                text=
                f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('inf_delete_confirmation', ctx.guild.id, id=inf_id, user=str(target), user_id=target.id, reason=reason)}",
                on_yes=yes)
Пример #2
0
 async def on_member_join(self, member: discord.Member):
     now = datetime.datetime.fromtimestamp(time.time())
     if Infraction.get_or_none(Infraction.type == "Mute",
                               Infraction.active == True,
                               Infraction.end >= now,
                               Infraction.guild_id == member.guild.id,
                               Infraction.user_id == member.id):
         roleid = Configuration.get_var(member.guild.id, "MUTE_ROLE")
         if roleid is not 0:
             role = member.guild.get_role(roleid)
             if role is not None:
                 if member.guild.me.guild_permissions.manage_roles:
                     await member.add_roles(role,
                                            reason=Translator.translate(
                                                'mute_reapply_reason',
                                                member.guild.id))
                     GearbotLogging.log_to(
                         member.guild.id, "MOD_ACTIONS",
                         f"{Emoji.get_chat_emoji('MUTE')} {Translator.translate('mute_reapply_log', member.guild.id, user=Utils.clean_user(member), user_id=member.id)}"
                     )
                 else:
                     GearbotLogging.log_to(
                         member.guild.id, "MOD_ACTIONS",
                         Translator.translate('mute_reapply_failed_log',
                                              member.build.id))
Пример #3
0
 async def convert(self, ctx, argument):
     try:
         argument = int(argument)
     except ValueError:
         raise TranslatedBadArgument('NaN', ctx)
     infraction = Infraction.get_or_none(id=argument, guild_id=ctx.guild.id)
     if infraction is None:
         raise TranslatedBadArgument('inf_not_found', ctx, id=argument)
     else:
         return infraction
Пример #4
0
 async def mute_punishment(self, v: Violation):
     duration = v.bucket["PUNISHMENT"]["DURATION"]
     until = time.time() + duration
     reason = self.assemble_reason(v)
     role = AntiSpam._get_mute_role(v.guild)
     i = Infraction.get_or_none((Infraction.user_id == v.member.id)
                                & (Infraction.type == "Mute")
                                & (Infraction.guild_id == v.member.guild.id)
                                & Infraction.active)
     if i is None:
         i = InfractionUtils.add_infraction(v.guild.id,
                                            v.member.id,
                                            self.bot.user.id,
                                            'Mute',
                                            reason,
                                            end=until)
         try:
             await v.member.add_roles(role, reason=reason)
         except Forbidden:
             GearbotLogging.log_key(v.guild.id,
                                    'mute_punishment_failure',
                                    user=Utils.clean_user(v.member),
                                    user_id=v.member.id,
                                    duration=Utils.to_pretty_time(
                                        duration, v.guild.id),
                                    reason=reason,
                                    inf=i.id)
         else:
             GearbotLogging.log_key(v.guild.id,
                                    'mute_log',
                                    user=Utils.clean_user(v.member),
                                    user_id=v.member.id,
                                    moderator=Utils.clean_user(v.guild.me),
                                    moderator_id=v.guild.me.id,
                                    duration=Utils.to_pretty_time(
                                        duration, v.guild.id),
                                    reason=reason,
                                    inf=i.id)
     else:
         i.end += datetime.timedelta(seconds=duration)
         i.reason += f'+ {reason}'
         i.save()
         GearbotLogging.log_key(v.guild.id,
                                'mute_duration_extended_log',
                                user=Utils.clean_user(v.member),
                                user_id=v.member.id,
                                moderator=Utils.clean_user(v.guild.me),
                                moderator_id=v.guild.me.id,
                                duration=Utils.to_pretty_time(
                                    duration, v.guild.id),
                                reason=reason,
                                inf_id=i.id,
                                end=i.end)
         InfractionUtils.clear_cache(v.guild.id)
Пример #5
0
 async def update(self, ctx:commands.Context, inf_id:int, *, reason:str):
     """inf_update_help"""
     infraction = Infraction.get_or_none(id=inf_id, guild_id=ctx.guild.id)
     if infraction is None:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('inf_not_found', ctx.guild.id, id=inf_id)}")
     else:
         infraction.mod_id = ctx.author.id
         infraction.reason = reason
         infraction.save()
         if f"{ctx.guild.id}_{infraction.user_id}" in InfractionUtils.cache.keys():
             del InfractionUtils.cache[f"{ctx.guild.id}_{infraction.user_id}"]
         await ctx.send(f"{Emoji.get_chat_emoji('YES')} {Translator.translate('inf_updated', ctx.guild.id, id=inf_id)}")