|
|
|
|
@@ -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,18 +96,22 @@ 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:
|
|
|
|
|
# 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=self.bot.bot_id,
|
|
|
|
|
moderator=message.broadcaster,
|
|
|
|
|
message_id=message.id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -141,8 +146,13 @@ 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)
|
|
|
|
|
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!)",
|
|
|
|
|
@@ -150,16 +160,18 @@ class FocusComponent(cmds.Component):
|
|
|
|
|
)
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.warning(f"Failed to delete a hyperfocus message: {payload!r}")
|
|
|
|
|
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! ☘️🍀☘️ "
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|