fix: Various typos
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
from .hyperfocus import *
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ VALUES ('HYPERFOCUS', 0, 1, 'Initial Creation');
|
|||||||
CREATE TABLE hyperfocused(
|
CREATE TABLE hyperfocused(
|
||||||
profileid INTEGER PRIMARY KEY REFERENCES user_profiles(profileid) ON DELETE CASCADE ON UPDATE CASCADE,
|
profileid INTEGER PRIMARY KEY REFERENCES user_profiles(profileid) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
ends_at TIMSTAMPTZ NOT NULL,
|
ends_at TIMESTAMPTZ NOT NULL,
|
||||||
started_in INTEGER REFERENCES communities(communityid) ON DELETE SET NULL ON UPDATE CASCADE
|
started_in INTEGER REFERENCES communities(communityid) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class FocusComponent(cmds.Component):
|
|||||||
self.data = bot.dbconn.load_registry(HyperfocusData())
|
self.data = bot.dbconn.load_registry(HyperfocusData())
|
||||||
|
|
||||||
self.channels: dict[str, FocusChannel] = {}
|
self.channels: dict[str, FocusChannel] = {}
|
||||||
|
self._last_deleted: dict[int, datetime] = {}
|
||||||
|
|
||||||
# ----- API -----
|
# ----- API -----
|
||||||
async def component_load(self):
|
async def component_load(self):
|
||||||
@@ -85,8 +86,8 @@ class FocusComponent(cmds.Component):
|
|||||||
"""
|
"""
|
||||||
Get the Hyperfocuser if the user is hyperfocused.
|
Get the Hyperfocuser if the user is hyperfocused.
|
||||||
"""
|
"""
|
||||||
row = Hyperfocuser.fetch(profileid)
|
row = await Hyperfocuser.fetch(profileid)
|
||||||
if row and row.ends_at < utc_now():
|
if row and row.ends_at > utc_now():
|
||||||
return row
|
return row
|
||||||
|
|
||||||
async def focus_delete_message(self, message: twitchio.ChatMessage):
|
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
|
# None id could cause chat to be wiped
|
||||||
assert message.id is not None
|
assert message.id is not None
|
||||||
|
|
||||||
badge_sets = {badge.set_id for badge in message.badges}
|
# badge_sets = {badge.set_id for badge in message.badges}
|
||||||
if "moderator" in badge_sets or "broadcaster" in badge_sets:
|
# if "moderator" in badge_sets or "broadcaster" in badge_sets:
|
||||||
# We need to use the focus channel
|
# # We need to use the focus channel
|
||||||
|
#
|
||||||
assert message.broadcaster.name is not None
|
# assert message.broadcaster.name is not None
|
||||||
chan = await self.get_focus_channel(
|
# chan = await self.get_focus_channel(
|
||||||
str(message.broadcaster.id), message.broadcaster.name
|
# str(message.broadcaster.id), message.broadcaster.name
|
||||||
)
|
# )
|
||||||
await chan.delete_msg(str(message.id))
|
# await chan.delete_msg(str(message.id))
|
||||||
else:
|
# else:
|
||||||
await message.broadcaster.delete_chat_messages(
|
# await message.broadcaster.delete_chat_messages(
|
||||||
moderator=self.bot.bot_id,
|
# moderator=self.bot.bot_id,
|
||||||
message_id=message.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):
|
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 they are, check the message content for deletion
|
||||||
if hyperfocused and not self.check_hyperfocus_message(payload):
|
if hyperfocused and not self.check_hyperfocus_message(payload):
|
||||||
# If we need to delete, run delete and send message
|
# 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:
|
try:
|
||||||
await self.focus_delete_message(payload)
|
await self.focus_delete_message(payload)
|
||||||
await payload.broadcaster.send_message(
|
if notify:
|
||||||
f"@{payload.chatter.name} Stay focused! "
|
await payload.broadcaster.send_message(
|
||||||
"(You are in !hyperfocus, use !unfocus to come back if you need to!)",
|
f"@{payload.chatter.name} Stay focused! "
|
||||||
sender=self.bot.bot_id,
|
"(You are in !hyperfocus, use !unfocus to come back if you need to!)",
|
||||||
)
|
sender=self.bot.bot_id,
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(f"Failed to delete a hyperfocus message: {payload!r}")
|
logger.warning(f"Failed to delete a hyperfocus message: {payload!r}")
|
||||||
await payload.broadcaster.send_message(
|
if notify:
|
||||||
f"@{payload.chatter.name} Stay focused! ",
|
await payload.broadcaster.send_message(
|
||||||
sender=self.bot.bot_id,
|
f"@{payload.chatter.name} Stay focused! ",
|
||||||
)
|
sender=self.bot.bot_id,
|
||||||
|
)
|
||||||
|
self._last_deleted[profile.profileid] = utc_now()
|
||||||
|
|
||||||
# ------ Commands -----
|
# ------ Commands -----
|
||||||
@cmds.command(
|
@cmds.command(
|
||||||
name="hyperfocus", aliases=["hyperf", "hyper", "hypercrocus", "hyperofcus"]
|
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()
|
now = utc_now()
|
||||||
|
|
||||||
# First parse duration
|
# First parse duration
|
||||||
@@ -202,7 +214,7 @@ class FocusComponent(cmds.Component):
|
|||||||
# TODO: Update channel
|
# TODO: Update channel
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
f"{ctx.chatter.name} has gone into HYPERFOCUS! "
|
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! ☘️🍀☘️ "
|
"Use !unfocus to come back if you need to, best of luck! ☘️🍀☘️ "
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -284,6 +284,7 @@ class FocusChannel:
|
|||||||
asyncio.create_task(self.connect())
|
asyncio.create_task(self.connect())
|
||||||
|
|
||||||
async def send_msg(self, content: str):
|
async def send_msg(self, content: str):
|
||||||
|
logger.debug(f"Sending: {content}")
|
||||||
await self._socket.send_str(content)
|
await self._socket.send_str(content)
|
||||||
|
|
||||||
async def delete_msg(self, msgid: str):
|
async def delete_msg(self, msgid: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user