mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Reformat with Black 22.1.0
This commit is contained in:
parent
f6d9632c8f
commit
c69e8d31fd
@ -96,7 +96,6 @@ class Admin(commands.Cog):
|
||||
return
|
||||
|
||||
async def handle_migrations(self):
|
||||
|
||||
lock = self.config.get_guilds_lock()
|
||||
async with lock:
|
||||
# This prevents the edge case of someone loading admin,
|
||||
@ -110,7 +109,6 @@ class Admin(commands.Cog):
|
||||
self._ready.set()
|
||||
|
||||
async def migrate_config_from_0_to_1(self):
|
||||
|
||||
all_guilds = await self.config.all_guilds()
|
||||
|
||||
for guild_id, guild_data in all_guilds.items():
|
||||
|
||||
@ -94,12 +94,10 @@ class Alias(commands.Cog):
|
||||
all_guild_aliases = await self.config.all_guilds()
|
||||
|
||||
for guild_id, guild_data in all_guild_aliases.items():
|
||||
|
||||
to_set = []
|
||||
modified = False
|
||||
|
||||
for a in guild_data.get("entries", []):
|
||||
|
||||
for keyname in ("creator", "guild"):
|
||||
if isinstance((val := a.get(keyname)), str):
|
||||
try:
|
||||
@ -482,7 +480,6 @@ class Alias(commands.Cog):
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message_without_command(self, message: discord.Message):
|
||||
|
||||
await self._ready_event.wait()
|
||||
|
||||
if message.guild is not None:
|
||||
|
||||
@ -67,7 +67,6 @@ class AliasEntry:
|
||||
return extra
|
||||
|
||||
def to_json(self) -> dict:
|
||||
|
||||
return {
|
||||
"name": self.name,
|
||||
"command": self.command,
|
||||
@ -91,7 +90,6 @@ class AliasCache:
|
||||
self._aliases: Dict[Optional[int], Dict[str, AliasEntry]] = {None: {}}
|
||||
|
||||
async def anonymize_aliases(self, user_id: int):
|
||||
|
||||
async with self.config.entries() as global_aliases:
|
||||
for a in global_aliases:
|
||||
if a.get("creator", 0) == user_id:
|
||||
|
||||
@ -182,7 +182,6 @@ class PlaylistCompat23:
|
||||
tracks: Optional[List[MutableMapping]] = None,
|
||||
guild: Union[discord.Guild, int, None] = None,
|
||||
):
|
||||
|
||||
self.bot = bot
|
||||
self.guild = guild
|
||||
self.scope = standardize_scope(scope)
|
||||
|
||||
@ -192,7 +192,6 @@ class ScopeParser(commands.Converter):
|
||||
async def convert(
|
||||
self, ctx: commands.Context, argument: str
|
||||
) -> Tuple[Optional[str], discord.User, Optional[discord.Guild], bool]:
|
||||
|
||||
target_scope: Optional[str] = None
|
||||
target_user: Optional[Union[discord.Member, discord.User]] = None
|
||||
target_guild: Optional[discord.Guild] = None
|
||||
@ -302,7 +301,6 @@ class ComplexScopeParser(commands.Converter):
|
||||
Optional[discord.Guild],
|
||||
bool,
|
||||
]:
|
||||
|
||||
target_scope: Optional[str] = None
|
||||
target_user: Optional[Union[discord.Member, discord.User]] = None
|
||||
target_guild: Optional[discord.Guild] = None
|
||||
|
||||
@ -244,7 +244,7 @@ class EqualizerCommands(MixinMeta, metaclass=CompositeMetaClass):
|
||||
eq_name_msg = await self.bot.wait_for(
|
||||
"message",
|
||||
timeout=15.0,
|
||||
check=MessagePredicate.regex(fr"^(?!{re.escape(ctx.prefix)})", ctx),
|
||||
check=MessagePredicate.regex(rf"^(?!{re.escape(ctx.prefix)})", ctx),
|
||||
)
|
||||
eq_preset = eq_name_msg.content.split(" ")[0].strip('"').lower()
|
||||
except asyncio.TimeoutError:
|
||||
|
||||
@ -224,7 +224,6 @@ class PlaylistCommands(MixinMeta, metaclass=CompositeMetaClass):
|
||||
*,
|
||||
scope_data: ComplexScopeParser = None,
|
||||
):
|
||||
|
||||
"""Copy a playlist from one scope to another.
|
||||
|
||||
**Usage**:
|
||||
@ -962,7 +961,6 @@ class PlaylistCommands(MixinMeta, metaclass=CompositeMetaClass):
|
||||
scope, author, guild, specified_user = scope_data
|
||||
async with ctx.typing():
|
||||
if scope is None:
|
||||
|
||||
global_matches = await get_all_playlist(
|
||||
scope=PlaylistScope.GLOBAL.value,
|
||||
bot=self.bot,
|
||||
|
||||
@ -31,7 +31,6 @@ class RedEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
requester: Literal["discord_deleted_user", "owner", "user", "user_strict"],
|
||||
user_id: int,
|
||||
):
|
||||
|
||||
await self.cog_ready_event.wait()
|
||||
|
||||
if requester in ("discord_deleted_user", "owner"):
|
||||
|
||||
@ -167,7 +167,6 @@ class FormattingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
ctx, title=_("This track is not allowed in this server.")
|
||||
)
|
||||
elif guild_data["maxlength"] > 0:
|
||||
|
||||
if self.is_track_length_allowed(search_choice, guild_data["maxlength"]):
|
||||
search_choice.extras.update(
|
||||
{
|
||||
|
||||
@ -11,7 +11,7 @@ from ..cog_utils import CompositeMetaClass
|
||||
|
||||
log = getLogger("red.cogs.Audio.cog.Utilities.Parsing")
|
||||
|
||||
STREAM_TITLE: Final[re.Pattern] = re.compile(br"StreamTitle='([^']*)';")
|
||||
STREAM_TITLE: Final[re.Pattern] = re.compile(rb"StreamTitle='([^']*)';")
|
||||
|
||||
|
||||
class ParsingUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
|
||||
@ -676,7 +676,6 @@ class PlaylistUtilities(MixinMeta, metaclass=CompositeMetaClass):
|
||||
def humanize_scope(
|
||||
self, scope: str, ctx: Union[discord.Guild, discord.abc.User, str] = None, the: bool = None
|
||||
) -> Optional[str]:
|
||||
|
||||
if scope == PlaylistScope.GLOBAL.value:
|
||||
return _("the Global") if the else _("Global")
|
||||
elif scope == PlaylistScope.GUILD.value:
|
||||
|
||||
@ -155,7 +155,7 @@ class Cleanup(commands.Cog):
|
||||
resolved = reference.resolved
|
||||
if resolved and isinstance(resolved, discord.Message):
|
||||
message = resolved
|
||||
elif (message := reference.cached_message) :
|
||||
elif message := reference.cached_message:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
|
||||
@ -59,7 +59,6 @@ class CommandObj:
|
||||
return {k: v for k, v in _commands.items() if _commands[k]}
|
||||
|
||||
async def redact_author_ids(self, user_id: int):
|
||||
|
||||
all_guilds = await self.config.all_guilds()
|
||||
|
||||
for guild_id in all_guilds.keys():
|
||||
|
||||
@ -349,7 +349,6 @@ class Economy(commands.Cog):
|
||||
).format(author=author, time=dtime)
|
||||
)
|
||||
else:
|
||||
|
||||
# Gets the users latest successfully payday and adds the guilds payday time
|
||||
next_payday = (
|
||||
await self.config.member(author).next_payday()
|
||||
|
||||
@ -399,7 +399,6 @@ class Filter(commands.Cog):
|
||||
async def filter_hits(
|
||||
self, text: str, server_or_channel: Union[discord.Guild, discord.TextChannel]
|
||||
) -> Set[str]:
|
||||
|
||||
try:
|
||||
guild = server_or_channel.guild
|
||||
channel = server_or_channel
|
||||
@ -528,7 +527,6 @@ class Filter(commands.Cog):
|
||||
await self.maybe_filter_name(member)
|
||||
|
||||
async def maybe_filter_name(self, member: discord.Member):
|
||||
|
||||
guild = member.guild
|
||||
if (not guild) or await self.bot.cog_disabled_in_guild(self, guild):
|
||||
return
|
||||
|
||||
@ -226,7 +226,6 @@ class ModInfo(MixinMeta):
|
||||
status_string = self.get_status_string(member)
|
||||
|
||||
if roles:
|
||||
|
||||
role_str = ", ".join([x.mention for x in roles])
|
||||
# 400 BAD REQUEST (error code: 50035): Invalid Form Body
|
||||
# In embed.fields.2.value: Must be 1024 or fewer in length.
|
||||
|
||||
@ -1065,7 +1065,6 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
|
||||
if ctx.guild.id in self._server_mutes:
|
||||
mutes_data = self._server_mutes[ctx.guild.id]
|
||||
if mutes_data:
|
||||
|
||||
msg += _("__Server Mutes__\n")
|
||||
for user_id, mutes in mutes_data.items():
|
||||
if not mutes:
|
||||
@ -1528,7 +1527,6 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
|
||||
mute_role = await self.config.guild(guild).mute_role()
|
||||
|
||||
if mute_role:
|
||||
|
||||
role = guild.get_role(mute_role)
|
||||
if not role:
|
||||
ret["reason"] = _(MUTE_UNMUTE_ISSUES["role_missing"])
|
||||
@ -1601,8 +1599,8 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
|
||||
if not await self.is_allowed_by_hierarchy(guild, author, user):
|
||||
ret["reason"] = _(MUTE_UNMUTE_ISSUES["hierarchy_problem"])
|
||||
return ret
|
||||
if mute_role:
|
||||
|
||||
if mute_role:
|
||||
role = guild.get_role(mute_role)
|
||||
if not role:
|
||||
ret["reason"] = _(MUTE_UNMUTE_ISSUES["role_missing"])
|
||||
|
||||
@ -55,7 +55,6 @@ class VoiceMutes(MixinMeta):
|
||||
ctx.permission_state is commands.PermState.NORMAL
|
||||
and not voice_channel.permissions_for(ctx.author) >= required_perms
|
||||
):
|
||||
|
||||
return (
|
||||
False,
|
||||
_(
|
||||
|
||||
@ -131,7 +131,6 @@ class Permissions(commands.Cog):
|
||||
# there's a below recast to int where needed for guild ids
|
||||
|
||||
for typename, getter in ((COG, self.bot.get_cog), (COMMAND, self.bot.get_command)):
|
||||
|
||||
obj_type_rules = await self.config.custom(typename).all()
|
||||
|
||||
count += 1
|
||||
@ -139,7 +138,6 @@ class Permissions(commands.Cog):
|
||||
await asyncio.sleep(0)
|
||||
|
||||
for obj_name, rules_dict in obj_type_rules.items():
|
||||
|
||||
count += 1
|
||||
if not count % 100:
|
||||
await asyncio.sleep(0)
|
||||
@ -147,7 +145,6 @@ class Permissions(commands.Cog):
|
||||
obj = getter(obj_name)
|
||||
|
||||
for guild_id, guild_rules in rules_dict.items():
|
||||
|
||||
count += 1
|
||||
if not count % 100:
|
||||
await asyncio.sleep(0)
|
||||
|
||||
@ -356,11 +356,9 @@ class Reports(commands.Cog):
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message: discord.Message):
|
||||
|
||||
to_remove = []
|
||||
|
||||
for k, v in self.tunnel_store.items():
|
||||
|
||||
guild, ticket_number = k
|
||||
if await self.bot.cog_disabled_in_guild(self, guild):
|
||||
to_remove.append(k)
|
||||
|
||||
@ -263,7 +263,6 @@ class YoutubeStream(Stream):
|
||||
return snippet["title"]
|
||||
|
||||
async def _fetch_channel_resource(self, resource: str):
|
||||
|
||||
params = {"key": self._token["api_key"], "part": resource}
|
||||
if resource == "id":
|
||||
params["forUsername"] = self.name
|
||||
@ -334,8 +333,8 @@ class TwitchStream(Stream):
|
||||
"""
|
||||
current_time = int(time.time())
|
||||
self._rate_limit_resets = {x for x in self._rate_limit_resets if x > current_time}
|
||||
if self._rate_limit_remaining == 0:
|
||||
|
||||
if self._rate_limit_remaining == 0:
|
||||
if self._rate_limit_resets:
|
||||
reset_time = next(iter(self._rate_limit_resets))
|
||||
# Calculate wait time and add 0.1s to the wait time to allow Twitch to reset
|
||||
|
||||
@ -661,7 +661,6 @@ class Command(CogCommandMixin, DPYCommand):
|
||||
|
||||
@a_command.error
|
||||
async def a_command_error_handler(self, ctx, error):
|
||||
|
||||
if isinstance(error.original, MyErrorType):
|
||||
self.log_exception(error.original)
|
||||
else:
|
||||
|
||||
@ -360,7 +360,6 @@ if TYPE_CHECKING or os.getenv("BUILDING_DOCS", False):
|
||||
def me(self) -> discord.Member:
|
||||
...
|
||||
|
||||
|
||||
else:
|
||||
GuildContext = Context
|
||||
DMContext = Context
|
||||
|
||||
@ -274,7 +274,6 @@ if TYPE_CHECKING:
|
||||
def get_dict_converter(*expected_keys: str, delims: Optional[List[str]] = None) -> Type[dict]:
|
||||
...
|
||||
|
||||
|
||||
else:
|
||||
|
||||
def get_dict_converter(*expected_keys: str, delims: Optional[List[str]] = None) -> Type[dict]:
|
||||
@ -354,7 +353,6 @@ if TYPE_CHECKING:
|
||||
) -> Type[timedelta]:
|
||||
...
|
||||
|
||||
|
||||
else:
|
||||
|
||||
def get_timedelta_converter(
|
||||
|
||||
@ -306,7 +306,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
async def format_command_help(
|
||||
self, ctx: Context, obj: commands.Command, help_settings: HelpSettings
|
||||
):
|
||||
|
||||
send = help_settings.verify_exists
|
||||
if not send:
|
||||
async for __ in self.help_filter_func(
|
||||
@ -450,7 +449,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
|
||||
@staticmethod
|
||||
def group_embed_fields(fields: List[EmbedField], max_chars=1000):
|
||||
|
||||
curr_group = []
|
||||
ret = []
|
||||
current_count = 0
|
||||
@ -473,7 +471,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
return ret
|
||||
|
||||
async def make_and_send_embeds(self, ctx, embed_dict: dict, help_settings: HelpSettings):
|
||||
|
||||
pages = []
|
||||
|
||||
page_char_limit = help_settings.page_char_limit
|
||||
@ -544,7 +541,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
await self.send_pages(ctx, pages, embed=True, help_settings=help_settings)
|
||||
|
||||
async def format_cog_help(self, ctx: Context, obj: commands.Cog, help_settings: HelpSettings):
|
||||
|
||||
coms = await self.get_cog_help_mapping(ctx, obj, help_settings=help_settings)
|
||||
if not (coms or help_settings.verify_exists):
|
||||
return
|
||||
@ -613,7 +609,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
await self.send_pages(ctx, pages, embed=False, help_settings=help_settings)
|
||||
|
||||
async def format_bot_help(self, ctx: Context, help_settings: HelpSettings):
|
||||
|
||||
coms = await self.get_bot_help_mapping(ctx, help_settings=help_settings)
|
||||
if not coms:
|
||||
return
|
||||
@ -622,7 +617,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
tagline = (help_settings.tagline) or self.get_default_tagline(ctx)
|
||||
|
||||
if await self.embed_requested(ctx):
|
||||
|
||||
emb = {"embed": {"title": "", "description": ""}, "footer": {"text": ""}, "fields": []}
|
||||
|
||||
emb["footer"]["text"] = tagline
|
||||
@ -630,7 +624,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
emb["embed"]["title"] = f"*{description[:250]}*"
|
||||
|
||||
for cog_name, data in coms:
|
||||
|
||||
if cog_name:
|
||||
title = underline(bold(f"{cog_name}:"), escape_formatting=False)
|
||||
else:
|
||||
@ -676,7 +669,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
yield nm, doc, max_width - width_gap
|
||||
|
||||
for cog_name, data in coms:
|
||||
|
||||
title = f"{cog_name}:" if cog_name else _("No Category:")
|
||||
to_join.append(title)
|
||||
|
||||
@ -830,7 +822,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
and channel_permissions.read_message_history
|
||||
and help_settings.use_menus
|
||||
):
|
||||
|
||||
max_pages_in_guild = help_settings.max_pages_in_guild
|
||||
use_DMs = len(pages) > max_pages_in_guild
|
||||
destination = ctx.author if use_DMs else ctx.channel
|
||||
@ -862,7 +853,6 @@ class RedHelpFormatter(HelpFormatterABC):
|
||||
and delete_delay > 0 # delete delay is enabled
|
||||
and channel_permissions.manage_messages # we can manage messages here
|
||||
):
|
||||
|
||||
# We need to wrap this in a task to not block after-sending-help interactions.
|
||||
# The channel has to be TextChannel as we can't bulk-delete from DMs
|
||||
async def _delete_delay_help(
|
||||
|
||||
@ -268,7 +268,6 @@ PermStateAllowedStates = (
|
||||
|
||||
|
||||
def transition_permstate_to(prev: PermState, next_state: PermState) -> TransitionResult:
|
||||
|
||||
# Transforms here are used so that the
|
||||
# informational ALLOWED_BY_HOOK/DENIED_BY_HOOK
|
||||
# remain, while retaining the behavior desired.
|
||||
|
||||
@ -645,7 +645,6 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
)
|
||||
|
||||
async def get_serious_confirmation(self, ctx: commands.Context, prompt: str) -> bool:
|
||||
|
||||
confirm_token = "".join(random.choices((*ascii_letters, *digits), k=8))
|
||||
|
||||
await ctx.send(f"{prompt}\n\n{confirm_token}")
|
||||
@ -4002,9 +4001,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
|
||||
)
|
||||
else:
|
||||
successful = True
|
||||
|
||||
else:
|
||||
|
||||
msg_text = "{}\nMessage:\n\n{}\n{}".format(description, message, footer)
|
||||
|
||||
try:
|
||||
|
||||
@ -198,7 +198,6 @@ def init_events(bot, cli_flags):
|
||||
|
||||
@bot.event
|
||||
async def on_command_error(ctx, error, unhandled_by_cog=False):
|
||||
|
||||
if not unhandled_by_cog:
|
||||
if hasattr(ctx.command, "on_error"):
|
||||
return
|
||||
|
||||
@ -98,7 +98,6 @@ async def _init(bot: Red):
|
||||
await register_casetypes(all_generics)
|
||||
|
||||
async def on_member_ban(guild: discord.Guild, member: discord.Member):
|
||||
|
||||
if not guild.me.guild_permissions.view_audit_log:
|
||||
return
|
||||
|
||||
|
||||
@ -178,7 +178,6 @@ class IgnoreManager:
|
||||
async def set_ignored_channel(
|
||||
self, channel: Union[discord.TextChannel, discord.CategoryChannel], set_to: bool
|
||||
):
|
||||
|
||||
cid: int = channel.id
|
||||
self._cached_channels[cid] = set_to
|
||||
if set_to:
|
||||
@ -200,7 +199,6 @@ class IgnoreManager:
|
||||
return ret
|
||||
|
||||
async def set_ignored_guild(self, guild: discord.Guild, set_to: bool):
|
||||
|
||||
gid: int = guild.id
|
||||
self._cached_guilds[gid] = set_to
|
||||
if set_to:
|
||||
@ -221,9 +219,7 @@ class WhitelistBlacklistManager:
|
||||
self._access_lock = asyncio.Lock()
|
||||
|
||||
async def discord_deleted_user(self, user_id: int):
|
||||
|
||||
async with self._access_lock:
|
||||
|
||||
async for guild_id_or_none, ids in AsyncIter(
|
||||
self._cached_whitelist.items(), steps=100
|
||||
):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user