From 2a23da302ee9310b00364cf633c8df1785d5bc93 Mon Sep 17 00:00:00 2001 From: Red-GitHubBot <88117545+Red-GitHubBot@users.noreply.github.com> Date: Sun, 26 Dec 2021 03:18:16 +0100 Subject: [PATCH] [3.4] Make invite URL part of public API (#5424) (#5491) * [3.4] Make invite URL part of public API (#5424) * Make invite URL public API * Add doc and RPC * Lint * Update redbot/core/core_commands.py Co-authored-by: Matt * Update redbot/core/bot.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * RPC handling, * Fix appinfo * Change docs * Fix docs * Change docs * Update redbot/core/core_commands.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Docstring changes * nit (cherry picked from commit 6297bfcab6def31fdbd1d674336d9493c8c52adb) Co-authored-by: Stonedestroyer <1307729+Stonedestroyer@users.noreply.github.com> Co-authored-by: Matt Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Red->RedBase Co-authored-by: Stonedestroyer <1307729+Stonedestroyer@users.noreply.github.com> Co-authored-by: Matt Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/core/bot.py | 31 +++++++++++++++++++++++++++++++ redbot/core/core_commands.py | 10 ++-------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/redbot/core/bot.py b/redbot/core/bot.py index dd00e15cd..5e295e294 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -1302,6 +1302,37 @@ class RedBase( return ret + async def get_invite_url(self) -> str: + """ + Generates the invite URL for the bot. + + Does not check if the invite URL is configured to be public + with ``[p]inviteset public``. To check if invites are public, + use `RedBase.is_invite_url_public()`. + + Returns + ------- + str + Invite URL. + """ + data = await self._config.all() + commands_scope = data["invite_commands_scope"] + scopes = ("bot", "applications.commands") if commands_scope else None + perms_int = data["invite_perm"] + permissions = discord.Permissions(perms_int) + return discord.utils.oauth_url(self._app_info.id, permissions, scopes=scopes) + + async def is_invite_url_public(self) -> bool: + """ + Determines if invite URL is configured to be public with ``[p]inviteset public``. + + Returns + ------- + bool + :code:`True` if the invite URL is public. + """ + return await self._config.invite_public() + async def is_admin(self, member: discord.Member) -> bool: """Checks if a member is an admin of their guild.""" try: diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index cdcc33601..59f7e00e3 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -360,13 +360,7 @@ class CoreLogic: str Invite URL. """ - app_info = await self.bot.application_info() - data = await self.bot._config.all() - commands_scope = data["invite_commands_scope"] - scopes = ("bot", "applications.commands") if commands_scope else None - perms_int = data["invite_perm"] - permissions = discord.Permissions(perms_int) - return discord.utils.oauth_url(app_info.id, permissions, scopes=scopes) + return await self.bot.get_invite_url() @staticmethod async def _can_get_invite_url(ctx): @@ -1466,7 +1460,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): - `[p]invite` """ try: - await ctx.author.send(await self._invite_url()) + await ctx.author.send(await self.bot.get_invite_url()) await ctx.tick() except discord.errors.Forbidden: await ctx.send(