From 0d4f9b9a9a2780531000583926101112a6dd3989 Mon Sep 17 00:00:00 2001 From: Interitio Date: Sun, 31 May 2026 06:32:31 +1000 Subject: [PATCH] fix(twitch): Fix relative imports --- twitch/client.py | 29 ++++++++++++++--------------- twitch/component.py | 30 +++++++++++++++--------------- twitch/context.py | 33 +++++++++++++++++---------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/twitch/client.py b/twitch/client.py index ea4cccf..ab3567e 100644 --- a/twitch/client.py +++ b/twitch/client.py @@ -1,11 +1,13 @@ import twitchio -from customcmd.client import ExecClient -from customcmd.data import CustomCmd, CustomCmdData from meta import Bot +from ..customcmd.client import ExecClient +from ..customcmd.data import CustomCmd, CustomCmdData + from .context import CustomContext, CustomCmdUser + class TwitchCmdClient(ExecClient): def __init__(self, bot: Bot, data: CustomCmdData): super().__init__() @@ -22,12 +24,12 @@ class TwitchCmdClient(ExecClient): if message.reply: # Strip the hidden mention prefix from the start of the message prefix = message.reply.parent_user.mention - content = content[len(prefix) + 1:] + content = content[len(prefix) + 1 :] - # If we start with a valid prefix, parse out a command name + # If we start with a valid prefix, parse out a command name if prefix := next((p for p in prefixes if content.startswith(p)), None): # Strip the valid prefix - content = content[len(prefix):].strip() + content = content[len(prefix) :].strip() if not content: # Exit early, no command return @@ -45,7 +47,7 @@ class TwitchCmdClient(ExecClient): # Read the arguments, build the context, run the command. # TODO: Check the permissions and log etc. # TODO: Exception handling, as usual - # TODO: Nice string reprs + # TODO: Nice string reprs ctx = CustomContext( bot=self.bot, args=args, @@ -53,20 +55,17 @@ class TwitchCmdClient(ExecClient): used_prefix=prefix, message=message, initial_globals={ - 'author': CustomCmdUser(message.chatter), - 'channel': CustomCmdUser(message.broadcaster), - } + "author": CustomCmdUser(message.chatter), + "channel": CustomCmdUser(message.broadcaster), + }, ) result = await self.run_command(ctx, cmd.response) if result: - await message.broadcaster.send_message( - result, - sender=self.bot.user - ) + await message.broadcaster.send_message(result, sender=self.bot.user) async def get_prefixes(self, message: twitchio.ChatMessage): - # TODO: - return ('!',) + # TODO: + return ("!",) async def get_commands_in(self, communityid: int) -> dict[str, CustomCmd]: """ diff --git a/twitch/component.py b/twitch/component.py index 9669d4f..4759a1a 100644 --- a/twitch/component.py +++ b/twitch/component.py @@ -2,23 +2,21 @@ from typing import Optional import twitchio from twitchio import PartialUser -from twitchio.ext import commands as cmds +from twitchio.ext import commands as cmds -from customcmd.parser.context import ExecContext from meta import Bot from twitch.client import TwitchCmdClient from utils.lib import utc_now -from . import logger +from . import logger from ..customcmd.data import CustomCmd, CustomCmdData from ..customcmd.client import ExecClient +from ..customcmd.parser import ExecContext # TODO: Make an alphacroc or croccyalpha client for testing # TODO: Fix the tracker not actually guarding the commands properly - - class CustomCmdComponent(cmds.Component): def __init__(self, bot: Bot): self.bot = bot @@ -31,11 +29,11 @@ class CustomCmdComponent(cmds.Component): await self.bot.version_check(*self.data.VERSION) async def component_teardown(self): - pass + pass - # ----- Methods ----- + # ----- Methods ----- - # ----- Event handlers ----- + # ----- Event handlers ----- @cmds.Component.listener() async def event_message(self, payload: twitchio.ChatMessage): await self.cmdclient.process_message(payload) @@ -44,9 +42,9 @@ class CustomCmdComponent(cmds.Component): @cmds.group(name="commands") async def cmd_grp(self, ctx: cmds.Context): # TODO: Probably attempt to list commands or something here. - pass + pass - @cmd_grp.command(name="add", aliases=('create', 'new')) + @cmd_grp.command(name="add", aliases=("create", "new")) @cmds.is_broadcaster() # TODO: Better command creation perm checks async def cmd_add(self, ctx: cmds.Context, name: str, *, response: str): comm = await self.bot.profiles.fetch_community(ctx.broadcaster) @@ -60,11 +58,13 @@ class CustomCmdComponent(cmds.Component): # Make sure the command parses (can't guarantee it runs, but at least it can parse) try: - await self.cmdclient.run_command(ExecContext(args=[], content=''), response) + await self.cmdclient.run_command(ExecContext(args=[], content=""), response) except Exception: # TODO: Nicer errors for pinpointing problem await ctx.reply(f"Sorry, could not parse your command!") - logger.info(f"Failed to parse attempted customcmd '{response}'", exc_info=True) + logger.info( + f"Failed to parse attempted customcmd '{response}'", exc_info=True + ) # If everything is good, add it to the table # TODO: Again, permission resolution @@ -79,10 +79,10 @@ class CustomCmdComponent(cmds.Component): await ctx.reply(f"Created a new command !{name}") - @cmd_grp.command(name="del", aliases=('delete', 'remove', 'rm')) - @cmds.is_broadcaster() + @cmd_grp.command(name="del", aliases=("delete", "remove", "rm")) + @cmds.is_broadcaster() async def cmd_del(self, ctx: cmds.Context, name: str): - # Lookup the name to make sure a command does exist + # Lookup the name to make sure a command does exist # Delete the command (again, consider permissions later) # Confirm with user. comm = await self.bot.profiles.fetch_community(ctx.broadcaster) diff --git a/twitch/context.py b/twitch/context.py index be13885..9c26bc4 100644 --- a/twitch/context.py +++ b/twitch/context.py @@ -1,11 +1,11 @@ import twitchio -from customcmd.client import ExecClient -from customcmd.data import CustomCmd, CustomCmdData from meta import Bot from utils.lib import utc_now, strfdur from ..customcmd.parser import ExecContext +from ..customcmd.client import ExecClient +from ..customcmd.data import CustomCmd, CustomCmdData from .ctxvars import stuff @@ -25,10 +25,7 @@ class CustomCmdUser: return self.user.display_name or self.user.name or self.user.id async def _exec_attr_whisper(self, ctx, message: str): - await self.user.send_whisper( - to_user=self.user, - message=message - ) + await self.user.send_whisper(to_user=self.user, message=message) async def _exec_attr_followage(self, ctx, channel: twitchio.PartialUser): followed_at = None @@ -38,7 +35,9 @@ class CustomCmdUser: if followed_at: durstr = strfdur(utc_now() - followed_at) - resp = f"{self.user.mention} has been following {channel.mention} for {durstr}" + resp = ( + f"{self.user.mention} has been following {channel.mention} for {durstr}" + ) else: return f"{self.user.mention} is not following {channel.mention}" @@ -51,18 +50,20 @@ class CustomContext(ExecContext): """ CustomCommand ExecContext instantiated from a Twitch message """ + def __init__( - self, - bot: Bot, - message: twitchio.ChatMessage, - alias: str, - used_prefix: str, - **kwargs): + self, + bot: Bot, + message: twitchio.ChatMessage, + alias: str, + used_prefix: str, + **kwargs, + ): super().__init__(**kwargs) self.bot = bot - self.message = message - self.alias = alias + self.message = message + self.alias = alias self.used_prefix = used_prefix self.enter_scope(stuff) - # TODO: Need a nice way to define some global functions. Registry pattern? + # TODO: Need a nice way to define some global functions. Registry pattern?