fix: Various typos

This commit is contained in:
2025-11-01 06:38:12 +10:00
parent 82b78924a0
commit 6eabbc0d73
4 changed files with 42 additions and 28 deletions

View File

@@ -34,6 +34,7 @@ class FocusComponent(cmds.Component):
self.data = bot.dbconn.load_registry(HyperfocusData())
self.channels: dict[str, FocusChannel] = {}
self._last_deleted: dict[int, datetime] = {}
# ----- API -----
async def component_load(self):
@@ -85,8 +86,8 @@ class FocusComponent(cmds.Component):
"""
Get the Hyperfocuser if the user is hyperfocused.
"""
row = Hyperfocuser.fetch(profileid)
if row and row.ends_at < utc_now():
row = await Hyperfocuser.fetch(profileid)
if row and row.ends_at > utc_now():
return row
async def focus_delete_message(self, message: twitchio.ChatMessage):
@@ -95,20 +96,24 @@ class FocusComponent(cmds.Component):
# None id could cause chat to be wiped
assert message.id is not None
badge_sets = {badge.set_id for badge in message.badges}
if "moderator" in badge_sets or "broadcaster" in badge_sets:
# We need to use the focus channel
assert message.broadcaster.name is not None
chan = await self.get_focus_channel(
str(message.broadcaster.id), message.broadcaster.name
)
await chan.delete_msg(str(message.id))
else:
await message.broadcaster.delete_chat_messages(
moderator=self.bot.bot_id,
message_id=message.id,
)
# badge_sets = {badge.set_id for badge in message.badges}
# if "moderator" in badge_sets or "broadcaster" in badge_sets:
# # We need to use the focus channel
#
# assert message.broadcaster.name is not None
# chan = await self.get_focus_channel(
# str(message.broadcaster.id), message.broadcaster.name
# )
# await chan.delete_msg(str(message.id))
# else:
# await message.broadcaster.delete_chat_messages(
# moderator=self.bot.bot_id,
# message_id=message.id,
# )
await message.broadcaster.delete_chat_messages(
moderator=message.broadcaster,
message_id=message.id,
)
def check_hyperfocus_message(self, message: twitchio.ChatMessage):
"""
@@ -141,25 +146,32 @@ class FocusComponent(cmds.Component):
# If they are, check the message content for deletion
if hyperfocused and not self.check_hyperfocus_message(payload):
# If we need to delete, run delete and send message
notify = ( #
(last := self._last_deleted.get(profile.profileid))
and (utc_now() - last).total_seconds() > 30
)
try:
await self.focus_delete_message(payload)
await payload.broadcaster.send_message(
f"@{payload.chatter.name} Stay focused! "
"(You are in !hyperfocus, use !unfocus to come back if you need to!)",
sender=self.bot.bot_id,
)
if notify:
await payload.broadcaster.send_message(
f"@{payload.chatter.name} Stay focused! "
"(You are in !hyperfocus, use !unfocus to come back if you need to!)",
sender=self.bot.bot_id,
)
except Exception:
logger.warning(f"Failed to delete a hyperfocus message: {payload!r}")
await payload.broadcaster.send_message(
f"@{payload.chatter.name} Stay focused! ",
sender=self.bot.bot_id,
)
if notify:
await payload.broadcaster.send_message(
f"@{payload.chatter.name} Stay focused! ",
sender=self.bot.bot_id,
)
self._last_deleted[profile.profileid] = utc_now()
# ------ Commands -----
@cmds.command(
name="hyperfocus", aliases=["hyperf", "hyper", "hypercrocus", "hyperofcus"]
)
async def hyperfocus_cmd(self, ctx, *, duration: str | None):
async def hyperfocus_cmd(self, ctx, *, duration: str | None = None):
now = utc_now()
# First parse duration
@@ -202,7 +214,7 @@ class FocusComponent(cmds.Component):
# TODO: Update channel
await ctx.reply(
f"{ctx.chatter.name} has gone into HYPERFOCUS! "
"They will be in emote and command only mode for the next {minutes} minutes! "
f"They will be in emote and command only mode for the next {minutes} minutes! "
"Use !unfocus to come back if you need to, best of luck! ☘️🍀☘️ "
)

View File

@@ -284,6 +284,7 @@ class FocusChannel:
asyncio.create_task(self.connect())
async def send_msg(self, content: str):
logger.debug(f"Sending: {content}")
await self._socket.send_str(content)
async def delete_msg(self, msgid: str):