Blocks

All Block

class TagScriptEngine.block.AllBlock[source]

Bases: VerbRequiredBlock

The all block checks that all of the passed expressions are true. Multiple expressions can be passed to the parameter by splitting them with |.

The payload is a required message that must be split by |. If the expression evaluates true, then the message before the | is returned, else the message after is returned.

Usage: {all(<expression|expression|...>):<message>}

Aliases: and

Payload: message

Parameter: expression

Examples:

{all({args}>=100|{args}<=1000):You picked {args}.|You must provide a number between 100 and 1000.}
# if {args} is 52
You must provide a number between 100 and 1000.

# if {args} is 282
You picked 282.

Any Block

class TagScriptEngine.block.AnyBlock[source]

Bases: VerbRequiredBlock

The any block checks that any of the passed expressions are true. Multiple expressions can be passed to the parameter by splitting them with |.

The payload is a required message that must be split by |. If the expression evaluates true, then the message before the | is returned, else the message after is returned.

Usage: {any(<expression|expression|...>):<message>}

Aliases: or

Payload: message

Parameter: expression

Examples:

{any({args}==hi|{args}==hello|{args}==heyy):Hello {user}!|How rude.}
# if {args} is hi
Hello sravan#0001!

# if {args} is what's up!
How rude.

Assignment Block

class TagScriptEngine.block.AssignmentBlock[source]

Bases: VerbRequiredBlock

Variables are useful for choosing a value and referencing it later in a tag. Variables can be referenced using brackets as any other block.

Usage: {=(<name>):<value>}

Aliases: assign, let, var

Payload: value

Parameter: name

Examples:

{=(prefix):!}
The prefix here is `{prefix}`.
# The prefix here is `!`.

{assign(day):Monday}
{if({day}==Wednesday):It's Wednesday my dudes!|The day is {day}.}
# The day is Monday.

Blacklist Block

class TagScriptEngine.block.BlacklistBlock[source]

Bases: VerbRequiredBlock

The blacklist block will attempt to convert the given parameter into a channel or role, using name or ID. If the user running the tag is in the targeted channel or has the targeted role, the tag will stop processing and it will send the response if one is given. Multiple role or channel requirements can be given, and should be split by a “,”.

Usage: {blacklist(<role,channel>):[response]}

Payload: response, None

Parameter: role, channel

Examples:

{blacklist(Muted)}
{blacklist(#support):This tag is not allowed in #support.}
{blacklist(Tag Blacklist, 668713062186090506):You are blacklisted from using tags.}

Break Block

class TagScriptEngine.block.BreakBlock[source]

Bases: Block

The break block will force the tag output to only be the payload of this block, if the passed expresssion evaluates true. If no message is provided to the payload, the tag output will be empty.

This differs from the StopBlock as the stop block stops all tagscript processing and returns its message while the break block continues to process blocks. If command blocks exist after the break block, they will still execute.

Usage: {break(<expression>):[message]}

Aliases: short, shortcircuit

Payload: message

Parameter: expression

Examples:

{break({args}==):You did not provide any input.}

Command Block

class TagScriptEngine.block.CommandBlock(limit: int = 3)[source]

Bases: VerbRequiredBlock

Run a command as if the tag invoker had ran it. Only 3 command blocks can be used in a tag.

Usage: {command:<command>}

Aliases: c, com, command

Payload: command

Parameter: None

Examples:

{c:ping}
# invokes ping command

{c:ban {target(id)} Chatflood/spam}
# invokes ban command on the pinged user with the reason as "Chatflood/spam"

Cooldown Block

class TagScriptEngine.block.CooldownBlock[source]

Bases: VerbRequiredBlock

The cooldown block implements cooldowns when running a tag. The parameter requires 2 values to be passed: rate and per integers. The rate is the number of times the tag can be used every per seconds.

The payload requires a key value, which is the key used to store the cooldown. A key should be any string that is unique. If a channel’s ID is passed as a key, the tag’s cooldown will be enforced on that channel. Running the tag in a separate channel would have a different cooldown with the same rate and per values.

The payload also has an optional message value, which is the message to be sent when the cooldown is exceeded. If no message is passed, the default message will be sent instead. The cooldown message supports 2 blocks: key and retry_after.

Usage: {cooldown(<rate>|<per>):<key>|[message]}

Payload: key, message

Parameter: rate, per

Examples:

{cooldown(1|10):{author(id)}}
# the tag author used the tag more than once in 10 seconds
# The bucket for 741074175875088424 has reached its cooldown. Retry in 3.25 seconds."

{cooldown(3|3):{channel(id)}|Slow down! This tag can only be used 3 times per 3 seconds per channel. Try again in **{retry_after}** seconds."}
# the tag was used more than 3 times in 3 seconds in a channel
# Slow down! This tag can only be used 3 times per 3 seconds per channel. Try again in **0.74** seconds.

Embed Block

class TagScriptEngine.block.EmbedBlock[source]

Bases: Block

An embed block will send an embed in the tag response. There are two ways to use the embed block, either by using properly formatted embed JSON from an embed generator or manually inputting the accepted embed attributes.

JSON

Using JSON to create an embed offers complete embed customization. Multiple embed generators are available online to visualize and generate embed JSON.

Usage: {embed(<json>)}

Payload: None

Parameter: json

Examples:

{embed({"title":"Hello!", "description":"This is a test embed."})}
{embed({
    "title":"Here's a random duck!",
    "image":{"url":"https://random-d.uk/api/randomimg"},
    "color":15194415
})}

Manual

The following embed attributes can be set manually:

  • title

  • description

  • color

  • url

  • thumbnail

  • image

  • footer

  • field - (See below)

Adding a field to an embed requires the payload to be split by |, into either 2 or 3 parts. The first part is the name of the field, the second is the text of the field, and the third optionally specifies whether the field should be inline.

Usage: {embed(<attribute>):<value>}

Payload: value

Parameter: attribute

Examples:

{embed(color):#37b2cb}
{embed(title):Rules}
{embed(description):Follow these rules to ensure a good experience in our server!}
{embed(field):Rule 1|Respect everyone you speak to.|false}
{embed(footer):Thanks for reading!|{guild(icon)}}

Both methods can be combined to create an embed in a tag. The following tagscript uses JSON to create an embed with fields and later set the embed title.

{embed({{"fields":[{"name":"Field 1","value":"field description","inline":false}]})}
{embed(title):my embed title}

Fifty Fifty Block

class TagScriptEngine.block.FiftyFiftyBlock[source]

Bases: VerbRequiredBlock

The fifty-fifty block has a 50% change of returning the payload, and 50% chance of returning null.

Usage: {50:<message>}

Aliases: 5050, ?

Payload: message

Parameter: None

Examples:

I pick {if({5050:.}!=):heads|tails}
# I pick heads

If Block

class TagScriptEngine.block.IfBlock[source]

Bases: VerbRequiredBlock

The if block returns a message based on the passed expression to the parameter. An expression is represented by two values compared with an operator.

The payload is a required message that must be split by |. If the expression evaluates true, then the message before the | is returned, else the message after is returned.

Expression Operators:

Operator

Check

Example

Description

==

equality

a==a

value 1 is equal to value 2

!=

inequality

a!=b

value 1 is not equal to value 2

>

greater than

5>3

value 1 is greater than value 2

<

less than

4<8

value 1 is less than value 2

>=

greater than or equality

10>=10

value 1 is greater than or equal to value 2

<=

less than or equality

5<=6

value 1 is less than or equal to value 2

Usage: {if(<expression>):<message>]}

Payload: message

Parameter: expression

Examples:

{if({args}==63):You guessed it! The number I was thinking of was 63!|Too {if({args}<63):low|high}, try again.}
# if args is 63
# You guessed it! The number I was thinking of was 63!

# if args is 73
# Too low, try again.

# if args is 14
# Too high, try again.

Loose Variable Block

class TagScriptEngine.block.LooseVariableGetterBlock[source]

Bases: Block

The loose variable block represents the adapters for any seeded or defined variables. This variable implementation is considered “loose” since it checks whether the variable is valid during process(), rather than will_accept().

Usage: {<variable_name>([parameter]):[payload]}

Aliases: This block is valid for any inputted declaration.

Payload: Depends on the variable’s underlying adapter.

Parameter: Depends on the variable’s underlying adapter.

Examples:

{=(var):This is my variable.}
{var}
# This is my variable.

Math Block

class TagScriptEngine.block.MathBlock[source]

Bases: Block

Override Block

class TagScriptEngine.block.OverrideBlock[source]

Bases: Block

Override a command’s permission requirements. This can override mod, admin, or general user permission requirements when running commands with the Command Block. Passing no parameter will default to overriding all permissions.

In order to add a tag with the override block, the tag author must have Manage Server permissions.

This will not override bot owner commands or command checks.

Usage: {override(["admin"|"mod"|"permissions"]):[command]}

Payload: command

Parameter: “admin”, “mod”, “permissions”

Examples:

{override}
# overrides all commands and permissions

{override(admin)}
# overrides commands that require the admin role

{override(permissions)}
{override(mod)}
# overrides commands that require the mod role or have user permission requirements

Random Block

class TagScriptEngine.block.RandomBlock[source]

Bases: VerbRequiredBlock

Pick a random item from a list of strings, split by either ~ or ,. An optional seed can be provided to the parameter to always choose the same item when using that seed.

Usage: {random([seed]):<list>}

Aliases: #, rand

Payload: list

Parameter: seed, None

Examples:

{random:Carl,Harold,Josh} attempts to pick the lock!
# Possible Outputs:
# Josh attempts to pick the lock!
# Carl attempts to pick the lock!
# Harold attempts to pick the lock!

{=(insults):You're so ugly that you went to the salon and it took 3 hours just to get an estimate.~I'll never forget the first time we met, although I'll keep trying.~You look like a before picture.}
{=(insult):{#:{insults}}}
{insult}
# Assigns a random insult to the insult variable

Range Block

class TagScriptEngine.block.RangeBlock[source]

Bases: VerbRequiredBlock

The range block picks a random number from a range of numbers seperated by -. The number range is inclusive, so it can pick the starting/ending number as well. Using the rangef block will pick a number to the tenth decimal place.

An optional seed can be provided to the parameter to always choose the same item when using that seed.

Usage: {range([seed]):<lowest-highest>}

Aliases: rangef

Payload: number

Parameter: seed, None

Examples:

Your lucky number is {range:10-30}!
# Your lucky number is 14!
# Your lucky number is 25!

{=(height):{rangef:5-7}}
I am guessing your height is {height}ft.
# I am guessing your height is 5.3ft.

Redirect Block

class TagScriptEngine.block.RedirectBlock[source]

Bases: VerbRequiredBlock

Redirects the tag response to either the given channel, the author’s DMs, or uses a reply based on what is passed to the parameter.

Usage: {redirect(<"dm"|"reply"|channel>)}

Payload: None

Parameter: “dm”, “reply”, channel

Examples:

{redirect(dm)}
{redirect(reply)}
{redirect(#general)}
{redirect(626861902521434160)}

Replace Block

class TagScriptEngine.block.ReplaceBlock[source]

Bases: VerbRequiredBlock

The replace block will replace specific characters in a string. The parameter should split by a ,, containing the characters to find before the command and the replacements after.

Usage: {replace(<original,new>):<message>}

Aliases: None

Payload: message

Parameter: original, new

Examples:

{replace(o,i):welcome to the server}
# welcime ti the server

{replace(1,6):{args}}
# if {args} is 1637812
# 6637862

{replace(, ):Test}
# T e s t

Require Block

class TagScriptEngine.block.RequireBlock[source]

Bases: VerbRequiredBlock

The require block will attempt to convert the given parameter into a channel or role, using name or ID. If the user running the tag is not in the targeted channel or doesn’t have the targeted role, the tag will stop processing and it will send the response if one is given. Multiple role or channel requirements can be given, and should be split by a “,”.

Usage: {require(<role,channel>):[response]}

Aliases: whitelist

Payload: response, None

Parameter: role, channel

Examples:

{require(Moderator)}
{require(#general, #bot-cmds):This tag can only be run in #general and #bot-cmds.}
{require(757425366209134764, 668713062186090506, 737961895356792882):You aren't allowed to use this tag.}

ShortCutRedirect Block

class TagScriptEngine.block.ShortCutRedirectBlock(var_name)[source]

Bases: Block

STRF Block

class TagScriptEngine.block.StrfBlock[source]

Bases: Block

The strf block converts and formats timestamps based on strftime formatting spec. Two types of timestamps are supported: ISO and epoch. If a timestamp isn’t passed, the current UTC time is used.

Invoking this block with Unix Specific Services will return the current Unix timestamp.

Usage: {strf([timestamp]):<format>}

Aliases: unix

Payload: format, None

Parameter: timestamp

Example:

{strf:%Y-%m-%d}
# 2021-07-11

{strf({user(timestamp)}):%c}
# Fri Jun 29 21:10:28 2018

{strf(1420070400):%A %d, %B %Y}
# Thursday 01, January 2015

{strf(2019-10-09T01:45:00.805000):%H:%M %d-%B-%Y}
# 01:45 09-October-2019

{unix}
# 1629182008

Strict Variable Block

class TagScriptEngine.block.StrictVariableGetterBlock[source]

Bases: Block

The strict variable block represents the adapters for any seeded or defined variables. This variable implementation is considered “strict” since it checks whether the variable is valid during will_accept() and is only processed if the declaration refers to a valid variable.

Usage: {<variable_name>([parameter]):[payload]}

Aliases: This block is valid for any variable name in Response.variables.

Payload: Depends on the variable’s underlying adapter.

Parameter: Depends on the variable’s underlying adapter.

Examples:

{=(var):This is my variable.}
{var}
# This is my variable.

SubstringBlock Block

class TagScriptEngine.block.SubstringBlock[source]

Bases: VerbRequiredBlock

URL Encode Block

class TagScriptEngine.block.URLEncodeBlock[source]

Bases: VerbRequiredBlock

This block will encode a given string into a properly formatted url with non-url compliant characters replaced. Using + as the parameter will replace spaces with + rather than %20.

Usage: {urlencode(["+"]):<string>}

Payload: string

Parameter: “+”, None

Examples:

{urlencode:covid-19 sucks}
# covid-19%20sucks

{urlencode(+):im stuck at home writing docs}
# im+stuck+at+home+writing+docs

# the following tagscript can be used to search up tag blocks
# assume {args} = "command block"
<https://phen-cogs.readthedocs.io/en/latest/search.html?q={urlencode(+):{args}}&check_keywords=yes&area=default>
# <https://phen-cogs.readthedocs.io/en/latest/search.html?q=command+block&check_keywords=yes&area=default>