Esempio n. 1
0
 async def silentban(self,
                     ctx,
                     member: discord.Member,
                     *,
                     reason=None):  # p!silentban
     "Bans a member from the server without messaging.\nThis command is only usable by staff members."
     logChannel = self.bot.get_channel(
         variables.ACTIONLOGS)  # Channel #action-logs.
     if check_staff_member(member):
         return await ctx.send(
             f"{ctx.author.mention}, this user cannot be banned from the server."
         )
     await ctx.guild.ban(member, reason=reason)
     embed = discord.Embed(color=0xff8080)
     embed.add_field(name="Reason", value=reason, inline=False)
     await ctx.send(
         f"{ctx.author.mention}, {member.mention} has been banned from the server."
     )
     if reason != None:
         await logChannel.send(
             f"{ctx.author.mention} ({ctx.author.id}) has silently banned {member.mention} ({member.id}).",
             embed=embed)
     else:
         await logChannel.send(
             f"{ctx.author.mention} ({ctx.author.id}) has silently banned {member.mention} ({member.id})."
         )
Esempio n. 2
0
 async def on_command_error(self, ctx, error):
     if isinstance(error, commands.CommandOnCooldown):
         if check_staff_member(ctx.author): return await ctx.reinvoke()
         return await ctx.send(
             f"{ctx.author.mention}, this command is on cooldown. Please try again in {error.retry_after:.0f} seconds."
         )
     elif isinstance(error, commands.MissingPermissions):
         ctx.command.reset_cooldown(ctx)
         return await ctx.send(
             f"{ctx.author.mention}, you don't have permission to use this command."
         )
     elif isinstance(error, commands.CheckFailure):
         ctx.command.reset_cooldown(ctx)
         return await ctx.send(
             f"{ctx.author.mention}, you don't have permission to use this command."
         )
     elif isinstance(error, commands.MissingRequiredArgument):
         ctx.command.reset_cooldown(ctx)
         await ctx.send(
             f"{ctx.author.mention}, you missed a required argument for this command."
         )
         return await ctx.send_help(ctx.command)
     elif isinstance(error, commands.BadArgument):
         ctx.command.reset_cooldown(ctx)
         await ctx.send(
             f"{ctx.author.mention}, you provided an invalid argument for this command."
         )
         return await ctx.send_help(ctx.command)
     elif isinstance(error, commands.CommandNotFound):
         pass
Esempio n. 3
0
 async def ban(self,
               ctx,
               member: typing.Union[discord.Member, int],
               *,
               reason=None):  # p!ban
     "Bans a member from the server.\nThis command is only usable by staff members."
     logChannel = self.bot.get_channel(
         variables.ACTIONLOGS)  # Channel #action-logs.
     if isinstance(member, int):
         try:
             member = await self.bot.fetch_user(member)
             await ctx.guild.ban(member, reason=reason)
             embed = discord.Embed(color=0xff8080)
             embed.add_field(name="Reason", value=reason, inline=False)
             await ctx.send(
                 f"{ctx.author.mention}, {member.mention} has been banned from the server."
             )
             if reason != None:
                 await logChannel.send(
                     f"{ctx.author.mention} ({ctx.author.id}) has banned {member.mention} ({member.id}).",
                     embed=embed)
             else:
                 await logChannel.send(
                     f"{ctx.author.mention} ({ctx.author.id}) has banned {member.mention} ({member.id})."
                 )
         except discord.errors.NotFound:
             return await ctx.send(
                 f"{ctx.author.mention}, there is no user associated with ID {member}."
             )
     if isinstance(member, discord.Member):
         if check_staff_member(member):
             return await ctx.send(
                 f"{ctx.author.mention}, this user cannot be banned from the server."
             )
         try:
             if reason != None:
                 await member.send(
                     f"You have been banned from {ctx.guild.name}. If you wish to rejoin, you must reach out to a member of the moderation team.",
                     embed=embed)
             else:
                 await member.send(
                     f"You have been banned from {ctx.guild.name}. If you wish to rejoin, you must reach out to a member of the moderation team."
                 )
         except discord.errors.Forbidden:
             pass
         await ctx.guild.ban(member, reason=reason, delete_message_days=0)
         embed = discord.Embed(color=0xff8080)
         embed.add_field(name="Reason", value=reason, inline=False)
         await ctx.send(
             f"{ctx.author.mention}, {member.mention} has been banned from the server."
         )
         if reason != None:
             await logChannel.send(
                 f"{ctx.author.mention} ({ctx.author.id}) has banned {member.mention} ({member.id}).",
                 embed=embed)
         else:
             await logChannel.send(
                 f"{ctx.author.mention} ({ctx.author.id}) has banned {member.mention} ({member.id})."
             )
Esempio n. 4
0
 async def showUserProfile(user):
     if isinstance(user, discord.Member):
         role = user.top_role.name
         embed = discord.Embed(title=user.display_name,
                               description=role,
                               color=0xffff00)
     else:
         embed = discord.Embed(title=user.display_name, color=0xffff00)
     embed.set_thumbnail(url=user.avatar_url_as(static_format="png"))
     embed.add_field(name="Account Name", value=user.name, inline=True)
     embed.add_field(name="Discriminator",
                     value="#" + user.discriminator,
                     inline=False)
     embed.add_field(name="Account Identification",
                     value=user.id,
                     inline=False)
     formatCreate = user.created_at
     formatCreate2 = formatCreate.strftime("%B %d, %Y (%I:%M %p)")
     if isinstance(user, discord.Member): formatJoin = user.joined_at
     if isinstance(user, discord.Member):
         formatJoin2 = formatJoin.strftime("%B %d, %Y (%I:%M %p)")
     embed.add_field(name="Created",
                     value="{}".format(formatCreate2),
                     inline=False)
     if isinstance(user, discord.Member):
         embed.add_field(name="Joined",
                         value="{}".format(formatJoin2),
                         inline=False)
     if not check_staff_member(user):
         if collection.count_documents({"_id": user.id}, limit=1) != 0:
             results = collection.find({"_id": user.id})
             for result in results:
                 checkWarn1 = result["Warn 1"]
                 checkWarn2 = result["Warn 2"]
                 checkWarn3 = result["Warn 3"]
             if checkWarn3 != None: warns = "3"
             elif checkWarn3 == None and checkWarn2 != None: warns = "2"
             elif checkWarn2 == None and checkWarn1 != None: warns = "1"
             embed.add_field(name="Warns", value=warns, inline=False)
         else:
             embed.add_field(name="Warns", value="0", inline=False)
     if not isinstance(user, discord.Member):
         try:
             banned = await ctx.guild.fetch_ban(user)
             embed.add_field(name="Banned",
                             value=f"{banned.reason}",
                             inline=False)
         except discord.NotFound:
             banned = None
     if user == ctx.author:
         await ctx.send(
             f"{ctx.author.mention}, here's some information about you.",
             embed=embed)
     else:
         await ctx.send(
             f"{ctx.author.mention}, here's some information about {user.mention}.",
             embed=embed)
Esempio n. 5
0
 async def on_message(self, ctx): # Initial message filtering.
     logChannel = self.bot.get_channel(variables.MESSAGELOGS) # Channel #message-logs.
     messageCheck = "".join(char for char in ctx.content.lower() if char in printable)
     messageNoSeparators = re.sub(r"[ \*_\-~.!`@#$%^&+=?/|)(]", "", messageCheck)
     filterAlert = any(x in messageNoSeparators for x in arrays.MESSAGEFILTER)
     if filterAlert:
         try:
             if check_staff_member(ctx.author): return None
             if ctx.channel.id in arrays.CHANNELINFORMATION:
                 info = arrays.CHANNELINFORMATION.get(ctx.channel.id)
                 filterSetting = info.get("Filter")
                 if filterSetting: return None
             print("Filter has been set off.")
             await ctx.delete()
             embed = discord.Embed(color=0xff8080)
             embed.add_field(name="Deleted Message", value=ctx.content, inline=False)
             try: await ctx.author.send(f"Your message has been automatically deleted as it violated the server rules. Please read <#450903022613168129> for more information.", embed=embed)
             except discord.errors.Forbidden: pass
             await logChannel.send(f"{ctx.author.mention} ({ctx.author.id}) has sent a message in {ctx.channel.mention} in violation of the server rules which was automatically deleted.", embed=embed)
         except AttributeError: pass
Esempio n. 6
0
 async def clearwarn(self, ctx, member: discord.Member):  # p!clearwarn
     "Clears all warns from a specified user.\nThis command is only usable by staff members."
     logChannel = self.bot.get_channel(
         variables.ACTIONLOGS)  # Channel #action-logs.
     cluster = MongoClient(variables.DBACCOUNT)
     database = cluster["Moderation"]
     collection = database["Warns"]
     if check_staff_member(member):
         return await ctx.send(
             f"{ctx.author.mention}, this user cannot be warned in the server."
         )
     if collection.count_documents({"_id": member.id}, limit=1) != 0:
         results = collection.find({"_id": member.id})
         for result in results:
             checkWarn1 = result["Warn 1"]
             checkWarn2 = result["Warn 2"]
             checkWarn3 = result["Warn 3"]
         embed = discord.Embed(color=0xff8080)
         if checkWarn1 != None:
             embed.add_field(name="Warning 1",
                             value=checkWarn1,
                             inline=False)
         if checkWarn2 != None:
             embed.add_field(name="Warning 2",
                             value=checkWarn2,
                             inline=False)
         if checkWarn3 != None:
             embed.add_field(name="Warning 3",
                             value=checkWarn3,
                             inline=False)
         collection.delete_one({"_id": member.id})
         await logChannel.send(
             f"{ctx.author.mention} ({ctx.author.id}) has cleared all warnings from {member.mention} ({member.id}).",
             embed=embed)
         await ctx.send(
             f"{ctx.author.mention}, all warnings given to {member.mention} have been cleared sucessfully."
         )
     else:
         await ctx.send(
             f"{ctx.author.mention}, there are no warnings given to {member.mention}."
         )
Esempio n. 7
0
 async def kick(self,
                ctx,
                member: discord.Member,
                *,
                reason=None):  # p!kick
     "Kicks a user from the server.\nThis command is only usable by staff members."
     logChannel = self.bot.get_channel(
         variables.ACTIONLOGS)  # Channel #action-logs.
     if check_staff_member(member):
         return await ctx.send(
             f"{ctx.author.mention}, this user cannot be kicked from the server."
         )
     if reason != None:
         embed = discord.Embed(color=0xff8080)
         embed.add_field(name="Reason", value=reason, inline=False)
         await member.send(
             f"You have been kicked from {ctx.guild.name}. You may rejoin, however please read the #rules channel before participating in the server.",
             embed=embed)
         await member.kick(reason=reason)
         await ctx.send(
             f"{ctx.author.mention}, {member.mention} has been kicked from the server."
         )
         await logChannel.send(
             f"{ctx.author.mention} ({ctx.author.id}) has kicked {member.mention} ({member.id}).",
             embed=embed)
     else:
         try:
             await member.send(
                 f"You have been kicked from {ctx.guild.name}. You may rejoin, however please read the #rules channel before participating in the server."
             )
         except discord.errors.Forbidden:
             pass
         await member.kick(reason=reason)
         await ctx.send(
             f"{ctx.author.mention}, {member.mention} has been kicked from the server."
         )
         await logChannel.send(
             f"{ctx.author.mention} ({ctx.author.id}) has kicked {member.mention} ({member.id})."
         )
Esempio n. 8
0
    async def userinfo(self,
                       ctx,
                       user: typing.Union[discord.Member, discord.User,
                                          int] = None):  # p!userinfo
        "Displays information regarding a user's account.\nStaff members can use this command on others."
        cluster = MongoClient(variables.DBACCOUNT)
        database = cluster["Moderation"]
        collection = database["Warns"]
        if isinstance(user, (discord.User, int)):
            user = await self.bot.fetch_user(user)

        async def showUserProfile(user):
            if isinstance(user, discord.Member):
                role = user.top_role.name
                embed = discord.Embed(title=user.display_name,
                                      description=role,
                                      color=0xffff00)
            else:
                embed = discord.Embed(title=user.display_name, color=0xffff00)
            embed.set_thumbnail(url=user.avatar_url_as(static_format="png"))
            embed.add_field(name="Account Name", value=user.name, inline=True)
            embed.add_field(name="Discriminator",
                            value="#" + user.discriminator,
                            inline=False)
            embed.add_field(name="Account Identification",
                            value=user.id,
                            inline=False)
            formatCreate = user.created_at
            formatCreate2 = formatCreate.strftime("%B %d, %Y (%I:%M %p)")
            if isinstance(user, discord.Member): formatJoin = user.joined_at
            if isinstance(user, discord.Member):
                formatJoin2 = formatJoin.strftime("%B %d, %Y (%I:%M %p)")
            embed.add_field(name="Created",
                            value="{}".format(formatCreate2),
                            inline=False)
            if isinstance(user, discord.Member):
                embed.add_field(name="Joined",
                                value="{}".format(formatJoin2),
                                inline=False)
            if not check_staff_member(user):
                if collection.count_documents({"_id": user.id}, limit=1) != 0:
                    results = collection.find({"_id": user.id})
                    for result in results:
                        checkWarn1 = result["Warn 1"]
                        checkWarn2 = result["Warn 2"]
                        checkWarn3 = result["Warn 3"]
                    if checkWarn3 != None: warns = "3"
                    elif checkWarn3 == None and checkWarn2 != None: warns = "2"
                    elif checkWarn2 == None and checkWarn1 != None: warns = "1"
                    embed.add_field(name="Warns", value=warns, inline=False)
                else:
                    embed.add_field(name="Warns", value="0", inline=False)
            if not isinstance(user, discord.Member):
                try:
                    banned = await ctx.guild.fetch_ban(user)
                    embed.add_field(name="Banned",
                                    value=f"{banned.reason}",
                                    inline=False)
                except discord.NotFound:
                    banned = None
            if user == ctx.author:
                await ctx.send(
                    f"{ctx.author.mention}, here's some information about you.",
                    embed=embed)
            else:
                await ctx.send(
                    f"{ctx.author.mention}, here's some information about {user.mention}.",
                    embed=embed)

        if check_staff_member(ctx.author):
            if user == None: user = ctx.author
            return await showUserProfile(user)
        if user != ctx.author and user != None:
            return await ctx.send(
                f"{ctx.author.mention}, using this command on others is only allowed for staff members."
            )
        user = ctx.author
        return await showUserProfile(user)
Esempio n. 9
0
 async def warn(self, ctx, member: discord.Member, *, reason):  # p!warn
     "Warns a user on the server.\nTwo warns will kick automatically, three will ban.\nThis command is only usable by staff members."
     logChannel = self.bot.get_channel(
         variables.ACTIONLOGS)  # Channel #action-logs.
     cluster = MongoClient(variables.DBACCOUNT)
     database = cluster["Moderation"]
     collection = database["Warns"]
     if check_staff_member(member):
         return await ctx.send(
             f"{ctx.author.mention}, this user cannot be warned in the server."
         )
     if collection.count_documents({"_id": member.id}, limit=1) == 0:
         post = {
             "_id": member.id,
             "Warn 1": None,
             "Warn 2": None,
             "Warn 3": None
         }
         collection.insert_one(post)
         results = collection.find({"_id": member.id})
         for result in results:
             checkWarn1 = result["Warn 1"]
             checkWarn2 = result["Warn 2"]
             checkWarn3 = result["Warn 3"]
         if checkWarn1 == None:
             collection.update_one({"_id": member.id},
                                   {"$set": {
                                       "Warn 1": reason
                                   }})
             embed = discord.Embed(color=0xff8080)
             embed.add_field(name="Warning 1", value=reason, inline=False)
             try:
                 await member.send(
                     f"You have been warned in {ctx.guild.name}. This is your first warning and only warning without an automatic punishment. Please reconsider the rules before participating in the server. Your next offense will result in an automatic kick.",
                     embed=embed)
             except discord.errors.Forbidden:
                 pass
             await logChannel.send(
                 f"{ctx.author.mention} ({ctx.author.id}) has given a warning to {member.mention} ({member.id}).",
                 embed=embed)
             await ctx.send(
                 f"{ctx.author.mention}, a warning has been given to {member.mention}."
             )
     else:
         results = collection.find({"_id": member.id})
         for result in results:
             checkWarn1 = result["Warn 1"]
             checkWarn2 = result["Warn 2"]
             checkWarn3 = result["Warn 3"]
         if checkWarn2 == None and checkWarn1 != None:
             collection.update_one({"_id": member.id},
                                   {"$set": {
                                       "Warn 2": reason
                                   }})
             embed = discord.Embed(color=0xff8080)
             embed.add_field(name="Warning 2", value=reason, inline=False)
             try:
                 await member.send(
                     f"You have been warned in {ctx.guild.name}. This is your second warning, therefore you have automatically been kicked from the server. Please reconsider the rules before participating in the server. Your next offense will result in an automatic ban.",
                     embed=embed)
             except discord.errors.Forbidden:
                 pass
             await logChannel.send(
                 f"{ctx.author} ({ctx.author.id}) has given a warning to {member.mention} ({member.id}). A kick has been initiated automatically.",
                 embed=embed)
             await member.kick(
                 reason=f"Automatically kicked. ({checkWarn1}, {reason})")
             await ctx.send(
                 f"{ctx.author.mention}, a warning has been given to {member.mention}. A kick has been initiated automatically."
             )
         elif checkWarn3 == None and checkWarn2 != None:
             collection.update_one({"_id": member.id},
                                   {"$set": {
                                       "Warn 3": reason
                                   }})
             embed = discord.Embed(color=0xff8080)
             embed.add_field(name="Warning 3", value=reason, inline=False)
             try:
                 await member.send(
                     f"You have been warned in {ctx.guild.name}. This is your third warning, therefore you have automatically been banned from the server. Please contact a staff member if you feel you have been wrongfully punished.",
                     embed=embed)
             except discord.errors.Forbidden:
                 pass
             await logChannel.send(
                 f"{ctx.author.mention} ({ctx.author.id}) has given a warning to {member.mention} ({member.id}). A ban has been initiated automatically.",
                 embed=embed)
             await member.ban(
                 reason=
                 f"Automatically banned. ({checkWarn1}, {checkWarn2}, {reason})"
             )
             await ctx.send(
                 f"{ctx.author.mention}, a warning has been given to {member.mention}. A ban has been initiated automatically."
             )
         elif checkWarn3 != None and checkWarn2 != None:
             await ctx.send(
                 f"{ctx.author.mention}, there are too many warnings recorded for {member.mention}."
             )
Esempio n. 10
0
    async def listwarn(self, ctx, member: discord.Member = None):  # p!listwarn
        "Lists the warns that a user has received.\nStaff members can use this command on others."
        cluster = MongoClient(variables.DBACCOUNT)
        database = cluster["Moderation"]
        collection = database["Warns"]

        async def userWarnList(user):
            if collection.count_documents({"_id": member.id}, limit=1) == 0:
                if member == ctx.author:
                    await ctx.send(
                        f"{ctx.author.mention}, there are no warnings recorded."
                    )
                else:
                    await ctx.send(
                        f"{ctx.author.mention}, there are no warnings recorded for {member.mention}."
                    )
            else:
                results = collection.find({"_id": member.id})
                for result in results:
                    checkWarn1 = result["Warn 1"]
                    checkWarn2 = result["Warn 2"]
                    checkWarn3 = result["Warn 3"]
                embed = discord.Embed(color=0xff8080)
                if checkWarn1 != None:
                    embed.add_field(name="Warning 1",
                                    value=checkWarn1,
                                    inline=False)
                if checkWarn2 != None:
                    embed.add_field(name="Warning 2",
                                    value=checkWarn2,
                                    inline=False)
                if checkWarn3 != None:
                    embed.add_field(name="Warning 3",
                                    value=checkWarn3,
                                    inline=False)
                embed.set_footer(
                    text="To appeal a warn, speak to a staff member.")
                if member == ctx.author:
                    await ctx.send(
                        f"{ctx.author.mention}, here's all recorded warnings.",
                        embed=embed)
                else:
                    await ctx.send(
                        f"{ctx.author.mention}, here are all recorded warnings for {member.mention}.",
                        embed=embed)

        if check_staff_member(ctx.author):
            if member == None: member = ctx.author
            if check_staff_member(member):
                return await ctx.send(
                    f"{ctx.author.mention}, this user cannot be warned in the server."
                )
            return await userWarnList(member)
        if member != None:
            return await ctx.send(
                f"{ctx.author.mention}, using this command on others is only allowed for staff members."
            )
        else:
            member = ctx.author
            if check_staff_member(member):
                return await ctx.send(
                    f"{ctx.author.mention}, this user cannot be warned in the server."
                )
            else:
                return await userWarnList(member)
Esempio n. 11
0
 async def pardon(self, ctx, member: discord.Member):  # p!warn
     "Removes a warn from a user on the server.\nThis command is only usable by staff members."
     logChannel = self.bot.get_channel(
         variables.ACTIONLOGS)  # Channel #action-logs.
     cluster = MongoClient(variables.DBACCOUNT)
     database = cluster["Moderation"]
     collection = database["Warns"]
     if check_staff_member(member):
         return await ctx.send(
             f"{ctx.author.mention}, this user cannot be warned in the server."
         )
     if collection.count_documents({"_id": member.id}, limit=1) == 1:
         results = collection.find({"_id": member.id})
         for result in results:
             checkWarn1 = result["Warn 1"]
             checkWarn2 = result["Warn 2"]
             checkWarn3 = result["Warn 3"]
         if checkWarn3 != None:
             embed = discord.Embed(color=0xff8080)
             embed.add_field(name="Warning 3",
                             value=checkWarn3,
                             inline=False)
             await logChannel.send(
                 f"{ctx.author.mention} ({ctx.author.id}) has pardoned a warning from {member.mention} ({member.id}).",
                 embed=embed)
             collection.update_one({"_id": member.id},
                                   {"$set": {
                                       "Warn 3": None
                                   }})
             return await ctx.send(
                 f"{ctx.author.mention}, the latest warning given to {member.mention} has been removed successfully."
             )
         elif checkWarn2 != None and checkWarn3 == None:
             embed = discord.Embed(color=0xff8080)
             embed.add_field(name="Warning 2",
                             value=checkWarn2,
                             inline=False)
             await logChannel.send(
                 f"{ctx.author.mention} ({ctx.author.id}) has pardoned a warning from {member.mention} ({member.id}).",
                 embed=embed)
             collection.update_one({"_id": member.id},
                                   {"$set": {
                                       "Warn 2": None
                                   }})
             return await ctx.send(
                 f"{ctx.author.mention}, the latest warning given to {member.mention} has been removed successfully."
             )
         elif checkWarn1 != None and checkWarn2 == None:
             embed = discord.Embed(color=0xff8080)
             embed.add_field(name="Warning 1",
                             value=checkWarn1,
                             inline=False)
             await logChannel.send(
                 f"{ctx.author.mention} ({ctx.author.id}) has pardoned a warning from {member.mention} ({member.id}).",
                 embed=embed)
             collection.delete_one({"_id": member.id})
             return await ctx.send(
                 f"{ctx.author.mention}, the latest warning given to {member.mention} has been removed successfully."
             )
         else:
             return await ctx.send(
                 f"{ctx.author.mention}, there are no warnings recorded for {member.mention}."
             )
     else:
         return await ctx.send(
             f"{ctx.author.mention}, there are no warnings recorded for {member.mention}."
         )