Skip to content

The Variable system

Casper1123 edited this page Oct 2, 2024 · 9 revisions

Welcome tot the wiki page on the variable system.
This page will be divided into the following segments:

  • Where to use variables
  • How to use variables
  • Regular variables
  • Command variables

Where to use variables

Variables are usable in many strings that the bot processes. The most important one of these is facts, but it also works on auto-replies, triggers, sayings, anything really. If you're interested in the code behind the processing, you can find it here.

How to use variables

Whenever you're adding a fact, variables are represented inside {}.

If you want to use { or } without calling a variable, put a \ before it (ex: \{ \}) This also works for variable indicating characters in [command variables](https://github.com/Casper1123/Patrick-Bateman-Discord-Bot/wiki/The-Variable-system#command-variables). (for example, using a "inside of achoiceoption:{choice:"this has a " in it"}) For what variables exist or how they work, see below. <BR> To use a variable, take for example this following fact that you could enter into [/admin preview [fact]](https://github.com/Casper1123/Patrick-Bateman-Discord-Bot/wiki/Admin-commands#admin-preview-fact): <BR> Hello {user.name}! I hope you've been having {choice:"a nice","an awesome"} day.<BR> Keep in mind that you can still use [Markdown styling](https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51) to for example link a channel:<#{channel.id}>`

Regular variables

Regular variables are predefined pieces of data that you can access without any arguments.
*For bot hosters: Some information is only usable inside of servers. If something is **not globally* usable, it will have an * added to it

user

The user that triggered the response. This is either the caller of the command, or the sender of the message.

  • user.account the user's account name.
  • user.name the user's (nick)name.
  • user.id the user's account id.

guild

The server the command is ran in.

  • guild.id* the server's id.
  • guild.name* the server's name.

This also has the guild's owner. In case you ever need it. Don't be too annoying.

  • guild.owner.account* the account name of the server's owner.
  • guild.owner.name* the (nick)name of the server's owner.
  • guild.owner.id* the account id of the server's owner.

randomuser

A random account from the server's entire member list is selected for this iteration of the fact.
Using any of the randomuser variables will point towards the same person.

  • randomuser.account* the randomly picked user's account name.
  • randomuser.name* the randomly picked user's (nick)name.
  • randomuser.id* the randomly picked user's account id.

self

Refers to the bot (and it's account) itself.

  • self.name the bot's name.
  • self.id the bot's id.
  • self.nick* the bot's nickname.

General

More general-purpose variables.

  • enter Adds a newline. you can also just put \n inside of a fact which works the same.
  • total_facts the sum of the local and global fact counts.
  • global_facts the count of global facts.
  • local_facts the count of local facts.

Command variables

Command variables (more commonly known as functions) take parameters to work properly. The type of parameters, and a couple examples, will be listed with their documentation.

rand:int,int

rand:int,int takes a lower and an upper int (no space behind the comma , ) and generates a random number between those (inclusive)

ex: {rand:1,5} is my lucky number.

choice:*str

choice:*str gives multiple options to select a random one from. The selection may contain variables.
Make sure to mark the ending of each option properly. The , in between is not mandatory, however using double quotations " is.

ex: {choice:"option1","option2, it even has a variable: {rand:0,1}"}

Clone this wiki locally