R16 - A Discord Trick Bot
1 The Trick Environment
8.0

R16 - A Discord Trick Bot

R16 is a "trick bot" for Discord. It saves snippets of code, which can then be recalled and executed on user-provided input.

1 The Trick Environment

Tricks are stored as plain text, and invoked in a sandbox from racket/sandbox.

The following symbols are available in the trick context:

All symbols from the threading-lib package are available for convenience.

procedure

(make-attachment payload name mime)  any/c

  payload : bytes?
  name : (or/c string? bytes?)
  mime : (or/c symbol? string? bytes?)
Creates an attachment with payload payload, filename name, and MIME-type mime. This opaque object must be returned from the trick to be sent to Discord. If more than one attachment is returned, an unspecified one is sent.

procedure

(call-trick name argument)  any/c

  name : (or/c symbol? string?)
  argument : any/c
Invokes another trick named by name and return its result. If argument is #f, then an empty string is passed to the subtrick. Otherwise, (~a argument) is passed.

value

message-contents : string?

Full text of the message that invoked this trick.

value

string-args : string?

Text of the message after the bot command, as a string.

procedure

(read-args)  (or/c (listof any/c) #f)

Function that returns string-args, but as a list of datums read by read. If there is a read failure, #f is returned.

procedure

(emote-lookup name)  (or/c string? #f)

  name : string?
Function that returns the ID for emote with name name, or #f if it doesn’t exist.

procedure

(emote-image id)  (or/c bytes? #f)

  id : string?
Function that returns the PNG data of the emote with ID id, or #f if it doesn’t exist.

procedure

(read-storage type)  any/c

  type : (or/c 'guild 'channel 'user)
Reads "trick-local storage" name and return its result, or #f if the result is uninitialized.

A trick’s "trick-local storage" can be per-guild, per-channel, or per-user.

This will always return #f for the eval command.

procedure

(write-storage type data)  boolean?

  type : (or/c 'guild 'channel 'user)
  data : any/c
Writes data to the trick’s "trick-local storage," overwriting any existing value, and returns whether the write succeeded. All data supported by write can be written.

Note that "trick-local storage" is transient and does not currently persist across bot restarts.

A trick’s "trick-local storage" can be per-guild, per-channel, or per-user; each type of storage has its own limitation on size:

Type

 

Size Limit

guild

 

64kb

channel

 

8kb

user

 

2kb

This will always be a no-op when invoked from the eval command.

procedure

(delete-caller)  void?

Thunk that deletes the message that invoked this sandbox.

value

parent-context : (or/c (hash/c symbol? any/c) #f)

Mapping of all the above symbols for the trick calling this one, or #f if this trick is the top level invocation.