forked from HoloTech/hyperfocus-plugin
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c834c1c4e | |||
| 2cba5d0bbf | |||
| 869b401314 |
+1
-1
@@ -4,7 +4,7 @@ from data.columns import String, Integer, Timestamp
|
|||||||
|
|
||||||
class Hyperfocuser(RowModel):
|
class Hyperfocuser(RowModel):
|
||||||
_tablename_ = "hyperfocused"
|
_tablename_ = "hyperfocused"
|
||||||
_cache_ = {}
|
# _cache_ = {}
|
||||||
|
|
||||||
profileid = Integer(primary=True)
|
profileid = Integer(primary=True)
|
||||||
started_at = Timestamp()
|
started_at = Timestamp()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import datetime as dt
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from math import ceil
|
from math import ceil
|
||||||
import time
|
import time
|
||||||
|
import random
|
||||||
|
|
||||||
import twitchio
|
import twitchio
|
||||||
from twitchio import Scopes
|
from twitchio import Scopes
|
||||||
@@ -32,6 +33,18 @@ CHANNEL_SCOPES = Scopes(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
responses = """
|
||||||
|
🐱 Nice try. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
❌ This interaction has been reviewed and rejected. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
🚨 Nico has reviewed your message and found it unnecessary. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
📄 Nico gently places your message in the shredder. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
🧐 Nico believes your future self would rather you keep focusing. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
💭 That thought can wait until after the focus session. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
⚠️ Unauthorized yapping detected. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
🚫 Nico has denied your request to be distracted. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
❌ Nico recommends focusing instead. (You are in !hyperfocus. Use !unfocus if needed 🐾)
|
||||||
|
""".splitlines()
|
||||||
|
|
||||||
|
|
||||||
class FocusComponent(cmds.Component):
|
class FocusComponent(cmds.Component):
|
||||||
def __init__(self, bot: Bot):
|
def __init__(self, bot: Bot):
|
||||||
@@ -161,16 +174,17 @@ class FocusComponent(cmds.Component):
|
|||||||
|
|
||||||
if notify:
|
if notify:
|
||||||
self._last_deleted[profile.profileid] = now
|
self._last_deleted[profile.profileid] = now
|
||||||
|
response_text = random.choice(responses)
|
||||||
|
response_text = payload.chatter.mention + ' ' + response_text
|
||||||
try:
|
try:
|
||||||
if deleted:
|
if deleted:
|
||||||
await payload.broadcaster.send_message(
|
await payload.broadcaster.send_message(
|
||||||
f"@{payload.chatter.name} Stay focused! "
|
response_text,
|
||||||
"(You are in !hyperfocus, use !unfocus to come back if you need to!)",
|
|
||||||
sender=self.bot.bot_id,
|
sender=self.bot.bot_id,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await payload.broadcaster.send_message(
|
await payload.broadcaster.send_message(
|
||||||
f"@{payload.chatter.name} Stay focused! ",
|
response_text,
|
||||||
sender=self.bot.bot_id,
|
sender=self.bot.bot_id,
|
||||||
)
|
)
|
||||||
except twitchio.exceptions.HTTPException:
|
except twitchio.exceptions.HTTPException:
|
||||||
@@ -233,12 +247,10 @@ class FocusComponent(cmds.Component):
|
|||||||
|
|
||||||
minutes = ceil(dur / 60)
|
minutes = ceil(dur / 60)
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
f"{ctx.chatter.name} has gone into HYPERFOCUS! "
|
f"🚨⚠️ Nico has decided distractions are illegal and activated HYPERFOCUS MODE. {ctx.chatter.name} will be in emote and command only mode for the next {minutes} minutes. Use !unfocus at your own risk. Nico is watching. kawaii16Stab"
|
||||||
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! ☘️🍀☘️ "
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@cmds.command(name="unfocus", aliases=["uncrocus"])
|
@cmds.command(name="unfocus", aliases=["uncrocus", "unhyper", "unhyperfocus"])
|
||||||
async def unfocus_cmd(self, ctx):
|
async def unfocus_cmd(self, ctx):
|
||||||
profile = await self.bot.profiles.fetch_profile(ctx.chatter, touch=True)
|
profile = await self.bot.profiles.fetch_profile(ctx.chatter, touch=True)
|
||||||
async with self.hyperfocus_lock:
|
async with self.hyperfocus_lock:
|
||||||
@@ -248,8 +260,7 @@ class FocusComponent(cmds.Component):
|
|||||||
await self.channel.send_hyperfocus_del(profile.profileid)
|
await self.channel.send_hyperfocus_del(profile.profileid)
|
||||||
|
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
"Welcome back from focus, hope it went well!"
|
"Nico has reluctantly granted your request. Welcome back to chat. 🐱✨"
|
||||||
" Remember to have a sip and stretch if you need it~"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@cmds.command(name="hyperfocused")
|
@cmds.command(name="hyperfocused")
|
||||||
@@ -273,6 +284,42 @@ class FocusComponent(cmds.Component):
|
|||||||
else:
|
else:
|
||||||
await ctx.reply(f"{user.name} is not hyperfocused!")
|
await ctx.reply(f"{user.name} is not hyperfocused!")
|
||||||
|
|
||||||
|
@cmds.command(name="focuswith", aliases=["hyperfocuswith"])
|
||||||
|
async def focuswith_cmd(self, ctx, user: twitchio.User):
|
||||||
|
profile = await self.bot.profiles.fetch_profile(ctx.chatter, touch=False)
|
||||||
|
pid = profile.profileid
|
||||||
|
tprofile = await self.bot.profiles.fetch_profile(user, touch=False)
|
||||||
|
tpid = tprofile.profileid
|
||||||
|
|
||||||
|
now = utc_now()
|
||||||
|
|
||||||
|
if hyper := await self.get_hyperfocus(tpid):
|
||||||
|
async with self.hyperfocus_lock:
|
||||||
|
end_at = hyper.ends_at
|
||||||
|
|
||||||
|
# Update the row
|
||||||
|
comm = await self.bot.profiles.fetch_community(
|
||||||
|
ctx.broadcaster, touch=True
|
||||||
|
)
|
||||||
|
|
||||||
|
await Hyperfocuser.table.delete_where(profileid=pid)
|
||||||
|
focuser = await Hyperfocuser.create(
|
||||||
|
profileid=pid,
|
||||||
|
started_at=now,
|
||||||
|
ends_at=end_at,
|
||||||
|
started_in=comm.communityid,
|
||||||
|
)
|
||||||
|
|
||||||
|
await self.dispatch_focuser_update(pid, comm.communityid, focuser)
|
||||||
|
|
||||||
|
durstr = strfdelta(end_at - now)
|
||||||
|
await ctx.reply(
|
||||||
|
f"{ctx.chatter.name} follows {user.name} into HYPERFOCUS for the next {durstr}! "
|
||||||
|
"Best of luck! ☘️🍀☘️ "
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await ctx.reply(f"{user.name} is not hyperfocused!")
|
||||||
|
|
||||||
@cmds.command(name="addfocus")
|
@cmds.command(name="addfocus")
|
||||||
async def addfocus_cmd(self, ctx):
|
async def addfocus_cmd(self, ctx):
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
@@ -283,7 +330,7 @@ class FocusComponent(cmds.Component):
|
|||||||
async def focuslist_cmd(self, ctx):
|
async def focuslist_cmd(self, ctx):
|
||||||
comm = await self.bot.profiles.fetch_community(ctx.broadcaster, touch=True)
|
comm = await self.bot.profiles.fetch_community(ctx.broadcaster, touch=True)
|
||||||
link = (
|
link = (
|
||||||
f"https://croccyfocus.thewisewolf.dev/widget/?community={comm.communityid}"
|
f"https://nicofocus.thewisewolf.dev/widget/?community={comm.communityid}"
|
||||||
)
|
)
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
f"Browser source link for your channel's hyperfocus: {link} (For troubleshooting: your community id is {comm.communityid})"
|
f"Browser source link for your channel's hyperfocus: {link} (For troubleshooting: your community id is {comm.communityid})"
|
||||||
|
|||||||
Reference in New Issue
Block a user