From 893ab1e960e0d5510b47d079f47eb5ee63818bb2 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Sat, 21 Jul 2018 20:54:12 -0700 Subject: [PATCH] [V3 Dungeon] Add banish command, add DM on verify [p]banish will strip all user roles and apply the dungeon role. [p]dungeon dm with a message will DM users when a [p]dungeon verify command is used on them. --- dungeon/dungeon.py | 84 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/dungeon/dungeon.py b/dungeon/dungeon.py index c26cbb2..9f8a5c4 100644 --- a/dungeon/dungeon.py +++ b/dungeon/dungeon.py @@ -15,6 +15,8 @@ class Dungeon: default_guild = { "announce_channel": None, "auto_blacklist": False, + "dm_message": None, + "dm_toggle": False, "dungeon_channel": None, "dungeon_role": None, "join_days": 7, @@ -26,6 +28,46 @@ class Dungeon: self.config.register_guild(**default_guild) + @checks.mod_or_permissions(administrator=True) + @commands.command() + async def banish(self, ctx, user: discord.Member): + """Strip a user of their roles, apply the dungeon role, and blacklist them. + If the blacklist toggle is off, the user will not be blacklisted from the bot.""" + data = await self.config.guild(ctx.guild).all() + blacklist = data["auto_blacklist"] + dungeon_role_id = data["dungeon_role"] + dungeon_role_obj = discord.utils.get(ctx.guild.roles, id=dungeon_role_id) + + if blacklist: + async with self.bot.db.blacklist() as blacklist_list: + if user.id not in blacklist_list: + blacklist_list.append(user.id) + + if not dungeon_role_obj: + return await ctx.send("No dungeon role set.") + + try: + await user.edit( + roles=[], reason=f"Removing all roles, {ctx.message.author} is banishing user" + ) + except discord.Forbidden: + return await ctx.send( + "I need permission to manage roles or the role hierarchy might not allow me to do this. I need a role higher than the person you're trying to banish." + ) + + await user.add_roles( + dungeon_role_obj, reason=f"Adding dungeon role, {ctx.message.author} is banishing user" + ) + + if blacklist: + blacklist_msg = ", blacklisted from the bot, " + else: + blacklist_msg = "" + msg = ( + f"{user} has been sent to the dungeon{blacklist_msg} and has had all previous roles stripped." + ) + await ctx.send(msg) + @commands.group(autohelp=True) @commands.guild_only() @checks.admin_or_permissions(manage_server=True) @@ -55,6 +97,18 @@ class Dungeon: dungeon_channel_id = await self.config.guild(ctx.guild).dungeon_channel() await ctx.send(f"Dungeon channel set to: {self.bot.get_channel(dungeon_channel_id).name}.") + @dungeon.command() + async def dm(self, ctx, *, dm_message=None): + """Set the message to send on successful verification. + A blank message will turn off the DM setting.""" + if not dm_message: + await self.config.guild(ctx.guild).dm_toggle.set(False) + await self.config.guild(ctx.guild).dm_message.set(None) + return await ctx.send("DM message on verification turned off.") + await self.config.guild(ctx.guild).dm_message.set(str(dm_message)) + await self.config.guild(ctx.guild).dm_toggle.set(True) + await ctx.send(f"DM message on verification turned on.\nMessage to send:\n{dm_message}") + @dungeon.command() async def joindays(self, ctx, days: int): """Set how old an account needs to be a trusted user.""" @@ -104,11 +158,15 @@ class Dungeon: @dungeon.command() async def verify(self, ctx, user: discord.Member): """Verify a user: remove the dungeon role and add initial user role.""" - blacklist = await self.config.guild(ctx.guild).auto_blacklist() - dungeon_role_id = await self.config.guild(ctx.guild).dungeon_role() + data = await self.config.guild(ctx.guild).all() + announce_channel = data["announce_channel"] + blacklist = data["auto_blacklist"] + dungeon_role_id = data["dungeon_role"] dungeon_role_obj = discord.utils.get(ctx.guild.roles, id=dungeon_role_id) - user_role_id = await self.config.guild(ctx.guild).user_role() + user_role_id = data["user_role"] user_role_obj = discord.utils.get(ctx.guild.roles, id=user_role_id) + dm_toggle = data["dm_toggle"] + dm_message = data["dm_message"] if blacklist: async with self.bot.db.blacklist() as blacklist_list: @@ -139,9 +197,19 @@ class Dungeon: blacklist_msg = " and the bot blacklist" else: blacklist_msg = "" - msg = f"{user.name} has been removed from the dungeon{blacklist_msg} and now has the initial user role." + msg = ( + f"{user} has been removed from the dungeon{blacklist_msg} and now has the initial user role." + ) await ctx.send(msg) + if dm_toggle: + try: + await user.send(dm_message) + except discord.Forbidden: + await ctx.send( + f"I couldn't DM {user} to let them know they've been verified, they've blocked me." + ) + @dungeon.command() async def autosetup(self, ctx): """Automatically set up the dungeon channel and role to apply to suspicious users. @@ -211,6 +279,7 @@ class Dungeon: join_days = data["join_days"] auto_blacklist = data["auto_blacklist"] profile_toggle = data["profile_toggle"] + dm_toggle = data["dm_toggle"] msg = ( "```ini\n----Dungeon Settings----\n" @@ -221,7 +290,8 @@ class Dungeon: f"Autorole Enabled: [{user_role_enabled}]\n" f"Autorole Role: [{urole}]\n" f"Auto-blacklist: [{auto_blacklist}]\n" - f"Default PFP Flag: [{profile_toggle}]\n```" + f"Default PFP Flag: [{profile_toggle}]\n" + f"Msg on Verify: [{dm_toggle}]\n```" ) embed = discord.Embed(colour=ctx.guild.me.top_role.colour, description=msg) @@ -265,7 +335,9 @@ class Dungeon: print("dungeon.py: I need permissions to manage channels and manage roles.") return - msg = f"Auto-banished new user: \n**{member.name}#{member.discriminator}** ({member.id})\n{self._dynamic_time(int(since_join.total_seconds()))} old account" + msg = ( + f"Auto-banished new user: \n**{member.name}#{member.discriminator}** ({member.id})\n{self._dynamic_time(int(since_join.total_seconds()))} old account" + ) if default_avatar: msg += ", no profile picture set" await channel_object.send(msg)