70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
import twitchio
|
|
|
|
from meta import Bot
|
|
from utils.lib import utc_now, strfdelta
|
|
|
|
from ..customcmd.parser import ExecContext
|
|
from ..customcmd.client import ExecClient
|
|
from ..customcmd.data import CustomCmd, CustomCmdData
|
|
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 ctx.bot.user.send_whisper(to_user=self.user, message=message)
|
|
|
|
async def _exec_attr_followage(self, ctx, channel: "CustomCmdUser"):
|
|
followed_at = None
|
|
query = await channel.user.fetch_followers(
|
|
user=self.user, token_for=ctx.bot.user
|
|
)
|
|
async for follower in query.followers:
|
|
followed_at = follower.followed_at
|
|
|
|
if followed_at:
|
|
durstr = strfdelta(utc_now() - followed_at)
|
|
return durstr
|
|
else:
|
|
return None
|
|
|
|
@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__(alias=alias, **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?
|