예제 #1
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)
예제 #2
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)}")
예제 #3
0
 async def yes():
     await infraction.delete()
     await MessageUtils.send_to(ctx, "YES", "inf_delete_deleted", id=infraction.id)
     GearbotLogging.log_key(ctx.guild.id, 'inf_delete_log', id=infraction.id, target=Utils.clean_user(target),
                            target_id=target.id, mod=Utils.clean_user(mod), mod_id=mod.id if mod is not None else 0, reason=reason,
                            user=Utils.clean_user(ctx.author), user_id=ctx.author.id)
     InfractionUtils.clear_cache(ctx.guild.id)
예제 #4
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
                        InfractionUtils.add_infraction(member.guild.id, entry.target.id, entry.user.id, "Kick", reason,
                                                       active=False)
                        GearbotLogging.log_to(member.guild.id, "MOD_ACTIONS",
                                              f":boot: {Translator.translate('kick_log', member.guild.id, user=Utils.clean_user(member), user_id=member.id, moderator=Utils.clean_user(entry.user), moderator_id=entry.user.id, reason=reason)}")
                        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, "JOIN_LOGS"):
            GearbotLogging.log_to(member.guild.id, "JOIN_LOGS",
                                  f"{Emoji.get_chat_emoji ('LEAVE')} {Translator.translate('leave_logging', member.guild.id, user=Utils.clean_user(member), user_id=member.id)}")
예제 #5
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)
예제 #6
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)}"
     )
예제 #7
0
 async def update(self, ctx: commands.Context, infraction: ServerInfraction, *, reason: Reason):
     """inf_update_help"""
     infraction.mod_id = ctx.author.id
     infraction.reason = reason
     infraction.save()
     await MessageUtils.send_to(ctx, 'YES', 'inf_updated', id=infraction.id)
     InfractionUtils.clear_cache(ctx.guild.id)
예제 #8
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)
예제 #9
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
     if guild.me.guild_permissions.view_audit_log:
         async for entry in guild.audit_logs(action=AuditLogAction.ban, limit=25):
             if entry.target == user and entry.created_at > datetime.datetime.utcfromtimestamp(time.time() - 30):
                 if entry.reason is None:
                     reason = Translator.translate("no_reason", guild.id)
                 else:
                     reason = entry.reason
                 Infraction.update(active=False).where((Infraction.user_id == user.id) &
                                                       (Infraction.type == "Unban") &
                                                       (Infraction.guild_id == guild.id)).execute()
                 InfractionUtils.add_infraction(guild.id, entry.target.id, entry.user.id, "Ban",
                                                "No reason given." if entry.reason is None else entry.reason)
                 GearbotLogging.log_to(guild.id, "MOD_ACTIONS",
                                       f":door: {Translator.translate('ban_log', guild.id, user=Utils.clean_user(user), user_id=user.id, moderator=Utils.clean_user(entry.user), moderator_id=entry.user.id, reason=reason)}")
                 return
     GearbotLogging.log_to(guild.id, "MOD_ACTIONS",
                           f":door: {Translator.translate('manual_ban_log', guild.id, user=Utils.clean_user(user), user_id=user.id)}")
     Infraction.update(active=False).where((Infraction.user_id == user.id) &
                                           (Infraction.type == "Unban") &
                                           (Infraction.guild_id == guild.id)).execute()
     self.bot.data["forced_exits"].add(fid)
예제 #10
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:
             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)}")
예제 #11
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)}"
         )
예제 #12
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)
예제 #13
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)
예제 #14
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)}"
         )
예제 #15
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_modlog', ctx.guild.id, user=name, moderator=aname, reason=reason)}"
             )
     else:
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} {Translator.translate('warning_added', ctx.guild.id, user=ctx.author)}"
         )
예제 #16
0
async def initialize(bot):
    #lock event handling while we get ready
    bot.locked = True
    try:
        #database
        GearbotLogging.info("Connecting to the database.")
        DatabaseConnector.init()
        bot.database_connection = DatabaseConnector.connection
        GearbotLogging.info("Database connection established.")

        GearbotLogging.initialize_pump(bot)
        Emoji.initialize(bot)
        Pages.initialize(bot)
        Utils.initialize(bot)
        Translator.initialize(bot)
        InfractionUtils.initialize(bot)
        bot.data = {
            "forced_exits": set(),
            "unbans": set(),
            "message_deletes": set()
        }
        await GearbotLogging.initialize(
            bot, Configuration.get_master_var("BOT_LOG_CHANNEL"))

        if bot.redis_pool is None or not hasattr(
                bot, 'redis_raid_pool') or bot.redis_raid_pool is None:
            try:
                bot.redis_pool = await aioredis.create_redis_pool(
                    (Configuration.get_master_var('REDIS_HOST', "localhost"),
                     Configuration.get_master_var('REDIS_PORT', 6379)),
                    encoding="utf-8",
                    db=0)
                bot.redis_raid_pool = await aioredis.create_redis_pool(
                    (Configuration.get_master_var('REDIS_HOST', "localhost"),
                     Configuration.get_master_var('REDIS_PORT', 6379)),
                    encoding="utf-8",
                    db=1)
            except OSError:
                GearbotLogging.error(
                    "==============Failed to connect to redis==============")
                await GearbotLogging.bot_log(
                    f"{Emoji.get_chat_emoji('NO')} Failed to connect to redis, caching and anti-raid connections unavailable"
                )
            else:
                GearbotLogging.info("Redis connection established")
                await GearbotLogging.bot_log(
                    f"{Emoji.get_chat_emoji('YES')} Redis connection established, caching and anti-raid connections established"
                )

        if bot.aiosession is None:
            bot.aiosession = aiohttp.ClientSession()
        bot.being_cleaned.clear()
        await Configuration.initialize(bot)
    except Exception as ex:
        #make sure we always unlock, even when something went wrong!
        bot.locked = False
        raise ex
    bot.locked = False
예제 #17
0
 async def claim(self, ctx, infraction: ServerInfraction):
     """inf_claim_help"""
     infraction.mod_id = ctx.author.id
     infraction.save()
     await MessageUtils.send_to(ctx,
                                'YES',
                                'inf_claimed',
                                inf_id=infraction.id)
     InfractionUtils.clear_cache(ctx.guild.id)
예제 #18
0
 async def update(self, ctx: commands.Context, infraction: ServerInfraction, *, reason: Reason):
     """inf_update_help"""
     infraction.mod_id = ctx.author.id
     infraction.reason = reason
     await infraction.save()
     await MessageUtils.send_to(ctx, 'YES', 'inf_updated', id=infraction.id)
     InfractionUtils.clear_cache(ctx.guild.id)
     user = await Utils.get_user(infraction.user_id)
     GearbotLogging.log_key(ctx.guild.id, "inf_update_log", inf=infraction.id, user=Utils.clean_user(user), userid=user.id, mod=Utils.clean_user(ctx.author), modid=ctx.author.id, reason=reason)
예제 #19
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)}"
                 )
예제 #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 = await Infraction.get_or_none(user_id=v.member.id,
                                      type="Mute",
                                      guild_id=v.member.guild.id,
                                      active=True)
     if i is None:
         i = await 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)
예제 #21
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)
예제 #22
0
async def initialize(bot, startup=False):
    #lock event handling while we get ready
    bot.locked = True
    try:
        #database
        GearbotLogging.info("Connecting to the database.")
        DatabaseConnector.init()
        bot.database_connection = DatabaseConnector.connection
        GearbotLogging.info("Database connection established.")

        Emoji.initialize(bot)
        Utils.initialize(bot)
        InfractionUtils.initialize(bot)
        bot.data = {
            "forced_exits": set(),
            "unbans": set(),
            "message_deletes": set(),
            "nickname_changes": set()
        }
        await GearbotLogging.initialize(bot, Configuration.get_master_var("BOT_LOG_CHANNEL"))
        if startup:
            c = await Utils.get_commit()
            bot.version = c
            GearbotLogging.info(f"GearBot spinning up version {c}")
            await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('ALTER')} GearBot spinning up version {c}")

        if bot.redis_pool is None:
            try:
                socket = Configuration.get_master_var("REDIS_SOCKET", "")
                if socket == "":
                    bot.redis_pool = await aioredis.create_redis_pool((Configuration.get_master_var('REDIS_HOST', "localhost"), Configuration.get_master_var('REDIS_PORT', 6379)), encoding="utf-8", db=0)
                else:
                    bot.redis_pool = await aioredis.create_redis_pool(socket, encoding="utf-8", db=0)
            except OSError:
                GearbotLogging.error("==============Failed to connect to redis==============")
                await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('NO')} Failed to connect to redis, caching unavailable")
            else:
                GearbotLogging.info("Redis connection established")
                await GearbotLogging.bot_log(f"{Emoji.get_chat_emoji('YES')} Redis connection established, let's go full speed!")

        if bot.aiosession is None:
            bot.aiosession = aiohttp.ClientSession()

        await Translator.initialize(bot)
        bot.being_cleaned.clear()
        await Configuration.initialize(bot)
        DashConfig.initialize(bot)
    except Exception as ex:
        #make sure we always unlock, even when something went wrong!
        bot.locked = False
        raise ex
    bot.locked = False
예제 #23
0
    async def update(self, ctx: commands.Context, infraction: ServerInfraction, *, reason: Reason):
        """inf_update_help"""
        reason += ",".join(Utils.assemble_attachment(ctx.message.channel.id, attachment.id, attachment.filename) for attachment in ctx.message.attachments)
        if len(reason) > 1800:
            raise TranslatedBadArgument('reason_too_long', ctx)

        infraction.mod_id = ctx.author.id
        infraction.reason = reason
        await infraction.save()
        await MessageUtils.send_to(ctx, 'YES', 'inf_updated', id=infraction.id)
        InfractionUtils.clear_cache(ctx.guild.id)
        user = await Utils.get_user(infraction.user_id)
        GearbotLogging.log_key(ctx.guild.id, "inf_update_log", inf=infraction.id, user=Utils.clean_user(user), userid=user.id, mod=Utils.clean_user(ctx.author), modid=ctx.author.id, reason=reason)
예제 #24
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)
예제 #25
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)
예제 #26
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)
예제 #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}"
     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)
예제 #28
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)
예제 #29
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 = await Infraction.get_or_none(user_id = v.member.id, type = "Mute", guild_id = v.member.guild.id, active=True)
        if i is None:
            i = await 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)
                if Configuration.get_var(v.guild.id, "INFRACTIONS", "DM_ON_MUTE"):
                    await Utils.send_infraction(self.bot, v.member, v.guild, 'MUTE', 'mute', reason, duration=Utils.to_pretty_time(duration, v.guild.id))
        else:
            i.end += duration
            i.reason += Utils.trim_message(f'+ {reason}', 2000)
            await 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)

        if v.member.voice:
            permissions = v.member.voice.channel.permissions_for(v.guild.me)
            if permissions.move_members:
                await v.member.move_to(None, reason=f"{reason}")
예제 #30
0
 async def yes(interaction: disnake.Interaction):
     await infraction.delete()
     await interaction.response.edit_message(
         content=MessageUtils.assemble(ctx,
                                       "YES",
                                       "inf_delete_deleted",
                                       id=infraction.id),
         view=None)
     GearbotLogging.log_key(ctx.guild.id,
                            'inf_delete_log',
                            id=infraction.id,
                            target=Utils.clean_user(target),
                            target_id=target.id,
                            mod=Utils.clean_user(mod),
                            mod_id=mod.id if mod is not None else 0,
                            reason=reason,
                            user=Utils.clean_user(ctx.author),
                            user_id=ctx.author.id)
     InfractionUtils.clear_cache(ctx.guild.id)