Example #1
0
 async def unban(self, ctx, member: BannedMember, *, reason: Reason = ""):
     """unban_help"""
     if reason == "":
         reason = Translator.translate("no_reason", ctx.guild.id)
     fid = f"{ctx.guild.id}-{member.user.id}"
     self.bot.data["unbans"].add(fid)
     try:
         await ctx.guild.unban(
             member.user,
             reason=Utils.trim_message(
                 f"Moderator: {ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) Reason: {reason}",
                 500))
     except Exception as e:
         self.bot.data["unbans"].remove(fid)
         raise e
     Infraction.update(active=False).where(
         (Infraction.user_id == member.user.id) & (Infraction.type == "Ban")
         & (Infraction.guild_id == ctx.guild.id)).execute()
     InfractionUtils.add_infraction(ctx.guild.id, member.user.id,
                                    ctx.author.id, "Unban", reason)
     await ctx.send(
         f"{Emoji.get_chat_emoji('YES')} {Translator.translate('unban_confirmation', ctx.guild.id, user=Utils.clean_user(member.user), user_id=member.user.id, reason=reason)}"
     )
     GearbotLogging.log_to(
         ctx.guild.id, "MOD_ACTIONS",
         f"{Emoji.get_chat_emoji('INNOCENT')} {Translator.translate('unban_log', ctx.guild.id, user=Utils.clean_user(member.user), user_id=member.user.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id, reason=reason)}"
     )
Example #2
0
 async def on_member_ban(self, guild, user):
     if user.id == self.bot.user.id or not Features.is_logged(guild.id, "MOD_ACTIONS"): return
     fid = f"{guild.id}-{user.id}"
     if fid in self.bot.data["forced_exits"]:
         return
     self.bot.data["forced_exits"].add(fid)
     Infraction.update(active=False).where((Infraction.user_id == user.id) &
                                           (Infraction.type == "Unban") &
                                           (Infraction.guild_id == guild.id)).execute()
     limit = datetime.datetime.utcfromtimestamp(time.time() - 60)
     log = await self.find_log(guild, AuditLogAction.ban, lambda e: e.target == user and e.created_at > limit)
     if log is None:
         await asyncio.sleep(1) #is the api having a fit or so?
         #this fails way to often for my liking, alternative is adding a delay but this seems to do the trick for now
         log = await self.find_log(guild, AuditLogAction.ban, lambda e: e.target == user and e.created_at > limit)
     if log is not None:
         if log.reason is None:
             reason = Translator.translate("no_reason", guild.id)
         else:
             reason = log.reason
         i = InfractionUtils.add_infraction(guild.id, log.target.id, log.user.id, "Ban", reason)
         GearbotLogging.log_key(guild.id, 'ban_log', user=Utils.clean_user(user), user_id=user.id, moderator=Utils.clean_user(log.user), moderator_id=log.user.id, reason=reason, inf=i.id)
     else:
         i = InfractionUtils.add_infraction(guild.id, user.id, 0, "Ban", "Manual ban")
         GearbotLogging.log_key(guild.id, 'manual_ban_log', user=Utils.clean_user(user), user_id=user.id, inf=i.id)
Example #3
0
 async def _kick(self, ctx, user, reason, confirm):
     self.bot.data["forced_exits"].add(f"{ctx.guild.id}-{user.id}")
     await ctx.guild.kick(
         user,
         reason=Utils.trim_message(
             f"Moderator: {ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) Reason: {reason}",
             500))
     translated = Translator.translate('kick_log',
                                       ctx.guild.id,
                                       user=Utils.clean_user(user),
                                       user_id=user.id,
                                       moderator=Utils.clean_user(
                                           ctx.author),
                                       moderator_id=ctx.author.id,
                                       reason=reason)
     GearbotLogging.log_to(ctx.guild.id, "MOD_ACTIONS",
                           f":boot: {translated}")
     InfractionUtils.add_infraction(ctx.guild.id,
                                    user.id,
                                    ctx.author.id,
                                    Translator.translate(
                                        'kick', ctx.guild.id),
                                    reason,
                                    active=False)
     if confirm:
         await GearbotLogging.send_to(ctx,
                                      "YES",
                                      "kick_confirmation",
                                      ctx.guild.id,
                                      user=Utils.clean_user(user),
                                      user_id=user.id,
                                      reason=reason)
Example #4
0
    async def on_member_unban(self, guild, user):
        fid = f"{guild.id}-{user.id}"
        if fid in self.bot.data["unbans"]:
            self.bot.data["unbans"].remove(fid)
            return
        elif not Features.is_logged(guild.id, "MOD_ACTIONS"):
            return
        Infraction.update(active=False).where((Infraction.user_id == user.id) &
                                              (Infraction.type == "Ban") &
                                              (Infraction.guild_id == guild.id)).execute()

        limit = datetime.datetime.utcfromtimestamp(time.time() - 60)
        log = await self.find_log(guild, AuditLogAction.unban, lambda e: e.target == user and e.created_at > limit)
        if log is None:
            # this fails way to often for my liking, alternative is adding a delay but this seems to do the trick for now
            log = await self.find_log(guild, AuditLogAction.unban, lambda e: e.target == user and e.created_at > limit)
        if log is not None:
            i = InfractionUtils.add_infraction(guild.id, user.id, log.user.id, "Unban", "Manual unban")
            GearbotLogging.log_key(guild.id, 'unban_log', user=Utils.clean_user(user), user_id=user.id,
                                   moderator=log.user, moderator_id=log.user.id, reason='Manual unban', inf=i.id)


        else:
            i = InfractionUtils.add_infraction(guild.id, user.id, 0, "Unban", "Manual ban")
            GearbotLogging.log_key(guild.id, 'manual_unban_log', user=Utils.clean_user(user), user_id=user.id, inf=i.id)
Example #5
0
 async def mute(self,
                ctx: commands.Context,
                target: discord.Member,
                durationNumber: int,
                durationIdentifier: Duration,
                *,
                reason: Reason = ""):
     """mute_help"""
     if reason == "":
         reason = Translator.translate("no_reason", ctx.guild.id)
     roleid = Configuration.get_var(ctx.guild.id, "MUTE_ROLE")
     if roleid is 0:
         await ctx.send(
             f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('mute_not_configured', ctx.guild.id, user=target.mention)}"
         )
     else:
         role = ctx.guild.get_role(roleid)
         if role is None:
             await ctx.send(
                 f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('mute_role_missing', ctx.guild.id, user=target.mention)}"
             )
         else:
             if (ctx.author != target and target != ctx.bot.user
                     and ctx.author.top_role > target.top_role
                 ) or ctx.guild.owner == ctx.author:
                 duration = Utils.convertToSeconds(durationNumber,
                                                   durationIdentifier)
                 if duration > 0:
                     until = time.time() + duration
                     await target.add_roles(
                         role,
                         reason=Utils.trim_message(
                             f"Moderator: {ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) Reason: {reason}",
                             500))
                     InfractionUtils.add_infraction(ctx.guild.id,
                                                    target.id,
                                                    ctx.author.id,
                                                    "Mute",
                                                    reason,
                                                    end=until)
                     await ctx.send(
                         f"{Emoji.get_chat_emoji('MUTE')} {Translator.translate('mute_confirmation', ctx.guild.id, user=Utils.clean_user(target), duration=f'{durationNumber} {durationIdentifier}')}"
                     )
                     GearbotLogging.log_to(
                         ctx.guild.id, "MOD_ACTIONS",
                         f"{Emoji.get_chat_emoji('MUTE')} {Translator.translate('mute_log', ctx.guild.id, user=Utils.clean_user(target), user_id=target.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id, duration=f'{durationNumber} {durationIdentifier}', reason=reason)}"
                     )
                 else:
                     await ctx.send(
                         f"{Emoji.get_chat_emoji('WHAT')} {Translator.translate('mute_negative_denied', ctx.guild.id, duration=f'{durationNumber} {durationIdentifier}')} {Emoji.get_chat_emoji('WHAT')}"
                     )
             else:
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('NO')} {Translator.translate('mute_not_allowed', ctx.guild.id, user=target)}"
                 )
Example #6
0
 async def mute(self,
                ctx: commands.Context,
                target: discord.Member,
                durationNumber: int,
                durationIdentifier: str,
                *,
                reason=""):
     """mute_help"""
     if reason == "":
         reason = Translator.translate("no_reason", ctx.guild.id)
     roleid = Configuration.getConfigVar(ctx.guild.id, "MUTE_ROLE")
     if roleid is 0:
         await ctx.send(
             f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('mute_not_configured', ctx.guild.id, user=target.mention)}"
         )
     else:
         role = discord.utils.get(ctx.guild.roles, id=roleid)
         if role is None:
             await ctx.send(
                 f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('mute_role_missing', ctx.guild.id, user=target.mention)}"
             )
         else:
             if (ctx.author != target and target != ctx.bot.user
                     and ctx.author.top_role > target.top_role
                 ) or ctx.guild.owner == ctx.author:
                 duration = Utils.convertToSeconds(durationNumber,
                                                   durationIdentifier)
                 if duration > 0:
                     until = time.time() + duration
                     await target.add_roles(
                         role,
                         reason=
                         f"{reason}, as requested by {ctx.author.name}")
                     if not str(ctx.guild.id) in self.mutes:
                         self.mutes[str(ctx.guild.id)] = dict()
                     self.mutes[str(ctx.guild.id)][str(target.id)] = until
                     await ctx.send(
                         f"{Emoji.get_chat_emoji('MUTE')} {Translator.translate('mute_confirmation', ctx.guild.id, user=Utils.clean_user(target), duration=f'{durationNumber} {durationIdentifier}')}"
                     )
                     Utils.saveToDisk("mutes", self.mutes)
                     await GearbotLogging.logToModLog(
                         ctx.guild,
                         f"{Emoji.get_chat_emoji('MUTE')} {Translator.translate('mute_log', ctx.guild.id, user=Utils.clean_user(target), user_id=target.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id, duration=f'{durationNumber} {durationIdentifier}', reason=reason)}"
                     )
                     InfractionUtils.add_infraction(ctx.guild.id, target.id,
                                                    ctx.author.id, "Mute",
                                                    reason)
                 else:
                     await ctx.send(
                         f"{Emoji.get_chat_emoji('WHAT')} {Translator.translate('mute_negative_denied', ctx.guild.id, duration=f'{durationNumber} {durationIdentifier}')} {Emoji.get_chat_emoji('WHAT')}"
                     )
             else:
                 await ctx.send(
                     f"{Emoji.get_chat_emoji('NO')} {Translator.translate('mute_not_allowed', ctx.guild.id, user=target)}"
                 )
Example #7
0
 async def unban(self, ctx, member: BannedMember, *, reason=""):
     """unban_help"""
     if reason == "":
         reason = Translator.translate("no_reason", ctx.guild.id)
     self.bot.data["unbans"].append(member.user.id)
     await ctx.guild.unban(member.user, reason=f"Moderator: {ctx.author.name} ({ctx.author.id}) Reason: {reason}")
     await ctx.send(
         f"{Emoji.get_chat_emoji('YES')} {Translator.translate('unban_confirmation', ctx.guild.id, user=Utils.clean_user(member.user), user_id=member.user.id)}")
     await GearbotLogging.logToModLog(ctx.guild,
                                      f"{Emoji.get_chat_emoji('INNOCENT')} {Translator.translate('unban_log', ctx.guild.id, user=Utils.clean_user(member.user), user_id=member.user.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id)}")
     InfractionUtils.add_infraction(ctx.guild.id, member.user.id, ctx.author.id, "Unban", reason)
Example #8
0
 async def warn(self, ctx:commands.Context, member:discord.Member, *, reason:str):
     """warn_help"""
     if (ctx.author != member and member != ctx.bot.user and ctx.author.top_role > member.top_role) or ctx.guild.owner == ctx.author:
         if len(reason) > 1800:
             await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('warning_to_long', ctx.guild.id)}")
         else:
             InfractionUtils.add_infraction(ctx.guild.id, member.id, ctx.author.id, "Warn", reason)
             name = Utils.clean_user(member)
             await ctx.send(f"{Emoji.get_chat_emoji('YES')} {Translator.translate('warning_added', ctx.guild.id, user=name)}")
             aname = Utils.clean_user(ctx.author)
             await GearbotLogging.logToModLog(ctx.guild, f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('warning_added', ctx.guild.id, user=name, moderator=aname)}")
     else:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('warning_added', ctx.guild.id, user=ctx.author)}")
Example #9
0
    async def tempban(self,
                      ctx: commands.Context,
                      user: discord.Member,
                      durationNumber: int,
                      durationIdentifier: Duration,
                      *,
                      reason: Reason = ""):
        """ban_help"""
        if reason == "":
            reason = Translator.translate("no_reason", ctx.guild.id)

        allowed, message = self._can_act("ban", ctx, user)
        if allowed:
            duration = Utils.convertToSeconds(durationNumber,
                                              durationIdentifier)
            if duration > 0:
                until = time.time() + duration
                self.bot.data["forced_exits"].add(f"{ctx.guild.id}-{user.id}")
                await ctx.guild.ban(
                    user,
                    reason=Utils.trim_message(
                        f"Moderator: {ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) Reason: {reason}",
                        500),
                    delete_message_days=0)
                InfractionUtils.add_infraction(ctx.guild.id,
                                               user.id,
                                               ctx.author.id,
                                               "Tempban",
                                               reason,
                                               end=until)
                translated = Translator.translate(
                    'tempban_log',
                    ctx.guild.id,
                    user=Utils.clean_user(user),
                    user_id=user.id,
                    moderator=Utils.clean_user(ctx.author),
                    moderator_id=ctx.author.id,
                    reason=reason,
                    until=datetime.datetime.utcfromtimestamp(until))
                GearbotLogging.log_to(ctx.guild.id, "MOD_ACTIONS",
                                      f":door: {translated}")
                await GearbotLogging.send_to(
                    ctx,
                    "YES",
                    "tempban_confirmation",
                    user=Utils.clean_user(user),
                    user_id=user.id,
                    reason=reason,
                    until=datetime.datetime.utcfromtimestamp(until))
        else:
            await GearbotLogging.send_to(ctx, "NO", message, translate=False)
Example #10
0
 async def warn_punishment(self, v: Violation):
     reason = self.assemble_reason(v)
     i = InfractionUtils.add_infraction(v.guild.id, v.member.id,
                                        self.bot.user.id, 'Warn', reason)
     GearbotLogging.log_key(v.guild.id,
                            'warning_added_modlog',
                            user=Utils.clean_user(v.member),
                            moderator=Utils.clean_user(v.guild.me),
                            reason=reason,
                            user_id=v.member.id,
                            moderator_id=v.guild.me.id,
                            inf=i.id)
     try:
         dm_channel = await v.member.create_dm()
         await dm_channel.send(
             MessageUtils.assemble(dm_channel,
                                   'WARNING',
                                   'warning_dm',
                                   server=v.member.guild.name) +
             f"```{reason}```")
     except Forbidden:
         GearbotLogging.log_key(v.member.guild.id,
                                'warning_could_not_dm',
                                user=Utils.escape_markdown(v.member.name),
                                userid=v.member.id)
Example #11
0
 async def kick_punishment(self, v: Violation):
     reason = self.assemble_reason(v)
     i = InfractionUtils.add_infraction(v.guild.id,
                                        v.member.id,
                                        self.bot.user.id,
                                        'Kick',
                                        reason,
                                        active=False)
     self.bot.data["forced_exits"].add(f"{v.guild.id}-{v.member.id}")
     try:
         await v.guild.kick(v.member, reason=reason)
     except Forbidden:
         GearbotLogging.log_key(v.guild.id,
                                'kick_punishment_failure',
                                user=Utils.clean_user(v.member),
                                user_id=v.member.id,
                                moderator=Utils.clean_user(v.guild.me),
                                moderator_id=v.guild.me.id,
                                reason=reason,
                                inf=i.id)
     else:
         GearbotLogging.log_key(v.guild.id,
                                'kick_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,
                                reason=reason,
                                inf=i.id)
Example #12
0
    async def on_member_remove(self, member: discord.Member):
        if member.id == self.bot.user.id: return
        exits = self.bot.data["forced_exits"]
        fid = f"{member.guild.id}-{member.id}"
        if fid in exits:
            exits.remove(fid)
            return
        if member.guild.me.guild_permissions.view_audit_log and Features.is_logged(member.guild.id, "MOD_ACTIONS"):
            try:
                async for entry in member.guild.audit_logs(action=AuditLogAction.kick, limit=25):
                    if member.joined_at is None or member.joined_at > entry.created_at or entry.created_at < datetime.datetime.utcfromtimestamp(
                             time.time() - 30):
                        break
                    if entry.target == member:
                        if entry.reason is None:
                            reason = Translator.translate("no_reason", member.guild.id)
                        else:
                            reason = entry.reason
                        i = InfractionUtils.add_infraction(member.guild.id, entry.target.id, entry.user.id, "Kick", reason,
                                                       active=False)
                        GearbotLogging.log_key(member.guild.id, 'kick_log', user=Utils.clean_user(member), user_id=member.id, moderator=Utils.clean_user(entry.user), moderator_id=entry.user.id, reason=reason, inf=i.id)
                        return
            except discord.Forbidden:
                permissions = member.guild.me.guild_permissions
                perm_info = ", ".join(f"{name}: {value}" for name, value in permissions)
                await GearbotLogging.bot_log(
                    f"{Emoji.get_chat_emoji('WARNING')} Tried to fetch audit log for {member.guild.name} ({member.guild.id}) but got denied even though it said i have access, guild permissions: ```{perm_info}```")

        if Features.is_logged(member.guild.id, "TRAVEL_LOGS"):
            GearbotLogging.log_key(member.guild.id, 'leave_logging', user=Utils.clean_user(member), user_id=member.id)
Example #13
0
    async def warn(self, ctx: commands.Context, member: discord.Member, *, reason: Reason):
        """warn_help"""
        if ctx.author != member and (ctx.author.top_role > member.top_role or ctx.guild.owner == ctx.author):
            if member.id == self.bot.user.id:
                async def yes():
                    channel = self.bot.get_channel(Configuration.get_master_var("inbox", 0))
                    if channel is not None:
                        await channel.send(f"[`{ctx.message.created_at.strftime('%c')}`] {ctx.message.author} (`{ctx.message.author.id}`) submitted feedback: {reason}")
                        await MessageUtils.send_to(ctx, 'YES', 'feedback_submitted')

                message = MessageUtils.assemble(ctx, "THINK", "warn_to_feedback")
                await Confirmation.confirm(ctx, message, on_yes=yes)
            else:
                if member.bot:
                    await MessageUtils.send_to(ctx, "THINK", "cant_warn_bot")
                    return

                i = InfractionUtils.add_infraction(ctx.guild.id, member.id, ctx.author.id, "Warn", reason)
                name = Utils.clean_user(member)
                await MessageUtils.send_to(ctx, 'YES', 'warning_added', user=name, inf=i.id)
                aname = Utils.clean_user(ctx.author)
                GearbotLogging.log_key(ctx.guild.id, 'warning_added_modlog', user=name, moderator=aname, reason=reason,
                                       user_id=member.id, moderator_id=ctx.author.id, inf=i.id)
                if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_WARN"):
                    try:
                        dm_channel = await member.create_dm()
                        await dm_channel.send(
                            f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('warning_dm', ctx.guild.id, server=ctx.guild.name)}```{reason}```")
                    except discord.Forbidden:
                        GearbotLogging.log_key(ctx.guild.id, 'warning_could_not_dm', user=name,
                                               userid=member.id)
        else:
            await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('warning_not_allowed', ctx.guild.id, user=member)}")
Example #14
0
 async def _warn(ctx, target, *, reason, message=True):
     i = InfractionUtils.add_infraction(ctx.guild.id, target.id,
                                        ctx.author.id, "Warn", reason)
     name = Utils.clean_user(target)
     if message:
         await MessageUtils.send_to(ctx,
                                    'YES',
                                    'warning_added',
                                    user=name,
                                    inf=i.id)
     aname = Utils.clean_user(ctx.author)
     GearbotLogging.log_key(ctx.guild.id,
                            'warning_added_modlog',
                            user=name,
                            moderator=aname,
                            reason=reason,
                            user_id=target.id,
                            moderator_id=ctx.author.id,
                            inf=i.id)
     if Configuration.get_var(ctx.guild.id, "INFRACTIONS", "DM_ON_WARN"):
         try:
             dm_channel = await target.create_dm()
             await dm_channel.send(
                 f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('warning_dm', ctx.guild.id, server=ctx.guild.name)}```{reason}```"
             )
         except discord.Forbidden:
             GearbotLogging.log_key(ctx.guild.id,
                                    'warning_could_not_dm',
                                    user=name,
                                    userid=target.id)
Example #15
0
 async def execute(self, bot, member, data, raid_id, raider_ids, shield):
     bot.data["forced_exits"].add(f"{member.guild.id}-{member.id}")
     reason = f"Raider banned by raid shield {shield['name']} in raid {raid_id}"
     try:
         await member.ban(
             reason=reason,
             delete_message_days=1 if data["clean_messages"] else 0)
     except Forbidden:
         log(member.guild.id,
             'raid_ban_forbidden',
             shield,
             user_name=Utils.escape_markdown(member),
             user_id=member.id)
     except Exception as ex:
         log(member.guild.id,
             'raid_ban_unknown_error',
             shield,
             user_name=Utils.escape_markdown(member),
             user_id=member.id)
         await TheRealGearBot.handle_exception('RAID BAN FAILURE', bot, ex)
     finally:
         i = InfractionUtils.add_infraction(member.guild.id, member.id,
                                            bot.user.id, "Ban", reason)
         GearbotLogging.log_key(member.guild.id,
                                'ban_log',
                                user=Utils.clean_user(member),
                                user_id=member.id,
                                moderator=Utils.clean_user(bot.user),
                                moderator_id=bot.user.id,
                                reason=reason,
                                inf=i.id)
Example #16
0
 async def ban(self, ctx: commands.Context, user: discord.Member, *, reason=""):
     """ban_help"""
     if reason == "":
         reason = Translator.translate("no_reason", ctx.guild.id)
     if (ctx.author != user and user != ctx.bot.user and ctx.author.top_role > user.top_role) or ctx.guild.owner == ctx.author:
         if ctx.me.top_role > user.top_role:
             self.bot.data["forced_exits"].append(user.id)
             await ctx.guild.ban(user, reason=f"Moderator: {ctx.author.name} ({ctx.author.id}) Reason: {reason}",
                                 delete_message_days=0)
             await ctx.send(
                 f"{Emoji.get_chat_emoji('YES')} {Translator.translate('ban_confirmation', ctx.guild.id, user=Utils.clean_user(user), user_id=user.id, reason=reason)}")
             await GearbotLogging.logToModLog(ctx.guild,
                                              f":door: {Translator.translate('ban_log', ctx.guild.id, user=Utils.clean_user(user), user_id=user.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id, reason=reason)}")
             InfractionUtils.add_infraction(ctx.guild.id, user.id, ctx.author.id, "Ban", reason)
         else:
             await ctx.send(Translator.translate('ban_unable', ctx.guild.id, user=Utils.clean_user(user)))
     else:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('ban_not_allowed', ctx.guild.id, user=user)}")
Example #17
0
 async def forceban(self, ctx: commands.Context, user_id: int, *, reason=""):
     """purge_help"""
     if reason == "":
         reason = Translator.translate("no_reason", ctx.guild.id)
     try:
         member = await commands.MemberConverter().convert(ctx, str(user_id))
     except BadArgument:
         user = await ctx.bot.get_user_info(user_id)
         await ctx.guild.ban(user, reason=f"Moderator: {ctx.author.name} ({ctx.author.id}) Reason: {reason}",
                             delete_message_days=0)
         await ctx.send(
             f"{Emoji.get_chat_emoji('YES')} {Translator.translate('forceban_confirmation', ctx.guild.id, user=Utils.clean_user(user), reason=reason)}")
         await GearbotLogging.logToModLog(ctx.guild,
                                          f":door: {Translator.translate('forceban_log', ctx.guild.id, user=Utils.clean_user(user), user_id=user.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id, reason=reason)}")
         InfractionUtils.add_infraction(ctx.guild.id, user.id, ctx.author.id, Translator.translate('forced_ban', ctx.guild.id), reason)
     else:
         await ctx.send(f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('forceban_to_ban', ctx.guild.id)}")
         await ctx.invoke(self.ban, member, reason=reason)
Example #18
0
 async def kick(self, ctx, user: discord.Member, *, reason=""):
     """kick_help"""
     if reason == "":
         reason = Translator.translate("no_reason", ctx.guild.id)
     self.bot.data["forced_exits"].append(user.id)
     if (ctx.author != user and user != ctx.bot.user and ctx.author.top_role > user.top_role) or ctx.guild.owner == ctx.author:
         if ctx.me.top_role > user.top_role:
             await ctx.guild.kick(user,
                                  reason=f"Moderator: {ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) Reason: {reason}")
             await ctx.send(
                 f"{Emoji.get_chat_emoji('YES')} {Translator.translate('kick_confirmation', ctx.guild.id, user=Utils.clean_user(user), user_id=user.id, reason=reason)}")
             await GearbotLogging.logToModLog(ctx.guild,
                                              f":boot: {Translator.translate('kick_log', ctx.guild.id, user=Utils.clean_user(user), user_id=user.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id, reason=reason)}")
             InfractionUtils.add_infraction(ctx.guild.id, user.id, ctx.author.id, Translator.translate('kick', ctx.guild.id), reason)
         else:
             await ctx.send(Translator.translate('kick_unable',ctx.guild.id, user=Utils.clean_user(user)))
     else:
         await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('kick_not_allowed', ctx.guild.id, user=user)}")
Example #19
0
 async def unmute(self, ctx: commands.Context, target: discord.Member, *, reason=""):
     """unmute_help"""
     if reason == "":
         reason = Translator.translate("no_reason", ctx.guild.id)
     roleid = Configuration.getConfigVar(ctx.guild.id, "MUTE_ROLE")
     if roleid is 0:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} The mute feature has been disabled on this server, as such i cannot unmute that person")
     else:
         role = discord.utils.get(ctx.guild.roles, id=roleid)
         if role is None:
             await ctx.send(
                 f"{Emoji.get_chat_emoji('NO')} Unable to comply, the role i've been told to use for muting no longer exists")
         else:
             await target.remove_roles(role, reason=f"Unmuted by {ctx.author.name}, {reason}")
             await ctx.send(f"{Emoji.get_chat_emoji('INNOCENT')} {target.display_name} has been unmuted")
             await GearbotLogging.logToModLog(ctx.guild,
                                              f"{Emoji.get_chat_emoji('INNOCENT')} {target.name}#{target.discriminator} (`{target.id}`) has been unmuted by {ctx.author.name}")
             InfractionUtils.add_infraction(ctx.guild.id, target.id, ctx.author.id, "Unmute", reason)
Example #20
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)
Example #21
0
 async def ban_punishment(self, v: Violation):
     reason = self.assemble_reason(v)
     self.bot.data["forced_exits"].add(f"{v.guild.id}-{v.member.id}")
     await v.guild.ban(v.member, reason=reason, delete_message_days=0)
     Infraction.update(active=False).where(
         (Infraction.user_id == v.member.id) & (Infraction.type == "Unban") & (
                 Infraction.guild_id == v.guild.id)).execute()
     i = InfractionUtils.add_infraction(v.guild.id, v.member.id, self.bot.user.id, 'Ban', reason)
     GearbotLogging.log_key(v.guild.id, 'ban_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,
                            reason=reason, inf=i.id)
Example #22
0
 async def temp_ban_punishment(self, v: Violation):
     reason = self.assemble_reason(v)
     duration = v.bucket["PUNISHMENT"]["DURATION"]
     until = time.time() + duration
     self.bot.data["forced_exists"].add(f"{v.guild.id}-{v.member.id}")
     await v.guild.ban(v.member, reason=reason, delete_message_days=0)
     i = InfractionUtils.add_infraction(v.guild.id, v.member.id, self.bot.user.id, 'Tempban', reason,
                                        end=until)
     GearbotLogging.log_key(v.guild.id, 'tempban_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, reason=reason,
                            until=datetime.datetime.utcfromtimestamp(until), inf=i.id)
Example #23
0
 async def warn(self, ctx: commands.Context, member: discord.Member, *,
                reason: Reason):
     """warn_help"""
     if (ctx.author != member and member != ctx.bot.user
             and ctx.author.top_role > member.top_role
         ) or ctx.guild.owner == ctx.author:
         if len(reason) > 1800:
             await ctx.send(
                 f"{Emoji.get_chat_emoji('NO')} {Translator.translate('warning_to_long', ctx.guild.id)}"
             )
         else:
             InfractionUtils.add_infraction(ctx.guild.id, member.id,
                                            ctx.author.id, "Warn", reason)
             name = Utils.clean_user(member)
             await ctx.send(
                 f"{Emoji.get_chat_emoji('YES')} {Translator.translate('warning_added', ctx.guild.id, user=name)}"
             )
             aname = Utils.clean_user(ctx.author)
             GearbotLogging.log_to(
                 ctx.guild.id, "MOD_ACTIONS",
                 f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('warning_added_modlog', ctx.guild.id, user=name, moderator=aname, reason=reason)}"
             )
             if Configuration.get_var(ctx.guild.id, "DM_ON_WARN"):
                 try:
                     dm_channel = await member.create_dm()
                     await dm_channel.send(
                         f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('warning_dm', ctx.guild.id, server=ctx.guild.name)}```{reason}```"
                     )
                 except discord.Forbidden:
                     GearbotLogging.log_to(
                         ctx.guild.id, "MOD_ACTIONS",
                         f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('warning_could_not_dm', ctx.guild.id, user=name, userid=member.id)}"
                     )
     else:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate('warning_not_allowed', ctx.guild.id, user=member)}"
         )
Example #24
0
    async def softban(self,
                      ctx: commands.Context,
                      user: discord.Member,
                      *,
                      reason: Reason = ""):
        """softban_help"""
        if reason == "":
            reason = Translator.translate("no_reason", ctx.guild.id)

        allowed, message = self._can_act("softban", ctx, user)
        if allowed:
            self.bot.data["forced_exits"].add(f"{ctx.guild.id}-{user.id}")
            self.bot.data["unbans"].add(user.id)
            await ctx.guild.ban(
                user,
                reason=Utils.trim_message(
                    f"Moderator: {ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) Reason: {reason}",
                    500),
                delete_message_days=1)
            await ctx.guild.unban(user)
            await ctx.send(
                f"{Emoji.get_chat_emoji('YES')} {Translator.translate('softban_confirmation', ctx.guild.id, user=Utils.clean_user(user), user_id=user.id, reason=reason)}"
            )
            GearbotLogging.log_to(
                ctx.guild.id, "MOD_ACTIONS",
                f":door: {Translator.translate('softban_log', ctx.guild.id, user=Utils.clean_user(user), user_id=user.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id, reason=reason)}"
            )
            InfractionUtils.add_infraction(ctx.guild.id,
                                           user.id,
                                           ctx.author.id,
                                           "Softban",
                                           reason,
                                           active=False)

        else:
            await GearbotLogging.send_to(ctx, "NO", message, translate=False)
Example #25
0
 async def on_member_unban(self, guild, user):
     fid = f"{guild.id}-{user.id}"
     if fid in self.bot.data["unbans"]:
         self.bot.data["unbans"].remove(fid)
         return
     elif not Features.is_logged(guild.id, "MOD_ACTIONS"):
         return
     else:
         if guild.me.guild_permissions.view_audit_log:
             async for entry in guild.audit_logs(action=AuditLogAction.unban, limit=2):
                 if entry.target == user and entry.created_at > datetime.datetime.utcfromtimestamp(time.time() - 30):
                     Infraction.update(active=False).where((Infraction.user_id == user.id) &
                                                           (Infraction.type == "Ban") &
                                                           (Infraction.guild_id == guild.id)).execute()
                     InfractionUtils.add_infraction(guild.id, entry.target.id, entry.user.id, "Unban",
                                                    "Manual unban")
                     GearbotLogging.log_to(guild.id, "MOD_ACTIONS",
                                           f":door: {Translator.translate('unban_log', guild.id, user=Utils.clean_user(user), user_id=user.id, moderator=entry.user, moderator_id=entry.user.id, reason='Manual unban')}")
                     return
         GearbotLogging.log_to(guild.id, "MOD_ACTIONS",
                               f"{Emoji.get_chat_emoji('INNOCENT')} {Translator.translate('manual_unban_log', guild.id, user=Utils.clean_user(user), user_id=user.id)}")
         Infraction.update(active=False).where((Infraction.user_id == user.id) &
                                               (Infraction.type == "Ban") &
                                               (Infraction.guild_id == guild.id)).execute()
Example #26
0
 async def _ban(self, ctx, user, reason, confirm):
     self.bot.data["forced_exits"].add(f"{ctx.guild.id}-{user.id}")
     await ctx.guild.ban(
         user,
         reason=Utils.trim_message(
             f"Moderator: {ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) Reason: {reason}",
             500),
         delete_message_days=0)
     Infraction.update(active=False).where(
         (Infraction.user_id == user.id) & (Infraction.type == "Unban")
         & (Infraction.guild_id == ctx.guild.id)).execute()
     InfractionUtils.add_infraction(ctx.guild.id, user.id, ctx.author.id,
                                    "Ban", reason)
     GearbotLogging.log_to(
         ctx.guild.id, "MOD_ACTIONS",
         f":door: {Translator.translate('ban_log', ctx.guild.id, user=Utils.clean_user(user), user_id=user.id, moderator=Utils.clean_user(ctx.author), moderator_id=ctx.author.id, reason=reason)}"
     )
     if confirm:
         await GearbotLogging.send_to(ctx,
                                      "YES",
                                      "ban_confirmation",
                                      user=Utils.clean_user(user),
                                      user_id=user.id,
                                      reason=reason)
Example #27
0
 async def execute(self, bot, member, data, raid_id, raider_ids, shield):
     bot.data["forced_exits"].add(f"{member.guild.id}-{member.id}")
     reason = f"Raider banned by raid shield {shield['name']} in raid {raid_id}"
     await member.ban(
         reason=reason,
         delete_message_days=1 if data["clean_messages"] else 0)
     i = InfractionUtils.add_infraction(member.guild.id, member.id,
                                        bot.user.id, "Ban", reason)
     GearbotLogging.log_to(member.guild.id,
                           'ban_log',
                           user=Utils.clean_user(member),
                           user_id=member.id,
                           moderator=Utils.clean_user(bot.user),
                           moderator_id=bot.user.id,
                           reason=reason,
                           inf=i.id)
Example #28
0
 async def execute(self, bot, member, data, raid_id, raider_ids, shield):
     role = member.guild.get_role(
         Configuration.get_var(member.guild.id, "MUTE_ROLE"))
     if role is None:
         GearbotLogging.log_to(member.guild.id, 'raid_mute_failed_no_role')
     else:
         duration = data["duration"]
         reason = f"Raider muted by raid shield {shield['name']} in raid {raid_id}"
         await member.add_roles(role, reason=reason)
         until = time.time() + duration
         i = InfractionUtils.add_infraction(member.guild.id,
                                            member.id,
                                            member.guild.me.id,
                                            "Mute",
                                            reason,
                                            end=until)
         DatabaseConnector.RaidAction.create(raider=raider_ids[member.id],
                                             action="mute_raider",
                                             infraction=i)
Example #29
0
 async def execute(self, bot, member, data, raid_id, raider_ids, shield):
     bot.data["forced_exits"].add(f"{member.guild.id}-{member.id}")
     reason = f"Raider kicked by raid shield {shield['name']} in raid {raid_id}"
     await member.kick(reason=reason)
     i = InfractionUtils.add_infraction(member.guild.id,
                                        member.id,
                                        bot.user.id,
                                        'Kick',
                                        reason,
                                        active=False)
     GearbotLogging.log_to(member.guild.id,
                           'kick_log',
                           member.guild.id,
                           user=Utils.clean_user(member),
                           user_id=member.id,
                           moderator=Utils.clean_user(member.guild.me),
                           moderator_id=bot.user.id,
                           reason=reason,
                           inf=i.id)
     DatabaseConnector.RaidAction.create(raider=raider_ids[member.id],
                                         action="mute_raider",
                                         infraction=i)
Example #30
0
 async def execute(self, bot, member, data, raid_id, raider_ids, shield):
     bot.data["forced_exits"].add(f"{member.guild.id}-{member.id}")
     reason = f"Raider kicked by raid shield {shield['name']} in raid {raid_id}"
     try:
         await member.kick(reason=reason)
     except NotFound:
         pass
     except Forbidden:
         log(member.guild.id,
             'raid_kick_forbidden',
             shield,
             user_name=Utils.escape_markdown(member),
             user_id=member.id)
     except Exception as ex:
         log(member.guild.id,
             'raid_kick_unknown_error',
             shield,
             user_name=Utils.escape_markdown(member),
             user_id=member.id)
         await TheRealGearBot.handle_exception('RAID KICK FAILURE', bot, ex)
     finally:
         i = InfractionUtils.add_infraction(member.guild.id,
                                            member.id,
                                            bot.user.id,
                                            'Kick',
                                            reason,
                                            active=False)
         GearbotLogging.log_key(member.guild.id,
                                'kick_log',
                                user=Utils.clean_user(member),
                                user_id=member.id,
                                moderator=Utils.clean_user(member.guild.me),
                                moderator_id=bot.user.id,
                                reason=reason,
                                inf=i.id)
         DatabaseConnector.RaidAction.create(raider=raider_ids[member.id],
                                             action="mute_raider",
                                             infraction=i)