Skip to content
Duncan Sterken edited this page May 19, 2019 · 11 revisions

The custom commands feature and the join/leave messges utilize JagTag notation. JagTag is a text-processing language that can be customized for different applications. For full documentation on the JagTag java library, check out the repository. Please check out the documentation on methods available in DuncteBot here, as well as the examples below!

Methods

Discord

These methods deal with Discord entities, like users, channels, etc.
Please note that crossed out methods are not available yet.

{user} - Returns the name of the user that ran the command
{user:SEARCH} - Returns the name of the user found based on the given search

Example: I found {user:dunct} and me, {user}
Input: db!example
Output: I found duncte123 and me, Merlin

{usertag} - Returns the tag of the user that ran the command
{usertag:SEARCH} - Returns the tag of the user found based on the given search

Example: I found {usertag:ramid} and me, {usertag}
Input: db!example
Output: I found ramidzkh#4814 and me, IWS_Mello#2815

{nick} - Returns the nickname of the user that ran the command
{nick:SEARCH} - Returns the nickname of the user found based on the given search

Example: {nick:dunct} is the nickname of duncte123, and {nick} is my nickname
Input: db!example
Output: Danny is the nickname of duncte123, and Hourglass is my nickname

{discrim} - Returns the discriminator of the user that ran the command
{discrim:SEARCH} - Returns the discriminator of the user found based on the given search

Example: duncte's discrim is {discrim:dunct}, but mine is {discrim}
Input: db!example
Output: duncte's discrim is 1245, but mine is 1337

{avatar} - Returns the url of the avatar of the user that ran the command
{avatar:SEARCH} - Returns the url of the avatar of the user found based on the given search

Example: My avatar: {avatar}
Input: db!example
Output: My avatar: http://website.com/image.png

{creation:ENTITY ID} - Returns the creation time of an entity based on its ID

Example: The account was created {creation:113156185389092864}
Example 2: My account was created {creation:{userid}}
Input: db!example
Output: The account was created Mon, 9 Nov 2015 06:02:16 GMT Output 2: My account was created Sat, 11 Jun 2016 16:44:56 GMT

{userid} - Returns the id of the user running the command

Example: My id is {userid}
Input: db!example
Output: My id is 191231307290771456

{atuser} - Returns a ping of the user running the command. This is equivalent to <@{userid}>

Example: Ping me {atuser}
Input: db!example
Output: Ping me @duncte123

{server} - Returns the name of the server

Example: Welcome to {server}!
Input: db!example
Output: Welcome to DuncteBot Team & Support!

{serverid} - Returns the ID of the server

Example: This server's ID is {serverid}
Input: db!example
Output: This server's ID is 191245668617158656

{servercount} - Returns the number of members on the server

Example: There's {servercount} members
Input: db!example
Output: There's 1931 members

{servericon} - Returns the icon url of the server

Example: Icon: {servericon}
Input: db!example
Output: Icon: http://website.com/icon.png

{channel} - Returns the mention of the current channel
{channel:SEARCH} - Returns the mention of a channel based on the search

Example: This is {channel} and we also have {channel:gener}
Input: db!example
Output: This is #testing and we also have #general

{channelid} - Returns the id of the current channel
{channelid:SEARCH} - Returns the id of a channel based on the search

Example: This channel ID is {channelid}, the id of #meme-miners is {channelid:meme}
Input: db!example
Output: This channel ID is 411484591078244352, the id of #meme-miners is 360324967331659776

{randuser} - Returns the name of a random user on the server

Example: Send a message to {randuser} please
Input: db!example
Output: Send a message to Xamtheking please

{randatuser} - Returns the mention of a random user on the server

Example: Send a message to {randatuser} please
Input: db!example
Output: Send a message to @DavianFlight please

{randonline} - Returns the name of a random online user on the server

Example: Hey look! {randonline} is online!
Input: db!example
Output: Hey look! Sikor is online!

{randatonline} - Returns the mention of a random online user on the server

Example: Hey look! {randatonline} is online!
Input: db!example
Output: Hey look! @Noooope is online!

{randchannel} - Returns the mention of a random channel on the server

Example: Lets see what's going on in {randchannel}
Input: db!example
Output: Let's see what's going on in #support

Arguments

Arguments deal with input that is provided when the JagTag code is run. For example, when using a command, users can provide input to the command (after the name) and this input is provided as arguments.

{args} - Any additional text that is passed in

Example: You said "{args}".
Input: db!example I am a potato
Output: You said "I am a potato"

{argslen} - The number of arguments provided (split on any whitespace)

Example: You said {argslen} words
Input: db!example This is a cool command
Output: You said 5 words

{arg:NUMBER} - Returns the numbered argument. This is zero-based indexing, so the first argument is {arg:0}. If the number provided is higher than the total number of arguments, it is taken modulus the number of arguments so it will always be valid.

Example: Your 3rd word was: {arg:2}
Input: db!example I said some words
Output: Your 3rd word was: some

Functional

Functional methods deal with conditional statements, mathematics, and random numbers

{note:TEXT} - Comment that gets removed at runtime

Example: {note:This is a cool command} Hi there!
Input: db!example
Output: Hi there!

{choose:OPTION 1|OPTION 2|OPTION 3...} - Chooses randomly between several options. At least one item must be included.

Example: It's going to be {choose:sunny|rainy|stormy} today
Input: db!example
Output: It's going to be rainy today

{range:NUMBER|NUMBER} - Picks a random number in the provided range. This is inclusive for the lower number and exclusive for the higher number. For example, {range:3|7} can return 3, 4, 5, or 6

Example: There is a {range:0|101}% chance of this
Input: db!example
Output: There is a 57% chance of this

{if:ITEM|CONDITIONAL|ITEM|then:TEXT|else:TEXT} - Compares two items. If both items are numbers, they are compared using their values.

Comparator Text Number
= Exact same text Exact same value
< Alphabetical comparison Numeric comparison
> Alphabetical comparison Numeric comparison
~ Case-insensitive text Approximate same value (2 decimal places)
? Regex matching N/A

Example: {if:this|?|th.*|then:The word starts with th|else:The word doesn't}
Input: db!example
Output: The word starts with th

{math:NUMBER|EXPRESSION|NUMBER|EXPRESSION|NUMBER...} - Evaluates mathematics. Available expressions are + (addition), - (subtraction), * (multiplication), / (division), % (modulus), ^ (exponentiation)

Example: There are {math:60|*|60|*|24} seconds in a day
Input: db!example
Output: There are 86400 seconds in a day

{abs:NUMBER} - Takes the absolute value of a number

Example: Absolute value of -6 is {abs:-6}
Input: db!example
Output: Absolute value of -6 is 6

{floor:NUMBER} - Rounds a number down

Example: Floor of 8.3 is {floor:8.3}
Input: db!example
Output: Floor of 8.3 is 8

{ceil:NUMBER} - Rounds a number up

Example: Ceiling of 4.1 is {ceil:4.1}
Input: db!example
Output: Ceiling of 4.1 is 5

{round:NUMBER} - Rounds a number up or down based on the decimal value

Example: 5.6 rounded is {round:5.6}
Input: db!example
Output: 5.6 rounded is 6

{sin:NUMBER} - Takes sine of radian value

Example: Sine of 1.1 is {sin:1.1}
Input: db!example
Output: Sine of 1.1 is 0.89120736006

{cos:NUMBER} - Takes cosine of radian value

Example: Cosine of 1.1 is {cos:1.1}
Input: db!example
Output: Cosine of 1.1 is 0.45359612142

{tan:NUMBER} - Takes tangent of radian value

Example: Tangent of 1.1 is {tan:1.1}
Input: db!example
Output: Tangent of 1.1 is 1.96475965725

{base:NUMBER|OLD BASE|NEW BASE} - Converts a number from one base to another base

Example: 6 in binary is {base:6|10|2}
Input: db!example
Output: 6 in binary is 110

Strings

String methods are used for text manipulation

{lower:TEXT} - Makes a string all lowercase

Example: {lower:wHOA thErE!}
Input: db!example
Output: whoa there!

{upper:TEXT} - Makes a string all uppercase

Example: {upper:wHOA thErE!}
Input: db!example
Output: WHOA THERE!

{length:TEXT} - Returns the length of a string

Example: "Hello" is {length:Hello} characters long
Input: db!example
Output: "Hello" is 5 characters long

{url:TEXT} - Converts a string to standard URL UTF-8 encoding

Example: http://lmgtfy.com/?q={url:Discord Bots}
Input: db!example
Output: http://lmgtfy.com/?q=Discord+Bots

{replace:TEXT|with:TEXT|in:TEXT} - Replaces some text with other text in the provided text

Example: {replace:hello|with:goodbye|in:Oh, hello! I say hello a lot!}
Input: db!example
Output: Oh, goodbye! I say goodbye a lot!

{replaceregex:REGEX|with:TEXT|in:TEXT} - Replaces text matching a regex with other text in the provided text

Example: {replaceregex:\d|with:#|in:I have 5 cats and 23 shirts}
Input: db!example
Output: I have # cats and ## shirts

{substring:NUMBER|NUMBER|TEXT} - Takes a substring of a provided string. Numbers can be negative to work backward from the end of a string. Like range:, the lower number is inclusive and the higher number is exclusive.

Example: {substring:3|5|My Cool Text}
Input: db!example
Output: Co

{oneline:TEXT} - Condenses all whitespace (including newlines) to simple spaces

Example: {oneline:Whoa ​ ​ this is ​ ​ ​ ​ ​ a lot of space}
Input: db!example
Output: Whoa this is a lot of space

{hash:TEXT} - Returns a hash code for the provided text. This often, but not completely unique

Example: Your hash is: {hash:my text here}
Input: db!example
Output: Your hash is: -292243057

Time

These methods are designed for dealing with time and time formatting

{now} - Shows the current time, formatted to RFC 1123
{now:FORMAT} Shows the current time, formatted as specified. See the DateTimeFormatter Patterns documentation for available format symbols

Example: The current year is {now:YYYY}
Input: db!example
Output: The current year is 2018

{time:EPOCH MILLIS|FORMAT} - Parses the provided epoch milliseconds to the specified formatted time. If the format is not provided, it uses RFC 1123

Example: Current minutes: {time:1496519175495|mm}
Input: db!example
Output: Current minutes: 46

Variables

These methods are for dealing with variables. Variable values are not persistent after commands are run; these are for in-line changes only.

{set:NAME|VALUE} - Sets a variable to a value. This doesn't return any string

Example: {set:count|80} I'm setting the count to 80
Input: db!example
Output: I'm setting the count to 80

{get:NAME} - Recalls a variable. The variable must exist.

Example: {set:food|Pizza} My favorite food is {get:food}
Input: db!example
Output: My favorite food is Pizza


Examples

  • Mention a user: <@{userid}>
  • Give a response only if one is provided: {if:{argslen}|=|0|then:Please say something|else:{nick} said: {args}}
  • Give the number of users in a server only if it is a multiple of 100: {if:{math:{servercount}|%|100}|=|0|then:That's {servercount} users!|else:}
  • Pick a random phrase: I ate {choose:too many|a lot of|a big pile of|{range:0|100}|2 and a half} cookies!
Clone this wiki locally