diff --git a/src/modules/nowdoing/cog.py b/src/modules/nowdoing/cog.py index 19b12283..74fe15b7 100644 --- a/src/modules/nowdoing/cog.py +++ b/src/modules/nowdoing/cog.py @@ -4,17 +4,21 @@ import json import os 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 from twitchio.ext import commands -from meta import CrocBot, LionCog -from meta.LionBot import LionBot +from meta import CrocBot, LionCog, LionContext, LionBot from meta.sockets import Channel, register_channel from utils.lib import strfdelta, utc_now from . import logger from .data import NowListData +from modules.profiles.profile import UserProfile + class NowDoingChannel(Channel): name = 'NowList' @@ -82,7 +86,7 @@ class NowDoingChannel(Channel): class NowDoingCog(LionCog): def __init__(self, bot: LionBot): self.bot = bot - self.crocbot = bot.crocbot + self.crocbot: CrocBot = bot.crocbot self.data = bot.db.load_registry(NowListData()) self.channel = NowDoingChannel(self) register_channel(self.channel.name, self.channel) @@ -127,10 +131,9 @@ class NowDoingCog(LionCog): else: 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, *, args: Optional[str] = None): - userid = int(ctx.author.id) + async def now(self, ctx: commands.Context | LionContext, profile: UserProfile, args: Optional[str] = None): args = args.strip() if args else None + userid = profile.profileid if args: await self.data.Task.table.delete_where(userid=userid) task = await self.data.Task.create( @@ -141,7 +144,7 @@ class NowDoingCog(LionCog): ) self.tasks[task.userid] = 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): if task.is_done: 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" ) - @commands.command(name='next') - async def nownext(self, ctx: commands.Context, *, args: Optional[str] = None): - userid = int(ctx.author.id) + @commands.command( + name='now', + 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) if args: if task: @@ -200,9 +218,22 @@ class NowDoingCog(LionCog): "Show what you are currently working on with, e.g. !now Reading notes" ) - @commands.command() - async def done(self, ctx: commands.Context): - userid = int(ctx.author.id) + @commands.command( + name='next', + ) + 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.is_done: await ctx.send( @@ -222,6 +253,20 @@ class NowDoingCog(LionCog): "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() async def clear(self, ctx: commands.Context): userid = int(ctx.author.id) diff --git a/src/tracking/voice/cog.py b/src/tracking/voice/cog.py index cb839021..db5bfe3b 100644 --- a/src/tracking/voice/cog.py +++ b/src/tracking/voice/cog.py @@ -654,7 +654,7 @@ class VoiceTrackerCog(LionCog): # ----- Commands ----- @cmds.hybrid_command( - name=_p('cmd:now', "now"), + name="tag", description=_p( 'cmd:now|desc', "Describe what you are working on, or see what your friends are working on!" diff --git a/src/twitch/userflow.py b/src/twitch/userflow.py index 11c0fef9..8a73614e 100644 --- a/src/twitch/userflow.py +++ b/src/twitch/userflow.py @@ -56,7 +56,7 @@ class UserAuthFlow: result = await self._comm_task if result.get('error', None): # 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']}") if result.get('state', None) != self.auth.state: