feat: Data and client framework
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import twitchio
|
||||
|
||||
from customcmd.client import ExecClient
|
||||
from customcmd.data import CustomCmd, CustomCmdData
|
||||
from meta import Bot
|
||||
from utils.lib import utc_now, strfdur
|
||||
|
||||
from ..customcmd.parser import ExecContext
|
||||
from .ctxvars import stuff
|
||||
|
||||
|
||||
class CustomCmdUser:
|
||||
def __init__(self, user: twitchio.PartialUser):
|
||||
self.user = user
|
||||
|
||||
@property
|
||||
def _exec_attr_id(self):
|
||||
return self.user.id
|
||||
|
||||
@property
|
||||
def _exec_attr_name(self):
|
||||
return self.user.display_name
|
||||
|
||||
def __str__(self):
|
||||
return self.user.display_name or self.user.name or self.user.id
|
||||
|
||||
async def _exec_attr_whisper(self, ctx, message: str):
|
||||
await self.user.send_whisper(
|
||||
to_user=self.user,
|
||||
message=message
|
||||
)
|
||||
|
||||
async def _exec_attr_followage(self, ctx, channel: twitchio.PartialUser):
|
||||
followed_at = None
|
||||
query = await channel.fetch_followers(user=self.user)
|
||||
async for follower in query.followers:
|
||||
followed_at = follower.followed_at
|
||||
|
||||
if followed_at:
|
||||
durstr = strfdur(utc_now() - followed_at)
|
||||
resp = f"{self.user.mention} has been following {channel.mention} for {durstr}"
|
||||
else:
|
||||
return f"{self.user.mention} is not following {channel.mention}"
|
||||
|
||||
@classmethod
|
||||
def from_user(cls, user: twitchio.PartialUser):
|
||||
return cls(user)
|
||||
|
||||
|
||||
class CustomContext(ExecContext):
|
||||
"""
|
||||
CustomCommand ExecContext instantiated from a Twitch message
|
||||
"""
|
||||
def __init__(
|
||||
self,
|
||||
bot: Bot,
|
||||
message: twitchio.ChatMessage,
|
||||
alias: str,
|
||||
used_prefix: str,
|
||||
**kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.bot = bot
|
||||
self.message = message
|
||||
self.alias = alias
|
||||
self.used_prefix = used_prefix
|
||||
|
||||
self.enter_scope(stuff)
|
||||
# TODO: Need a nice way to define some global functions. Registry pattern?
|
||||
Reference in New Issue
Block a user