mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-08 02:12:32 -05:00
Migration to discord.py 2.0 (#5600)
* Temporarily set d.py to use latest git revision
* Remove `bot` param to Client.start
* Switch to aware datetimes
A lot of this is removing `.replace(...)` which while not technically
needed, simplifies the code base. There's only a few changes that are
actually necessary here.
* Update to work with new Asset design
* [threads] Update core ModLog API to support threads
- Added proper support for passing `Thread` to `channel`
when creating/editing case
- Added `parent_channel_id` attribute to Modlog API's Case
- Added `parent_channel` property that tries to get parent channel
- Updated case's content to show both thread and parent information
* [threads] Disallow usage of threads in some of the commands
- announceset channel
- filter channel clear
- filter channel add
- filter channel remove
- GlobalUniqueObjectFinder converter
- permissions addglobalrule
- permissions removeglobalrule
- permissions removeserverrule
- Permissions cog does not perform any validation for IDs
when setting through YAML so that has not been touched
- streamalert twitch/youtube/picarto
- embedset channel
- set ownernotifications adddestination
* [threads] Handle threads in Red's permissions system (Requires)
- Made permissions system apply rules of (only) parent in threads
* [threads] Update embed_requested to support threads
- Threads don't have their own embed settings and inherit from parent
* [threads] Update Red.message_eligible_as_command to support threads
* [threads] Properly handle invocation of [p](un)mutechannel in threads
Usage of a (un)mutechannel will mute/unmute user in the parent channel
if it's invoked in a thread.
* [threads] Update Filter cog to properly handle threads
- `[p]filter channel list` in a threads sends list for parent channel
- Checking for filter hits for a message in a thread checks its parent
channel's word list. There's no separate word list for threads.
* [threads] Support threads in Audio cog
- Handle threads being notify channels
- Update type hint for `is_query_allowed()`
* [threads] Update type hints and documentation to reflect thread support
- Documented that `{channel}` in CCs might be a thread
- Allowed (documented) usage of threads with `Config.channel()`
- Separate thread scope is still in the picture though
if it were to be done, it's going to be in separate in PR
- GuildContext.channel might be Thread
* Use less costy channel check in customcom's on_message_without_command
This isn't needed for d.py 2.0 but whatever...
* Update for in-place edits
* Embed's bool changed behavior, I'm hoping it doesn't affect us
* Address User.permissions_in() removal
* Swap VerificationLevel.extreme with VerificationLevel.highest
* Change to keyword-only parameters
* Change of `Guild.vanity_invite()` return type
* avatar -> display_avatar
* Fix metaclass shenanigans with Converter
* Update Red.add_cog() to be inline with `dpy_commands.Bot.add_cog()`
This means adding `override` keyword-only parameter and causing
small breakage by swapping RuntimeError with discord.ClientException.
* Address all DEP-WARNs
* Remove Context.clean_prefix and use upstream implementation instead
* Remove commands.Literal and use upstream implementation instead
Honestly, this was a rather bad implementation anyway...
Breaking but actually not really - it was provisional.
* Update Command.callback's setter
Support for functools.partial is now built into d.py
* Add new perms in HUMANIZED_PERM mapping (some from d.py 1.7 it seems)
BTW, that should really be in core instead of what we have now...
* Remove the part of do_conversion that has not worked for a long while
* Stop wrapping BadArgument in ConversionFailure
This is breaking but it's best to resolve it like this.
The functionality of ConversionFailure can be replicated with
Context.current_parameter and Context.current_argument.
* Add custom errors for int and float converters
* Remove Command.__call__ as it's now implemented in d.py
* Get rid of _dpy_reimplements
These were reimplemented for the purpose of typing
so it is no longer needed now that d.py is type hinted.
* Add return to Red.remove_cog
* Ensure we don't delete messages that differ only by used sticker
* discord.InvalidArgument->ValueError
* Move from raw <t:...> syntax to discord.utils.format_dt()
* Address AsyncIter removal
* Swap to pos-only for params that are pos-only in upstream
* Update for changes to Command.params
* [threads] Support threads in ignore checks and allow ignoring them
- Updated `[p](un)ignore channel` to accept threads
- Updated `[p]ignore list` to list ignored threads
- Updated logic in `Red.ignored_channel_or_guild()`
Ignores for guild channels now work as follows (only changes for threads):
- if channel is not a thread:
- check if user has manage channels perm in channel
and allow command usage if so
- check if channel is ignored and disallow command usage if so
- allow command usage if none of the conditions above happened
- if channel is a thread:
- check if user has manage channels perm in parent channel
and allow command usage if so
- check if parent channel is ignored and disallow command usage
if so
- check if user has manage thread perm in parent channel
and allow command usage if so
- check if thread is ignored and disallow command usage if so
- allow command usage if none of the conditions above happened
* [partial] Raise TypeError when channel is of PartialMessageable type
- Red.embed_requested
- Red.ignored_channel_or_guild
* [partial] Discard command messages when channel is PartialMessageable
* [threads] Add utilities for checking appropriate perms in both channels & threads
* [threads] Update code to use can_react_in() and @bot_can_react()
* [threads] Update code to use can_send_messages_in
* [threads] Add send_messages_in_threads perm to mute role and overrides
* [threads] Update code to use (bot/user)_can_manage_channel
* [threads] Update [p]diagnoseissues to work with threads
* Type hint fix
* [threads] Patch vendored discord.ext.menus to check proper perms in threads
I guess we've reached time when we have to patch the lib we vendor...
* Make docs generation work with non-final d.py releases
* Update discord.utils.oauth_url() usage
* Swap usage of discord.Embed.Empty/discord.embeds.EmptyEmbed to None
* Update usage of Guild.member_count to work with `None`
* Switch from Guild.vanity_invite() to Guild.vanity_url
* Update startup process to work with d.py's new asynchronous startup
* Use setup_hook() for pre-connect actions
* Update core's add_cog, remove_cog, and load_extension methods
* Update all setup functions to async and add awaits to bot.add_cog calls
* Modernize cogs by using async cog_load and cog_unload
* Address StoreChannel removal
* [partial] Disallow passing PartialMessageable to Case.channel
* [partial] Update cogs and utils to work better with PartialMessageable
- Ignore messages with PartialMessageable channel in CustomCommands cog
- In Filter cog, don't pass channel to modlog.create_case()
if it's PartialMessageable
- In Trivia cog, only compare channel IDs
- Make `.utils.menus.menu()` work for messages
with PartialMessageable channel
- Make checks in `.utils.tunnel.Tunnel.communicate()` more rigid
* Add few missing DEP-WARNs
This commit is contained in:
@@ -197,7 +197,7 @@ class AudioEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
):
|
||||
if not guild:
|
||||
return
|
||||
notify_channel = guild.get_channel(player.fetch("notify_channel"))
|
||||
notify_channel = guild.get_channel_or_thread(player.fetch("notify_channel"))
|
||||
has_perms = self._has_notify_perms(notify_channel)
|
||||
tries = 0
|
||||
while not player._is_playing:
|
||||
|
||||
@@ -18,6 +18,7 @@ from lavalink import NodeNotFound, PlayerNotFound
|
||||
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import can_user_send_messages_in
|
||||
from redbot.core.utils.antispam import AntiSpam
|
||||
from redbot.core.utils.chat_formatting import box, humanize_list, underline, bold
|
||||
|
||||
@@ -61,6 +62,16 @@ HUMANIZED_PERM = {
|
||||
"manage_roles": _("Manage Roles"),
|
||||
"manage_webhooks": _("Manage Webhooks"),
|
||||
"manage_emojis": _("Manage Emojis"),
|
||||
"use_slash_commands": _("Use Slash Commands"),
|
||||
"request_to_speak": _("Request to Speak"),
|
||||
"manage_events": _("Manage Events"),
|
||||
"manage_threads": _("Manage Threads"),
|
||||
"create_public_threads": _("Create Public Threads"),
|
||||
"create_private_threads": _("Create Private Threads"),
|
||||
"external_stickers": _("Use External Stickers"),
|
||||
"send_messages_in_threads": _("Send Messages in Threads"),
|
||||
"start_embedded_activities": _("Start Activities"),
|
||||
"moderate_members": _("Moderate Member"),
|
||||
}
|
||||
|
||||
DANGEROUS_COMMANDS = {
|
||||
@@ -175,13 +186,31 @@ class DpyEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
"Not running Audio command due to invalid machine architecture for the managed Lavalink node."
|
||||
)
|
||||
|
||||
current_perms = ctx.channel.permissions_for(ctx.me)
|
||||
surpass_ignore = (
|
||||
isinstance(ctx.channel, discord.abc.PrivateChannel)
|
||||
or await ctx.bot.is_owner(ctx.author)
|
||||
or await ctx.bot.is_admin(ctx.author)
|
||||
)
|
||||
guild = ctx.guild
|
||||
if guild and not can_user_send_messages_in(ctx.me, ctx.channel):
|
||||
log.debug(
|
||||
"Missing perms to send messages in %d, Owner ID: %d",
|
||||
guild.id,
|
||||
guild.owner.id,
|
||||
)
|
||||
if not surpass_ignore:
|
||||
text = _(
|
||||
"I'm missing permissions to send messages in this server. "
|
||||
"Please address this as soon as possible."
|
||||
)
|
||||
log.info(
|
||||
"Missing write permission in %d, Owner ID: %d",
|
||||
guild.id,
|
||||
guild.owner.id,
|
||||
)
|
||||
raise CheckFailure(message=text)
|
||||
|
||||
current_perms = ctx.channel.permissions_for(ctx.me)
|
||||
if guild and not current_perms.is_superset(self.permission_cache):
|
||||
current_perms_set = set(iter(current_perms))
|
||||
expected_perms_set = set(iter(self.permission_cache))
|
||||
@@ -207,14 +236,7 @@ class DpyEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
perm=_(HUMANIZED_PERM.get(perm, perm)),
|
||||
)
|
||||
text = text.strip()
|
||||
if current_perms.send_messages and current_perms.read_messages:
|
||||
await ctx.send(box(text=text, lang="ini"))
|
||||
else:
|
||||
log.info(
|
||||
"Missing write permission in %s, Owner ID: %s",
|
||||
ctx.guild.id,
|
||||
ctx.guild.owner.id,
|
||||
)
|
||||
await ctx.send(box(text=text, lang="ini"))
|
||||
raise CheckFailure(message=text)
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
@@ -312,7 +334,7 @@ class DpyEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
)
|
||||
if error.send_cmd_help:
|
||||
await ctx.send_help()
|
||||
elif isinstance(error, commands.ConversionFailure):
|
||||
elif isinstance(error, commands.BadArgument):
|
||||
handled = True
|
||||
if error.args:
|
||||
if match := RE_CONVERSION.search(error.args[0]):
|
||||
@@ -390,10 +412,10 @@ class DpyEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if not handled:
|
||||
await self.bot.on_command_error(ctx, error, unhandled_by_cog=True)
|
||||
|
||||
def cog_unload(self) -> None:
|
||||
async def cog_unload(self) -> None:
|
||||
if not self.cog_cleaned_up:
|
||||
self.bot.dispatch("red_audio_unload", self)
|
||||
self.session.detach()
|
||||
await self.session.close()
|
||||
if self.player_automated_timer_task:
|
||||
self.player_automated_timer_task.cancel()
|
||||
|
||||
@@ -408,10 +430,10 @@ class DpyEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
|
||||
lavalink.unregister_event_listener(self.lavalink_event_handler)
|
||||
lavalink.unregister_update_listener(self.lavalink_update_handler)
|
||||
asyncio.create_task(lavalink.close(self.bot))
|
||||
asyncio.create_task(self._close_database())
|
||||
await lavalink.close(self.bot)
|
||||
await self._close_database()
|
||||
if self.managed_node_controller is not None:
|
||||
asyncio.create_task(self.managed_node_controller.shutdown())
|
||||
await self.managed_node_controller.shutdown()
|
||||
|
||||
self.cog_cleaned_up = True
|
||||
|
||||
|
||||
@@ -165,14 +165,14 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
try:
|
||||
await self.api_interface.autoplay(player, self.playlist_api)
|
||||
except DatabaseError:
|
||||
notify_channel = guild.get_channel(notify_channel_id)
|
||||
notify_channel = guild.get_channel_or_thread(notify_channel_id)
|
||||
if notify_channel and self._has_notify_perms(notify_channel):
|
||||
await self.send_embed_msg(
|
||||
notify_channel, title=_("Couldn't get a valid track.")
|
||||
)
|
||||
return
|
||||
except TrackEnqueueError:
|
||||
notify_channel = guild.get_channel(notify_channel_id)
|
||||
notify_channel = guild.get_channel_or_thread(notify_channel_id)
|
||||
if notify_channel and self._has_notify_perms(notify_channel):
|
||||
await self.send_embed_msg(
|
||||
notify_channel,
|
||||
@@ -185,7 +185,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
return
|
||||
if event_type == lavalink.LavalinkEvents.TRACK_START and notify:
|
||||
notify_channel_id = player.fetch("notify_channel")
|
||||
notify_channel = guild.get_channel(notify_channel_id)
|
||||
notify_channel = guild.get_channel_or_thread(notify_channel_id)
|
||||
if notify_channel and self._has_notify_perms(notify_channel):
|
||||
if player.fetch("notify_message") is not None:
|
||||
with contextlib.suppress(discord.HTTPException):
|
||||
@@ -226,7 +226,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if event_type == lavalink.LavalinkEvents.QUEUE_END:
|
||||
if not autoplay:
|
||||
notify_channel_id = player.fetch("notify_channel")
|
||||
notify_channel = guild.get_channel(notify_channel_id)
|
||||
notify_channel = guild.get_channel_or_thread(notify_channel_id)
|
||||
if notify_channel and notify and self._has_notify_perms(notify_channel):
|
||||
await self.send_embed_msg(notify_channel, title=_("Queue ended."))
|
||||
if disconnect:
|
||||
@@ -282,7 +282,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
self._ll_guild_updates.discard(guild_id)
|
||||
self.bot.dispatch("red_audio_audio_disconnect", guild)
|
||||
if message_channel:
|
||||
message_channel = guild.get_channel(message_channel)
|
||||
message_channel = guild.get_channel_or_thread(message_channel)
|
||||
if early_exit:
|
||||
log.warning(
|
||||
"Audio detected multiple continuous errors during playback "
|
||||
|
||||
Reference in New Issue
Block a user