From 61b5730c48ece2352b81fe59aec1b1ea64f9bcd2 Mon Sep 17 00:00:00 2001 From: El Laggron Date: Mon, 3 Jun 2019 17:46:13 +0200 Subject: [PATCH] [V3 Core] More features for the bot invite URL (#1847) * Add inviteset group command * Fix errors * Fix line break * Remove user bot support * Fix docstrings line breaks * Remove embed specific formatting * Remove invite redirect * Add self argument to _can_get_invite_url * Remove unused import * fix errors related to classes + double help * Removed self bot support --- redbot/core/bot.py | 2 ++ redbot/core/core_commands.py | 68 ++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 1c3505d59..531e48d22 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -60,6 +60,8 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d help__verify_checks=True, help__verify_exists=False, help__tagline="", + invite_public=False, + invite_perm=0, disabled_commands=[], disabled_command_msg="That command is disabled.", api_tokens={}, diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 38262fe99..1657f219e 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -265,7 +265,15 @@ class CoreLogic: Invite URL. """ app_info = await self.bot.application_info() - return discord.utils.oauth_url(app_info.id) + perms_int = await self.bot.db.invite_perm() + permissions = discord.Permissions(perms_int) + return discord.utils.oauth_url(app_info.id, permissions) + + @staticmethod + async def _can_get_invite_url(ctx): + is_owner = await ctx.bot.is_owner(ctx.author) + is_invite_public = await ctx.bot.db.invite_public() + return is_owner or is_invite_public @i18n.cog_i18n(_) @@ -441,11 +449,65 @@ class Core(commands.Cog, CoreLogic): await ctx.send(_("No exception has occurred yet")) @commands.command() - @checks.is_owner() - async def invite(self, ctx: commands.Context): + @commands.check(CoreLogic._can_get_invite_url) + async def invite(self, ctx): """Show's Red's invite url""" await ctx.author.send(await self._invite_url()) + @commands.group() + @checks.is_owner() + async def inviteset(self, ctx): + """Setup the bot's invite""" + pass + + @inviteset.command() + async def public(self, ctx, confirm: bool = False): + """ + Define if the command should be accessible\ + for the average users. + """ + if await self.bot.db.invite_public(): + await self.bot.db.invite_public.set(False) + await ctx.send("The invite is now private.") + return + app_info = await self.bot.application_info() + if not app_info.bot_public: + await ctx.send( + "I am not a public bot. That means that nobody except " + "you can invite me on new servers.\n\n" + "You can change this by ticking `Public bot` in " + "your token settings: " + "https://discordapp.com/developers/applications/me/{0}".format(self.bot.user.id) + ) + return + if not confirm: + await ctx.send( + "You're about to make the `{0}invite` command public. " + "All users will be able to invite me on their server.\n\n" + "If you agree, you can type `{0}inviteset public yes`.".format(ctx.prefix) + ) + else: + await self.bot.db.invite_public.set(True) + await ctx.send("The invite command is now public.") + + @inviteset.command() + async def perms(self, ctx, level: int): + """ + Make the bot create its own role with permissions on join. + + The bot will create its own role with the desired permissions\ + when he join a new server. This is a special role that can't be\ + deleted or removed from the bot. + + For that, you need to give a valid permissions level. + You can generate one here: https://discordapi.com/permissions.html + + Please note that you might need the two factor authentification for\ + some permissions. + """ + await self.bot.db.invite_perm.set(level) + await ctx.send("The new permissions level has been set.") + @commands.command() @commands.guild_only() @checks.is_owner()