Compare commits

...

4 Commits

5 changed files with 29 additions and 18 deletions
+1 -2
View File
@@ -13,7 +13,7 @@ CREATE TABLE customcmds(
cooldown_bucket_dur INTEGER, cooldown_bucket_dur INTEGER,
permlevel INTEGER, permlevel INTEGER,
maskperms BOOLEAN DEFAULT FALSE, maskperms BOOLEAN DEFAULT FALSE,
creatorid INTEGER NOT NULL REFERENCES profiles(profileid) ON DELETE CASCADE ON UPDATE CASCADE, creatorid INTEGER NOT NULL REFERENCES user_profiles(profileid) ON DELETE CASCADE ON UPDATE CASCADE,
description TEXT, description TEXT,
docstring TEXT, docstring TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
@@ -52,7 +52,6 @@ SELECT
cmds.maskperms, cmds.maskperms,
cmds.creatorid, cmds.creatorid,
cmds.description, cmds.description,
cmds.description,
cmds.docstring, cmds.docstring,
cmds.created_at, cmds.created_at,
cmds._timestamp, cmds._timestamp,
+1
View File
@@ -54,6 +54,7 @@ class TwitchCmdClient(ExecClient):
alias=maybe_command, alias=maybe_command,
used_prefix=prefix, used_prefix=prefix,
message=message, message=message,
content=message.text,
initial_globals={ initial_globals={
"author": CustomCmdUser(message.chatter), "author": CustomCmdUser(message.chatter),
"channel": CustomCmdUser(message.broadcaster), "channel": CustomCmdUser(message.broadcaster),
+9 -3
View File
@@ -5,16 +5,19 @@ from twitchio import PartialUser
from twitchio.ext import commands as cmds from twitchio.ext import commands as cmds
from meta import Bot from meta import Bot
from twitch.client import TwitchCmdClient
from utils.lib import utc_now from utils.lib import utc_now
from . import logger
from ..customcmd.data import CustomCmd, CustomCmdData from ..customcmd.data import CustomCmd, CustomCmdData
from ..customcmd.client import ExecClient from ..customcmd.client import ExecClient
from ..customcmd.parser import ExecContext from ..customcmd.parser import ExecContext
from . import logger
from .client import TwitchCmdClient
# TODO: Make an alphacroc or croccyalpha client for testing # TODO: Make an alphacroc or croccyalpha client for testing
# TODO: Fix the tracker not actually guarding the commands properly # TODO: Fix the tracker not actually guarding the commands properly
# TODO: Fix suffix of result not printing
# TODO When command produces None don't stringify to 'None'
class CustomCmdComponent(cmds.Component): class CustomCmdComponent(cmds.Component):
@@ -58,13 +61,16 @@ class CustomCmdComponent(cmds.Component):
# Make sure the command parses (can't guarantee it runs, but at least it can parse) # Make sure the command parses (can't guarantee it runs, but at least it can parse)
try: try:
await self.cmdclient.run_command(ExecContext(args=[], content=""), response) await self.cmdclient.run_command(
ExecContext(alias="testing", args=[], content=""), response, dryrun=True
)
except Exception: except Exception:
# TODO: Nicer errors for pinpointing problem # TODO: Nicer errors for pinpointing problem
await ctx.reply(f"Sorry, could not parse your command!") await ctx.reply(f"Sorry, could not parse your command!")
logger.info( logger.info(
f"Failed to parse attempted customcmd '{response}'", exc_info=True f"Failed to parse attempted customcmd '{response}'", exc_info=True
) )
return
# If everything is good, add it to the table # If everything is good, add it to the table
# TODO: Again, permission resolution # TODO: Again, permission resolution
+10 -10
View File
@@ -1,7 +1,7 @@
import twitchio import twitchio
from meta import Bot from meta import Bot
from utils.lib import utc_now, strfdur from utils.lib import utc_now, strfdelta
from ..customcmd.parser import ExecContext from ..customcmd.parser import ExecContext
from ..customcmd.client import ExecClient from ..customcmd.client import ExecClient
@@ -25,21 +25,21 @@ class CustomCmdUser:
return self.user.display_name or self.user.name or self.user.id return self.user.display_name or self.user.name or self.user.id
async def _exec_attr_whisper(self, ctx, message: str): async def _exec_attr_whisper(self, ctx, message: str):
await self.user.send_whisper(to_user=self.user, message=message) await ctx.bot.user.send_whisper(to_user=self.user, message=message)
async def _exec_attr_followage(self, ctx, channel: twitchio.PartialUser): async def _exec_attr_followage(self, ctx, channel: "CustomCmdUser"):
followed_at = None followed_at = None
query = await channel.fetch_followers(user=self.user) query = await channel.user.fetch_followers(
user=self.user, token_for=ctx.bot.user
)
async for follower in query.followers: async for follower in query.followers:
followed_at = follower.followed_at followed_at = follower.followed_at
if followed_at: if followed_at:
durstr = strfdur(utc_now() - followed_at) durstr = strfdelta(utc_now() - followed_at)
resp = ( return durstr
f"{self.user.mention} has been following {channel.mention} for {durstr}"
)
else: else:
return f"{self.user.mention} is not following {channel.mention}" return None
@classmethod @classmethod
def from_user(cls, user: twitchio.PartialUser): def from_user(cls, user: twitchio.PartialUser):
@@ -59,7 +59,7 @@ class CustomContext(ExecContext):
used_prefix: str, used_prefix: str,
**kwargs, **kwargs,
): ):
super().__init__(**kwargs) super().__init__(alias=alias, **kwargs)
self.bot = bot self.bot = bot
self.message = message self.message = message
self.alias = alias self.alias = alias
+8 -3
View File
@@ -4,23 +4,28 @@ from typing import Optional
stuff = {} stuff = {}
def register_var(name: str | None = None): def register_var(name: str | None = None):
def wrapper(coro): def wrapper(coro):
varname = name or coro.__name__ varname = name or coro.__name__
stuff[varname] = coro stuff[varname] = coro
return coro return coro
return wrapper return wrapper
@register_var('random') @register_var("random")
async def random_func(ctx, a: int, b: Optional[int] = None): async def random_func(ctx, a: int, b: Optional[int] = None):
a = int(a)
b = int(b) if b is not None else None
if b is not None: if b is not None:
low, high = a, b low, high = a, b
else: else:
low, high = 0, a low, high = 0, a
return random.randint(low, high) return random.randint(low, high)
@register_var('user')
@register_var("user")
async def user_func(ctx, userstr: int | str): async def user_func(ctx, userstr: int | str):
""" """
Attempt to turn the given userstr into a user. Attempt to turn the given userstr into a user.