From e3afe102997bb39f1eca3efcb2e1d9f34277b3d4 Mon Sep 17 00:00:00 2001 From: brandons209 Date: Sat, 22 Aug 2020 20:29:46 -0400 Subject: [PATCH] fix black formatting errors for sfx and scheduler --- scheduler/checks.py | 4 +- scheduler/converters.py | 7 +- scheduler/message.py | 18 ++-- scheduler/scheduler.py | 126 +++++++--------------------- scheduler/tasks.py | 11 +-- sfx/{injection.py => injection.txt} | 0 sfx/sfx.py | 2 +- 7 files changed, 42 insertions(+), 126 deletions(-) rename sfx/{injection.py => injection.txt} (100%) diff --git a/scheduler/checks.py b/scheduler/checks.py index 2d2c88a..e90bc8c 100644 --- a/scheduler/checks.py +++ b/scheduler/checks.py @@ -11,9 +11,7 @@ def can_run_command(command_name: str): return False try: - can_run = await command.can_run( - ctx, check_all_parents=True, change_permission_state=False - ) + can_run = await command.can_run(ctx, check_all_parents=True, change_permission_state=False) except commands.CommandError: can_run = False diff --git a/scheduler/converters.py b/scheduler/converters.py index 15b784d..0d92ace 100644 --- a/scheduler/converters.py +++ b/scheduler/converters.py @@ -49,9 +49,7 @@ class Schedule: command = None parser = NoExitParser(description="Scheduler event parsing", add_help=False) - parser.add_argument( - "-q", "--quiet", action="store_true", dest="quiet", default=False - ) + parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", default=False) parser.add_argument("--every", nargs="*", dest="every", default=[]) if not command: parser.add_argument("command", nargs="*") @@ -84,8 +82,7 @@ class Schedule: recur = parsed if recur.total_seconds() < 60: raise BadArgument( - "You can't schedule something to happen that frequently, " - "I'll get ratelimited." + "You can't schedule something to happen that frequently, " "I'll get ratelimited." ) if vals["at"]: diff --git a/scheduler/message.py b/scheduler/message.py index 2aaa8fe..142cb8e 100644 --- a/scheduler/message.py +++ b/scheduler/message.py @@ -30,9 +30,7 @@ def neuter_coroutines(klass): async def replacement_delete_messages(self, messages): - message_ids = list( - {m.id for m in messages if m.__class__.__name__ != "SchedulerMessage"} - ) + message_ids = list({m.id for m in messages if m.__class__.__name__ != "SchedulerMessage"}) if not message_ids: return @@ -42,9 +40,7 @@ async def replacement_delete_messages(self, messages): return if len(message_ids) > 100: - raise discord.ClientException( - "Can only bulk delete messages up to 100 messages" - ) + raise discord.ClientException("Can only bulk delete messages up to 100 messages") await self._state.http.delete_messages(self.id, message_ids) @@ -61,9 +57,7 @@ class SchedulerMessage(discord.Message): Be careful when using this in other use cases. """ - def __init__( - self, *, content: str, author: discord.Member, channel: discord.TextChannel - ) -> None: + def __init__(self, *, content: str, author: discord.Member, channel: discord.TextChannel) -> None: # auto current time self.id = discord.utils.time_snowflake(datetime.utcnow()) # important properties for even being processed @@ -81,9 +75,9 @@ class SchedulerMessage(discord.Message): # suport for attachments somehow later maybe? self.attachments: List[discord.Attachment] = [] # mentions - self.mention_everyone = self.channel.permissions_for( - self.author - ).mention_everyone and bool(EVERYONE_REGEX.match(self.content)) + self.mention_everyone = self.channel.permissions_for(self.author).mention_everyone and bool( + EVERYONE_REGEX.match(self.content) + ) # pylint: disable=E1133 # pylint improperly detects the inherited properties here as not being iterable # This should be fixed with typehint support added to upstream lib later diff --git a/scheduler/scheduler.py b/scheduler/scheduler.py index f5a75c1..cae8e3b 100644 --- a/scheduler/scheduler.py +++ b/scheduler/scheduler.py @@ -100,9 +100,7 @@ class Scheduler(commands.Cog): # explain: mypy assumes this is always true, but other CCs using this API may not be using mypy. if not (isinstance(author, discord.Member) and isinstance(channel, discord.TextChannel)): # type: ignore - raise TypeError( - "Must provide guild specific discord.py models for both author and channel" - ) + raise TypeError("Must provide guild specific discord.py models for both author and channel") if recur is not None and recur.total_seconds() < 60: raise ValueError("Recuring events must be at least a minute apart.") @@ -149,9 +147,7 @@ class Scheduler(commands.Cog): A string which is needed to unschedule the task """ - tasks = await self.fetch_task_by_attrs_exact( - extern_cog=calling_cog.qualified_name, uid=uid - ) + tasks = await self.fetch_task_by_attrs_exact(extern_cog=calling_cog.qualified_name, uid=uid) if tasks: await self._remove_tasks(*tasks) @@ -161,15 +157,11 @@ class Scheduler(commands.Cog): def __init__(self, bot, *args, **kwargs): self.bot = bot - self.config = Config.get_conf( - self, identifier=78631113035100160, force_registration=True - ) + self.config = Config.get_conf(self, identifier=78631113035100160, force_registration=True) self.config.register_channel(tasks={}) # Serialized Tasks go in here. self.log = logging.getLogger("red.sinbadcogs.scheduler") self.bg_loop_task: Optional[asyncio.Task] = None - self.scheduled: Dict[ - str, asyncio.Task - ] = {} # Might change this to a list later. + self.scheduled: Dict[str, asyncio.Task] = {} # Might change this to a list later. self.tasks: List[Task] = [] self._iter_lock = asyncio.Lock() @@ -183,10 +175,7 @@ class Scheduler(commands.Cog): task.cancel() async def red_delete_data_for_user( - self, - *, - requester: Literal["discord_deleted_user", "owner", "user", "user_strict"], - user_id: int, + self, *, requester: Literal["discord_deleted_user", "owner", "user", "user_strict"], user_id: int, ): loaded_tasks = await self.fetch_task_by_attrs_exact(author=user_id) if loaded_tasks: @@ -218,10 +207,7 @@ class Scheduler(commands.Cog): chan_dict = await self.config.all_channels() for channel_id, channel_data in chan_dict.items(): channel = self.bot.get_channel(channel_id) - if ( - not channel - or not channel.permissions_for(channel.guild.me).read_messages - ): + if not channel or not channel.permissions_for(channel.guild.me).read_messages: continue tasks_dict = channel_data.get("tasks", {}) for t in Task.bulk_from_config(bot=self.bot, **tasks_dict): @@ -236,9 +222,7 @@ class Scheduler(commands.Cog): async def bg_loop(self): await self.bot.wait_until_ready() await asyncio.sleep(2) - _guilds = [ - g for g in self.bot.guilds if g.large and not (g.chunked or g.unavailable) - ] + _guilds = [g for g in self.bot.guilds if g.large and not (g.chunked or g.unavailable)] await self.bot.request_offline_members(*_guilds) async with self._iter_lock: @@ -256,11 +240,7 @@ class Scheduler(commands.Cog): message = await task.get_message(self.bot) context = await self.bot.get_context(message) context.assume_yes = True - if ( - context.invoked_with - and context.command - and context.command.qualified_name in SUSPICIOUS_COMMANDS - ): + if context.invoked_with and context.command and context.command.qualified_name in SUSPICIOUS_COMMANDS: self.log.warning( f"Handling scheduled {context.command.qualified_name} " "if you are using this to avoid an issue with another cog, " @@ -305,9 +285,7 @@ class Scheduler(commands.Cog): for task in self.tasks: delay = task.next_call_delay if delay < 30 and task.uid not in self.scheduled: - self.scheduled[task.uid] = asyncio.create_task( - self.delayed_wrap_and_invoke(task, delay) - ) + self.scheduled[task.uid] = asyncio.create_task(self.delayed_wrap_and_invoke(task, delay)) if not task.recur: to_remove.append(task) @@ -317,9 +295,7 @@ class Scheduler(commands.Cog): # explain: mypy assumes this is always true, but other CCs using this API may not be using mypy. if not (isinstance(author, discord.Member) and isinstance(channel, discord.TextChannel)): # type: ignore - raise TypeError( - "Must provide guild specific discord.py models for both author and channel" - ) + raise TypeError("Must provide guild specific discord.py models for both author and channel") async def fetch_task_by_attrs_exact(self, **kwargs) -> List[Task]: def pred(item): @@ -331,9 +307,7 @@ class Scheduler(commands.Cog): async with self._iter_lock: return [t for t in self.tasks if pred(t)] - async def fetch_task_by_attrs_lax( - self, lax: Optional[dict] = None, strict: Optional[dict] = None - ) -> List[Task]: + async def fetch_task_by_attrs_lax(self, lax: Optional[dict] = None, strict: Optional[dict] = None) -> List[Task]: def pred(item): try: if strict and not all(getattr(item, k) == v for k, v in strict.items()): @@ -358,9 +332,7 @@ class Scheduler(commands.Cog): @checks.mod_or_permissions(manage_guild=True) @commands.guild_only() @commands.command(usage=" ") - async def schedule( - self, ctx: commands.GuildContext, event_name: NonNumeric, *, schedule: Schedule - ): + async def schedule(self, ctx: commands.GuildContext, event_name: NonNumeric, *, schedule: Schedule): """ Schedule something @@ -419,16 +391,12 @@ class Scheduler(commands.Cog): quiet: bool = schedule.quiet - if await self.fetch_task_by_attrs_exact( - author=ctx.author, channel=ctx.channel, nicename=event_name.parsed - ): + if await self.fetch_task_by_attrs_exact(author=ctx.author, channel=ctx.channel, nicename=event_name.parsed): if not quiet: return await ctx.send("You already have an event by that name here.") async with self._iter_lock: - async with self.config.channel(ctx.channel).tasks( - acquire_lock=False - ) as tsks: + async with self.config.channel(ctx.channel).tasks(acquire_lock=False) as tsks: tsks.update(t.to_config()) self.tasks.append(t) @@ -460,23 +428,15 @@ class Scheduler(commands.Cog): """ tasks = await self.fetch_task_by_attrs_lax( - lax={"uid": info, "nicename": info}, - strict={"author": ctx.author, "channel": ctx.channel}, + lax={"uid": info, "nicename": info}, strict={"author": ctx.author, "channel": ctx.channel}, ) if not tasks: - await ctx.send( - f"Hmm, I couldn't find that task. (try `{ctx.clean_prefix}showscheduled`)" - ) + await ctx.send(f"Hmm, I couldn't find that task. (try `{ctx.clean_prefix}showscheduled`)") elif len(tasks) > 1: - self.log.warning( - f"Mutiple tasks where should be unique. Task data: {tasks}" - ) - await ctx.send( - "There seems to have been breakage here. " - "Cleaning up and logging incident." - ) + self.log.warning(f"Mutiple tasks where should be unique. Task data: {tasks}") + await ctx.send("There seems to have been breakage here. " "Cleaning up and logging incident.") return else: @@ -486,9 +446,7 @@ class Scheduler(commands.Cog): @checks.bot_has_permissions(add_reactions=True, embed_links=True) @commands.guild_only() @commands.command() - async def showscheduled( - self, ctx: commands.GuildContext, all_channels: bool = False - ): + async def showscheduled(self, ctx: commands.GuildContext, all_channels: bool = False): """ Shows your scheduled tasks in this, or all channels. """ @@ -497,9 +455,7 @@ class Scheduler(commands.Cog): tasks = await self.fetch_tasks_by_guild(ctx.guild) tasks = [t for t in tasks if t.author == ctx.author] else: - tasks = await self.fetch_task_by_attrs_exact( - author=ctx.author, channel=ctx.channel - ) + tasks = await self.fetch_task_by_attrs_exact(author=ctx.author, channel=ctx.channel) if not tasks: return await ctx.send("No scheduled tasks") @@ -507,10 +463,7 @@ class Scheduler(commands.Cog): await self.task_menu(ctx, tasks) async def task_menu( - self, - ctx: commands.GuildContext, - tasks: List[Task], - message: Optional[discord.Message] = None, + self, ctx: commands.GuildContext, tasks: List[Task], message: Optional[discord.Message] = None, ): color = await ctx.embed_color() @@ -539,10 +492,7 @@ class Scheduler(commands.Cog): await message.delete() count = len(tasks) - embeds = [ - t.to_embed(index=i, page_count=count, color=color) - for i, t in enumerate(tasks, 1) - ] + embeds = [t.to_embed(index=i, page_count=count, color=color) for i, t in enumerate(tasks, 1)] controls = DEFAULT_CONTROLS.copy() page_mapping = {i: t for i, t in enumerate(tasks)} @@ -604,9 +554,7 @@ class Scheduler(commands.Cog): ) async with self._iter_lock: - async with self.config.channel(ctx.channel).tasks( - acquire_lock=False - ) as tsks: + async with self.config.channel(ctx.channel).tasks(acquire_lock=False) as tsks: tsks.update(t.to_config()) self.tasks.append(t) @@ -672,17 +620,11 @@ class Scheduler(commands.Cog): tasks = await self.fetch_task_by_attrs_exact(uid=task_id) if not tasks: - await ctx.send( - f"Hmm, I couldn't find that task. (try `{ctx.clean_prefix}showscheduled`)" - ) + await ctx.send(f"Hmm, I couldn't find that task. (try `{ctx.clean_prefix}showscheduled`)") elif len(tasks) > 1: - self.log.warning( - f"Mutiple tasks where should be unique. Task data: {tasks}" - ) - return await ctx.send( - "There seems to have been breakage here. Cleaning up and logging incident." - ) + self.log.warning(f"Mutiple tasks where should be unique. Task data: {tasks}") + return await ctx.send("There seems to have been breakage here. Cleaning up and logging incident.") else: await self._remove_tasks(*tasks) @@ -772,13 +714,9 @@ class Scheduler(commands.Cog): ) async with self._iter_lock: - self.scheduled[mute_task.uid] = asyncio.create_task( - self.delayed_wrap_and_invoke(mute_task, 0) - ) + self.scheduled[mute_task.uid] = asyncio.create_task(self.delayed_wrap_and_invoke(mute_task, 0)) - async with self.config.channel(ctx.channel).tasks( - acquire_lock=False - ) as tsks: + async with self.config.channel(ctx.channel).tasks(acquire_lock=False) as tsks: tsks.update(unmute_task.to_config()) self.tasks.append(unmute_task) @@ -835,12 +773,8 @@ class Scheduler(commands.Cog): ) async with self._iter_lock: - self.scheduled[mute_task.uid] = asyncio.create_task( - self.delayed_wrap_and_invoke(mute_task, 0) - ) + self.scheduled[mute_task.uid] = asyncio.create_task(self.delayed_wrap_and_invoke(mute_task, 0)) - async with self.config.channel(ctx.channel).tasks( - acquire_lock=False - ) as tsks: + async with self.config.channel(ctx.channel).tasks(acquire_lock=False) as tsks: tsks.update(unmute_task.to_config()) self.tasks.append(unmute_task) diff --git a/scheduler/tasks.py b/scheduler/tasks.py index 5e4e35b..724eca9 100644 --- a/scheduler/tasks.py +++ b/scheduler/tasks.py @@ -33,9 +33,7 @@ class Task: pfx = (await bot.get_prefix(self.channel))[0] content = f"{pfx}{self.content}" - return SchedulerMessage( - content=content, author=self.author, channel=self.channel - ) + return SchedulerMessage(content=content, author=self.author, channel=self.channel) def to_config(self): @@ -72,12 +70,7 @@ class Task: with contextlib.suppress(AttributeError, ValueError): yield cls( - initial=initial, - recur=recur, - channel=channel, - author=author, - uid=uid, - **data, + initial=initial, recur=recur, channel=channel, author=author, uid=uid, **data, ) @property diff --git a/sfx/injection.py b/sfx/injection.txt similarity index 100% rename from sfx/injection.py rename to sfx/injection.txt diff --git a/sfx/sfx.py b/sfx/sfx.py index 59d0274..8d97cb9 100644 --- a/sfx/sfx.py +++ b/sfx/sfx.py @@ -264,7 +264,7 @@ class SFX(commands.Cog): await ctx.send(error("Please reload the cog after the Audio cog has been loaded!")) return - inject_path = str(code_path(cog_instance=self) / "injection.py") + inject_path = str(code_path(cog_instance=self) / "injection.txt") with open(inject_path, "r") as f: injection = f.read()