feat(nows): Moved tasklist to profiles.

This commit is contained in:
2024-10-07 01:07:56 +10:00
parent 2cdd084bbe
commit 997804c6bf
3 changed files with 61 additions and 16 deletions

View File

@@ -4,17 +4,21 @@ import json
import os import os
from typing import Optional from typing import Optional
from attr import dataclass import discord
from discord.ext import commands as cmds
from discord import app_commands as appcmds
import twitchio import twitchio
from twitchio.ext import commands from twitchio.ext import commands
from meta import CrocBot, LionCog from meta import CrocBot, LionCog, LionContext, LionBot
from meta.LionBot import LionBot
from meta.sockets import Channel, register_channel from meta.sockets import Channel, register_channel
from utils.lib import strfdelta, utc_now from utils.lib import strfdelta, utc_now
from . import logger from . import logger
from .data import NowListData from .data import NowListData
from modules.profiles.profile import UserProfile
class NowDoingChannel(Channel): class NowDoingChannel(Channel):
name = 'NowList' name = 'NowList'
@@ -82,7 +86,7 @@ class NowDoingChannel(Channel):
class NowDoingCog(LionCog): class NowDoingCog(LionCog):
def __init__(self, bot: LionBot): def __init__(self, bot: LionBot):
self.bot = bot self.bot = bot
self.crocbot = bot.crocbot self.crocbot: CrocBot = bot.crocbot
self.data = bot.db.load_registry(NowListData()) self.data = bot.db.load_registry(NowListData())
self.channel = NowDoingChannel(self) self.channel = NowDoingChannel(self)
register_channel(self.channel.name, self.channel) register_channel(self.channel.name, self.channel)
@@ -127,10 +131,9 @@ class NowDoingCog(LionCog):
else: else:
await ctx.send(f"Hello {ctx.author.name}! I don't think you have permission to test that.") await ctx.send(f"Hello {ctx.author.name}! I don't think you have permission to test that.")
@commands.command(aliases=['task', 'check']) async def now(self, ctx: commands.Context | LionContext, profile: UserProfile, args: Optional[str] = None):
async def now(self, ctx: commands.Context, *, args: Optional[str] = None):
userid = int(ctx.author.id)
args = args.strip() if args else None args = args.strip() if args else None
userid = profile.profileid
if args: if args:
await self.data.Task.table.delete_where(userid=userid) await self.data.Task.table.delete_where(userid=userid)
task = await self.data.Task.create( task = await self.data.Task.create(
@@ -141,7 +144,7 @@ class NowDoingCog(LionCog):
) )
self.tasks[task.userid] = task self.tasks[task.userid] = task
await self.channel.send_set(*self.channel.task_args(task)) await self.channel.send_set(*self.channel.task_args(task))
await ctx.send(f"Updated your current task, good luck!") await ctx.send("Updated your current task, good luck!")
elif task := self.tasks.get(userid, None): elif task := self.tasks.get(userid, None):
if task.is_done: if task.is_done:
done_ago = strfdelta(utc_now() - task.done_at) done_ago = strfdelta(utc_now() - task.done_at)
@@ -159,9 +162,24 @@ class NowDoingCog(LionCog):
"Show what you are currently working on with, e.g. !now Reading notes" "Show what you are currently working on with, e.g. !now Reading notes"
) )
@commands.command(name='next') @commands.command(
async def nownext(self, ctx: commands.Context, *, args: Optional[str] = None): name='now',
userid = int(ctx.author.id) aliases=['task', 'check']
)
async def twi_now(self, ctx: commands.Context, *, args: Optional[str] = None):
profile = await self.bot.get_cog('ProfileCog').fetch_profile_twitch(ctx.author)
await self.now(ctx, profile, args)
@cmds.hybrid_command(
name='now',
aliases=['task', 'check']
)
async def disc_now(self, ctx: LionContext, *, args: Optional[str] = None):
profile = await self.bot.get_cog('ProfileCog').fetch_profile_discord(ctx.author)
await self.now(ctx, profile, args)
async def nownext(self, ctx: commands.Context | LionContext, profile: UserProfile, args: Optional[str]):
userid = profile.profileid
task = self.tasks.get(userid, None) task = self.tasks.get(userid, None)
if args: if args:
if task: if task:
@@ -200,9 +218,22 @@ class NowDoingCog(LionCog):
"Show what you are currently working on with, e.g. !now Reading notes" "Show what you are currently working on with, e.g. !now Reading notes"
) )
@commands.command() @commands.command(
async def done(self, ctx: commands.Context): name='next',
userid = int(ctx.author.id) )
async def twi_next(self, ctx: commands.Context, *, args: Optional[str] = None):
profile = await self.bot.get_cog('ProfileCog').fetch_profile_twitch(ctx.author)
await self.nownext(ctx, profile, args)
@cmds.hybrid_command(
name='next',
)
async def disc_next(self, ctx: LionContext, *, args: Optional[str] = None):
profile = await self.bot.get_cog('ProfileCog').fetch_profile_discord(ctx.author)
await self.nownext(ctx, profile, args)
async def done(self, ctx: commands.Context | LionContext, profile: UserProfile):
userid = profile.profileid
if task := self.tasks.get(userid, None): if task := self.tasks.get(userid, None):
if task.is_done: if task.is_done:
await ctx.send( await ctx.send(
@@ -222,6 +253,20 @@ class NowDoingCog(LionCog):
"Show what you are currently working on with, e.g. !now Reading notes" "Show what you are currently working on with, e.g. !now Reading notes"
) )
@commands.command(
name='done',
)
async def twi_done(self, ctx: commands.Context):
profile = await self.bot.get_cog('ProfileCog').fetch_profile_twitch(ctx.author)
await self.done(ctx, profile)
@cmds.hybrid_command(
name='done',
)
async def disc_done(self, ctx: LionContext):
profile = await self.bot.get_cog('ProfileCog').fetch_profile_discord(ctx.author)
await self.done(ctx, profile)
@commands.command() @commands.command()
async def clear(self, ctx: commands.Context): async def clear(self, ctx: commands.Context):
userid = int(ctx.author.id) userid = int(ctx.author.id)

View File

@@ -654,7 +654,7 @@ class VoiceTrackerCog(LionCog):
# ----- Commands ----- # ----- Commands -----
@cmds.hybrid_command( @cmds.hybrid_command(
name=_p('cmd:now', "now"), name="tag",
description=_p( description=_p(
'cmd:now|desc', 'cmd:now|desc',
"Describe what you are working on, or see what your friends are working on!" "Describe what you are working on, or see what your friends are working on!"

View File

@@ -56,7 +56,7 @@ class UserAuthFlow:
result = await self._comm_task result = await self._comm_task
if result.get('error', None): if result.get('error', None):
# TODO Custom auth errors # TODO Custom auth errors
# This is only documented to occure when the user denies the auth # This is only documented to occur when the user denies the auth
raise SafeCancellation(f"Could not authenticate user! Reason: {result['error_description']}") raise SafeCancellation(f"Could not authenticate user! Reason: {result['error_description']}")
if result.get('state', None) != self.auth.state: if result.get('state', None) != self.auth.state: