From e1226c6c88e7aa4bac5176f103452b8ae81db6d7 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Wed, 21 Oct 2020 20:55:25 +0200 Subject: [PATCH] Update to d.py 1.5.1, explicitly request privileged intents (#4423) Co-authored-by: Draper <27962761+Drapersniper@users.noreply.github.com> --- redbot/__main__.py | 13 +++++++++---- redbot/core/bank.py | 3 ++- redbot/core/bot.py | 6 ++++++ redbot/core/cli.py | 13 +++++++++++++ redbot/core/commands/__init__.py | 12 ++++++++++++ redbot/core/core_commands.py | 9 +++++++++ setup.cfg | 2 +- tests/core/test_commands.py | 17 +++++++++++++++++ 8 files changed, 69 insertions(+), 6 deletions(-) diff --git a/redbot/__main__.py b/redbot/__main__.py index 5f349842c..e09a4c2c3 100644 --- a/redbot/__main__.py +++ b/redbot/__main__.py @@ -300,7 +300,7 @@ def handle_edit(cli_flags: Namespace): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) data_manager.load_basic_configuration(cli_flags.instance_name) - red = Red(cli_flags=cli_flags, description="Red V3", dm_help=None, fetch_offline_members=True) + red = Red(cli_flags=cli_flags, description="Red V3", dm_help=None) try: driver_cls = drivers.get_driver_class() loop.run_until_complete(driver_cls.initialize(**data_manager.storage_details())) @@ -391,6 +391,13 @@ async def run_bot(red: Red, cli_flags: Namespace) -> None: print("Token has been reset.") sys.exit(0) sys.exit(1) + except discord.PrivilegedIntentsRequired: + print( + "Red requires all Privileged Intents to be enabled.\n" + "You can find out how to enable Privileged Intents with this guide:\n" + "https://docs.discord.red/en/stable/bot_application_guide.html#enabling-privileged-intents" + ) + sys.exit(1) return None @@ -487,9 +494,7 @@ def main(): data_manager.load_basic_configuration(cli_flags.instance_name) - red = Red( - cli_flags=cli_flags, description="Red V3", dm_help=None, fetch_offline_members=True - ) + red = Red(cli_flags=cli_flags, description="Red V3", dm_help=None) if os.name != "nt": # None of this works on windows. diff --git a/redbot/core/bank.py b/redbot/core/bank.py index 934cf75aa..e35049ebf 100644 --- a/redbot/core/bank.py +++ b/redbot/core/bank.py @@ -500,7 +500,8 @@ async def bank_prune(bot: Red, guild: discord.Guild = None, user_id: int = None) group = _config._get_base_group(_config.MEMBER, str(guild.id)) if user_id is None: - await bot.request_offline_members(*_guilds) + for _guild in _guilds: + await _guild.chunk() accounts = await group.all() tmp = accounts.copy() members = bot.get_all_members() if global_bank else guild.members diff --git a/redbot/core/bot.py b/redbot/core/bot.py index d46e8d7e5..1eb2644d1 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -172,6 +172,12 @@ class RedBase( if "owner_id" in kwargs: raise RuntimeError("Red doesn't accept owner_id kwarg, use owner_ids instead.") + if "intents" not in kwargs: + intents = discord.Intents.all() + for intent_name in cli_flags.disable_intent: + setattr(intents, intent_name, False) + kwargs["intents"] = intents + self._owner_id_overwrite = cli_flags.owner if "owner_ids" in kwargs: diff --git a/redbot/core/cli.py b/redbot/core/cli.py index 85b13d7bd..b05a7f875 100644 --- a/redbot/core/cli.py +++ b/redbot/core/cli.py @@ -4,6 +4,7 @@ import logging import sys from typing import Optional +import discord from discord import __version__ as discord_version @@ -236,6 +237,18 @@ def parse_cli_flags(args): parser.add_argument( "--no-message-cache", action="store_true", help="Disable the internal message cache." ) + parser.add_argument( + "--disable-intent", + action="append", + choices=list(discord.Intents.VALID_FLAGS), # DEP-WARN + default=[], + help="Unsupported flag that allows disabling the given intent." + " Currently NOT SUPPORTED (and not covered by our version guarantees)" + " as Red is not prepared to work without all intents.\n" + f"Go to https://discordpy.readthedocs.io/en/v{discord_version}/api.html#discord.Intents" + " to see what each intent does.\n" + "This flag can be used multiple times to specify multiple intents.", + ) args = parser.parse_args(args) diff --git a/redbot/core/commands/__init__.py b/redbot/core/commands/__init__.py index 75f664eeb..ab39b3065 100644 --- a/redbot/core/commands/__init__.py +++ b/redbot/core/commands/__init__.py @@ -127,6 +127,7 @@ from discord.ext.commands import ( Greedy as Greedy, ExpectedClosingQuoteError as ExpectedClosingQuoteError, ColourConverter as ColourConverter, + ColorConverter as ColorConverter, VoiceChannelConverter as VoiceChannelConverter, NSFWChannelRequired as NSFWChannelRequired, IDConverter as IDConverter, @@ -145,4 +146,15 @@ from discord.ext.commands import ( MaxConcurrencyReached as MaxConcurrencyReached, bot_has_guild_permissions as bot_has_guild_permissions, CommandRegistrationError as CommandRegistrationError, + MessageNotFound as MessageNotFound, + MemberNotFound as MemberNotFound, + UserNotFound as UserNotFound, + ChannelNotFound as ChannelNotFound, + ChannelNotReadable as ChannelNotReadable, + BadColourArgument as BadColourArgument, + RoleNotFound as RoleNotFound, + BadInviteArgument as BadInviteArgument, + EmojiNotFound as EmojiNotFound, + PartialEmojiConversionFailure as PartialEmojiConversionFailure, + BadBoolArgument as BadBoolArgument, ) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index abb9d44e0..3a02730fa 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -2579,6 +2579,14 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): osver = "Could not parse OS, report this on Github." user_who_ran = getpass.getuser() driver = storage_type() + disabled_intents = ( + ", ".join( + intent_name.replace("_", " ").title() + for intent_name, enabled in self.bot.intents + if not enabled + ) + or "None" + ) if await ctx.embed_requested(): e = discord.Embed(color=await ctx.embed_colour()) e.title = "Debug Info for Red" @@ -2595,6 +2603,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): inline=False, ) e.add_field(name="Storage type", value=driver, inline=False) + e.add_field(name="Disabled intents", value=disabled_intents, inline=False) await ctx.send(embed=e) else: info = ( diff --git a/setup.cfg b/setup.cfg index 00755ecdd..df744672f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,7 +44,7 @@ install_requires = click==7.1.2 colorama==0.4.3 contextlib2==0.6.0.post1 - discord.py==1.4.1 + discord.py==1.5.1 distro==1.5.0; sys_platform == "linux" fuzzywuzzy==0.18.0 idna==2.10 diff --git a/tests/core/test_commands.py b/tests/core/test_commands.py index 9217fc114..a0241f4f2 100644 --- a/tests/core/test_commands.py +++ b/tests/core/test_commands.py @@ -1,4 +1,8 @@ +import inspect + import pytest +from discord.ext import commands as dpy_commands + from redbot.core import commands @@ -32,3 +36,16 @@ def test_group_decorator_methods(group, coroutine): def test_bot_decorator_methods(red, coroutine): assert is_Command(red.command(name="cmd")(coroutine)) assert is_Group(red.group(name="grp")(coroutine)) + + +def test_dpy_commands_reexports(): + dpy_attrs = set() + for attr_name, attr_value in dpy_commands.__dict__.items(): + if attr_name.startswith("_") or inspect.ismodule(attr_value): + continue + + dpy_attrs.add(attr_name) + + missing_attrs = dpy_attrs - set(commands.__dict__.keys()) + + assert not missing_attrs