예제 #1
0
    async def invoketag(self,
                        ctx,
                        response: Optional[bool],
                        tag_name: str,
                        *,
                        args: Optional[str] = ""):
        """
        Manually invoke a tag with its name and arguments.

        Restricting this command with permissions in servers will restrict all members from invoking tags.
        """
        response = response or True
        try:
            _tag = await TagConverter(check_global=True).convert(ctx, tag_name)
        except commands.BadArgument as e:
            if response is True:
                await ctx.send(e)
        else:
            seed = {"args": adapter.StringAdapter(args)}
            await self.process_tag(ctx, _tag, seed_variables=seed)
예제 #2
0
    async def tag(self,
                  ctx,
                  response: Optional[bool],
                  tag_name: str,
                  *,
                  args: Optional[str] = ""):
        """Tag management with TagScript.

        These commands use TagScriptEngine. [This site](https://github.com/phenom4n4n/phen-cogs/blob/master/tags/README.md) has documentation on how to use TagScript blocks."""
        if response is None:
            response = True
        try:
            tag = await TagConverter().convert(ctx, tag_name)
        except commands.BadArgument as e:
            if response:
                await ctx.send(e)
                return
        async with self.config.guild(ctx.guild).tags() as t:
            t[tag_name]["uses"] += 1
        seed = {"args": adapter.StringAdapter(args)}
        await self.process_tag(ctx, tag, seed_variables=seed)
예제 #3
0
    async def tag(self,
                  ctx,
                  response: Optional[bool],
                  tag_name: str,
                  *,
                  args: Optional[str] = ""):
        """
        Tag management with TagScript.

        These commands use TagScriptEngine. [This site](https://phen-cogs.readthedocs.io/en/latest/index.html) has documentation on how to use TagScript blocks.
        """
        if response is None:
            response = True
        try:
            _tag = await TagConverter().convert(ctx, tag_name)
        except commands.BadArgument as e:
            if response:
                await ctx.send(e)
            return
        seed = {"args": adapter.StringAdapter(args)}
        log.info(
            f"Processing tag for {tag_name} on {ctx.guild} ({ctx.guild.id})")
        await self.process_tag(ctx, _tag, seed_variables=seed)
예제 #4
0
파일: command.py 프로젝트: bobloy/phen-cogs
 def process(self, ctx: Interpreter.Context) -> Optional[str]:
     if ctx.verb.parameter == None:
         return None
     ctx.response.variables[ctx.verb.parameter] = adapter.StringAdapter(str(ctx.verb.payload))
     return ""
예제 #5
0
import time
from TagScriptEngine import Verb, Interpreter, block, adapter

blocks = [
    block.MathBlock(),
    block.RandomBlock(),
    block.RangeBlock(),
    block.StrfBlock(),
    block.AssignmentBlock(),
    block.FiftyFiftyBlock(),
    block.LooseVariableGetterBlock(),
]
x = Interpreter(blocks)

# data to inject
dummy = {"message": adapter.StringAdapter("Hello, this is my message.")}


def timerfunc(func):
    """
    A timer decorator
    """
    def function_timer(*args, **kwargs):
        """
        A nested function for timing other functions
        """
        start = time.time()
        value = func(*args, **kwargs)
        end = time.time()
        runtime = end - start
        msg = "The runtime for {func} took {time} seconds to complete 1000 times"