Пример #1
0
 async def _listcogs(self, ctx):
     """Lists all the cogs - GM only."""
     if isModerator(ctx.author.id):
         embed = discord.Embed(title="Cogs", color=discord.Color.green(),
                               description="`essentials, info, moderation, listenerCog, botlists`")
         embed.set_footer(text=ctx.author.name, icon_url=ctx.author.avatar_url)
         await ctx.send(embed=embed)
     else:
         await ctx.send(
             embed=Embed(color=discord.Color.red(), description="You are not a Global Moderator! Shame!"))
Пример #2
0
    async def performBan(cls, ctx, users, reason):
        bot = ctx.bot
        if isinstance(users, tuple):
            users = list(users)
        elif not isinstance(users, list):
            users = [users]

        # Check all users if they are already banned and stuff
        usersToBan = []
        for user in users:
            if user == ctx.bot.user:
                error = "Banning a user failed - given user is the bot"
                await logger.log(error, bot, "INFO")
            elif isModerator(user.id):
                error = "Banning a user failed - given user is a Global Moderator"
                await logger.log(error, bot, "INFO")
            elif database.isBanned(user.id):
                error = "Banning a user failed - given user is already banned"
                await logger.log(error, bot, "INFO")
            else:
                usersToBan.append(user)

        # If the list is empty, then there are no users to ban. As such, let's return the most recent error, I guess
        if not usersToBan:
            return error

        # Ban on current guild
        for user in usersToBan:
            # Bans on current guild first
            try:
                await ctx.guild.ban(user, reason="WatchDog - Global Ban")
            except Exception as e:
                await logger.log("Could not ban the user `%s` (%s) in the guild `%s` (%s)" % (
                    user.name, user.id, ctx.guild.name, ctx.guild.id), bot, "INFO")
                logger.logDebug(e)

        # Ban on other guilds
        for user in usersToBan:
            guilds = [guild for guild in bot.guilds if guild.get_member(user.id)]
            guilds.append(bot.get_guild(int(os.getenv('banlistguild'))))

            for guild in guilds:
                try:
                    await guild.ban(user, reason="WatchDog - Global Ban")
                except Exception as e:
                    await logger.log("Could not ban the user `%s` (%s) in the guild `%s` (%s)" % (
                        user.name, user.id, guild.name, guild.id), bot, "INFO")
                    logger.logDebug(e)
            # Send private ban notif in private moderator ban list as well as message in botlog
            await cls.logBan(ctx, user, reason=reason)
Пример #3
0
 async def _unloadcog(self, ctx, arg1):
     """Unloads a cog - GM only."""
     bot = self.bot
     if isModerator(ctx.author.id):
         try:
             bot.unload_extension(f"cogs.{arg1}")
             await ctx.send(f"Successfully unloaded the {arg1} extension")
             await logger.log("Moderator `%s` unloaded the extension %s" % (ctx.author.name, arg1), bot, "INFO")
         except Exception as e:
             await ctx.send(f"Failed to unload the extension {arg1}")
             await logger.log(f"Failed to unload the extension {arg1} - {e}", bot, "ERROR")
     else:
         await ctx.send(
             embed=Embed(color=discord.Color.red(), description="You are not a Global Moderator! Shame!"))
Пример #4
0
    async def _ban(self, ctx, arg1, *args):
        """Bans a user globally - GM only."""
        bot = ctx.bot
        if isModerator(ctx.author.id):
            try:
                user = await self.getUser(ctx, arg1)
            except Exception as e:
                await ctx.send(embed=Embed(color=discord.Color.red(), description="Specified user not found!"))
                await logger.log("Could not get a specified user - Specified arg: %s - Error: %s" % (arg1, e), bot,
                                 "ERROR")
                return

            # Get the ban reason, if there is any
            reason = None
            if len(args) > 1:
                logger.logDebug("More than 1 argument given on ban command, getting banreason")
                reason = ' '.join(args)
                logger.logDebug("Banreason: " + reason)

            # Sends main embed
            embed = discord.Embed(title="Account is being banned...", color=discord.Color.green(),
                                  description="The ban is happening! Woah there! 👌")
            embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                             icon_url=ctx.author.avatar_url)
            embed_message = await ctx.send(embed=embed)

            # Perform the ban
            error = await self.performBan(ctx, user, reason)

            # Do this when done
            # send final embed, telling the ban was sucessful
            if not error:
                embed = discord.Embed(title="Account banned", color=discord.Color.green(),
                                      description="`%s` has been globally banned 👌" % user)
                embed.set_image(
                    url="https://cdn.discordapp.com/attachments/456229881064325131/475498849696219141/ban.gif")
            else:
                embed = discord.Embed(title="Banning failed", color=discord.Color.red(),
                                      description="Error: %s" % error)
                embed.set_image(
                    url="https://cdn.discordapp.com/attachments/474313313598046238/689828429318848517/failed.gif")
            embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                             icon_url=ctx.author.avatar_url)
            await embed_message.edit(embed=embed)
        else:
            await ctx.send(
                embed=Embed(color=discord.Color.red(), description="You are not a Global Moderator! Shame!"))
Пример #5
0
    async def _unban(self, ctx, arg1):
        """Unbans a user globally - GM only."""
        bot = ctx.bot
        if isModerator(ctx.author.id):
            try:
                user = await self.getUser(ctx, arg1)
            except Exception as e:
                await ctx.send(embed=Embed(color=discord.Color.red(), description="Specified user not found!"))
                await logger.log("Could not get a specified user - Specified arg: %s - Error: %s" % (arg1, e), bot,
                                 "ERROR")
                return

            if not database.isBanned(user.id):
                return

            guilds = bot.guilds
            if len(guilds) >= 1:
                embed = discord.Embed(title="Account is being unbanned...", color=discord.Color.green(),
                                      description="The bans are happening! Woah there! 👌")
                embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                                 icon_url=ctx.author.avatar_url)
                embed_message = await ctx.send(embed=embed)
                for guild in guilds:
                    if guild is None:  # Check if guild is none
                        await logger.log("Guild is none... GuildID: " + guild.id, bot, "ERROR")
                        continue
                    try:
                        await guild.unban(user, reason="WatchDog - Global Unban")
                    except Exception as e:
                        logger.logDebug("Could not unban the user `%s` (%s) in the guild `%s` (%s)" % (
                            user.name, user.id, guild.name, guild.id), "DEBUG")
                        logger.logDebug(e)
                # do this when done
                # Send private ban notif in private moderator ban list as well as message in botlog
                await self.logBan(ctx, user, unban=True)
                # edits final embed
                embed = discord.Embed(title="Account unbanned", color=discord.Color.green(),
                                      description="`%s` has been globally unbanned 👌" % user)
                embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                                 icon_url=ctx.author.avatar_url)
                embed.set_image(
                    url="https://cdn.discordapp.com/attachments/456229881064325131/475498943178866689/unban.gif")
                await embed_message.edit(embed=embed)
        else:
            await ctx.send(
                embed=Embed(color=discord.Color.red(), description="You are not a Global Moderator! Shame!"))
Пример #6
0
    async def _revsync(self, ctx):
        """Sync bans from server to central, and other guilds - GM only."""
        ban_list = await ctx.guild.bans()
        if isModerator(ctx.author.id):
            if not await self.confirmAction(ctx, "revsync"):
                await ctx.send("You took too long to respond, or didn't respond with the correct message...\n" +
                               "Try again?")
                return
            banCountAll = len(ban_list)
            if banCountAll == 0:
                await ctx.send("Sorry, but the guild doesn't have any bans!")
                return

            users = []
            for BanEntry in ban_list:
                users.append(BanEntry.user)

            embed = discord.Embed(title="Revsync in progress...", color=discord.Color.green(),
                                  description="Whoo! Here we goo! Don't worry, the bans are working very hard to "
                                              "reversibly synchronize! 👌")
            embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                             icon_url=ctx.author.avatar_url)
            embed_message = await ctx.send(embed=embed)

            # Perform the bans
            await self.performBan(ctx, users, "Revsync from " + ctx.guild.name + " (" + str(ctx.guild.id) + ")")

            # send final embed, telling the ban was sucessful
            if len(ban_list) == 1:
                desc_string = "Reverse synchronisation complete! %s account has been globally banned 👌" % len(
                    ban_list)
            else:
                desc_string = "Reverse synchronisation complete! %s accounts have been globally banned 👌" % len(
                    ban_list)

            embed = discord.Embed(title="Revsync complete", color=discord.Color.green(),
                                  description=desc_string)
            embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                             icon_url=ctx.author.avatar_url)
            embed.set_image(
                url="https://cdn.discordapp.com/attachments/485619099481800714/485917795679338496/1521567278_980x.gif")
            await embed_message.edit(embed=embed)
        else:
            await ctx.send(
                embed=Embed(color=discord.Color.red(), description="You are not a Global Moderator! Shame!"))
Пример #7
0
 async def _botinfo(self, ctx):
     """Retrives information about the bot - GM only."""
     if isModerator(ctx.author.id):
         embed = discord.Embed(title="Bot Information", color=discord.Color.green(),
                               description="")
         embed.add_field(name="Creation Date",
                         value="%s" % discord.utils.snowflake_time(ctx.bot.user.id).strftime(
                             "%Y-%m-%d %H:%M:%S"), inline=True)
         embed.add_field(name="Guilds", value="%s" % len(self.bot.guilds), inline=True)
         ban_list_guild = self.bot.get_guild(int(os.getenv('banlistguild')))
         ban_list = await ctx.guild.bans()
         embed.add_field(name="Global Bans", value="%s" % len(ban_list), inline=True)
         embed.add_field(name="Central Server", value=ban_list_guild.name,
                         inline=True)
         embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                          icon_url=ctx.author.avatar_url)
         await ctx.send(embed=embed)
     else:
         await ctx.send(
             embed=Embed(color=discord.Color.red(), description="You are not a Global Moderator! Shame!"))
Пример #8
0
    async def _mban(self, ctx, *args):
        """Bans multiple users globally - GM only."""
        if isModerator(ctx.author.id):
            # remove dupes
            args = list(dict.fromkeys(args))
            # sort the args into users and reason
            sortedargs = await self.sortArgs(ctx, args)
            print(sortedargs)
            users = sortedargs[0]
            print(users)
            reason = sortedargs[1]
            print(reason)

            # Sends main embed
            embed = discord.Embed(title="Accounts are being banned...", color=discord.Color.green(),
                                  description="The bans are happening! Woah there! 👌")
            embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                             icon_url=ctx.author.avatar_url)
            embed_message = await ctx.send(embed=embed)

            # Perform the bans
            error = await self.performBan(ctx, users, reason)

            # Do this when done
            # send final embed, telling the ban was sucessful
            if not error:
                embed = discord.Embed(title="Accounts banned", color=discord.Color.green(),
                                      description="All the accounts have been globally banned 👌")
                embed.set_image(
                    url="https://cdn.discordapp.com/attachments/456229881064325131/475498849696219141/ban.gif")
            else:
                embed = discord.Embed(title="Banning failed", color=discord.Color.red(),
                                      description="Error: %s" % error)
                embed.set_image(
                    url="https://cdn.discordapp.com/attachments/474313313598046238/689828429318848517/failed.gif")
            embed.set_footer(text="%s - Global WatchDog Moderator" % ctx.author.name,
                             icon_url=ctx.author.avatar_url)
            await embed_message.edit(embed=embed)
        else:
            await ctx.send(
                embed=Embed(color=discord.Color.red(), description="You are not a Global Moderator! Shame!"))
Пример #9
0
    async def _userinfo(self, ctx, arg1):
        """Gets info about a user."""
        try:
            user = await ctx.bot.fetch_user(arg1)
        except Exception as e:
            logger.logDebug("User not found! - %s" % e)
            try:
                user = await ctx.bot.fetch_user(ctx.message.mentions[0].id)
            except Exception as e:
                logger.logDebug("User not found! - %s" % e)
                try:
                    user = await ctx.bot.fetch_user(ctx.message.mentions[0].id)
                except Exception as e:
                    logger.logDebug("User not found! - %s" % e)
                    try:
                        user = discord.utils.get(ctx.message.guild.members, name=arg1)
                    except Exception as e:
                        logger.logDebug("User not found! - %s" % e)
                        await ctx.send("User not found!")
        if user is None:
            await ctx.send("User not found!")
        else:
            embed = discord.Embed(title="User Information", color=discord.Color.green(),
                                  description="DiscordTag: %s#%s" % (user.name, user.discriminator))
            embed.add_field(name="ID:", value="%s" % user.id, inline=True)
            embed.add_field(name="Created at:",
                            value="%s" % discord.utils.snowflake_time(user.id).strftime("%Y-%m-%d %H:%M:%S"),
                            inline=True)
            isUserBanned = isBanned(user.id)
            embed.add_field(name="Banned:", value="Yes" if isUserBanned else "No", inline=True)
            embed.add_field(name="In guild with bot:", value="Pending...", inline=True)
            if isUserBanned & isModerator(ctx.author.id):
                banreason = getBan(user.id).Reason
                if banreason is None:
                    banreason = "None"
                embed.add_field(name="Ban reason:", value=banreason, inline=True)
            embed.set_thumbnail(url=user.avatar_url)
            embed.set_footer(text="Userinfo requested by %s" % ctx.author.name, icon_url=ctx.author.avatar_url)
            embed_message = await ctx.send(embed=embed)

            inguildwithbot = "No"
            member = None
            for guild in self.bot.guilds:
                if inguildwithbot == "Yes":
                    break
                member = guild.get_member(user.id)
                if member:
                    inguildwithbot = "Yes"
                    break

            if inguildwithbot == "Yes":
                if str(member.status) == "dnd":
                    status = "Do Not Disturb"
                elif str(member.status) == "do_not_disturb":
                    status = "Do Not Disturb"
                elif str(member.status) == "offline":
                    status = "Offline"
                elif str(member.status) == "online":
                    status = "Online"
                elif str(member.status) == "idle":
                    status = "Idle"
                elif str(member.status) == "invisible":
                    status = "Offline"
                else:
                    status = "Unknown"
                embed.add_field(name="Status:", value="%s" % status, inline=True)

            embed.set_field_at(index=3, name="In guild with bot:", value="%s" % inguildwithbot, inline=True)
            await embed_message.edit(embed=embed)