Skip to content

Instantly share code, notes, and snippets.

@NotMyWing
Last active February 20, 2022 10:49
Show Gist options
  • Save NotMyWing/632d738644c17aa71931169af5cb2767 to your computer and use it in GitHub Desktop.
Save NotMyWing/632d738644c17aa71931169af5cb2767 to your computer and use it in GitHub Desktop.
Leveret Evaluation API

Table of contents generated with markdown-toc

Data Structures and Libraries

Discord

User

The user object is a serialized combination of:

Channel

The channel object structure can be found here:

Message

The message object structure can be found here:

Embed

The embed object structure can be found here:

Util

Util (util) isn't a data structure per se, but rather a collection of useful functions.

util.findUsers(query: string) => IsolatedUserData[]

Returns a list of users (max. 10) maching the input query. If the input query is a Snowflake, tries to find a user with the given id. If the input query is a mention, converts the mention to a Snowflake and ^.

The output is sorted by relevancy to the input query.

util.reply(message: string, embed?: Embed) or util.reply(embed: Embed) => void`

Allows attaching embeds to replies. Or, it's there if for whatever reason you want to reply without using the last transferrable value.

Can only be used once per execution.

HTTP

HTTP (http) is a library that contains request, a function capable of making synchronous HTTP requests.

http.request(config: string | RequestConfig) => Response

The config argument can either be a string containing URL (GET request), or a verbose RequestConfig object following the next structure:

Keep in mind that functions and classes cannot be passed to the RequestConfig object.

The response schema is defined here:

Overclocking

Overclocking (overclocking) isn't a data structure per se, but rather a collection of various GTCE-related overclocking methods. Primarily adopted from the OC calculator, however do keep in mind that function and enum names are different.

  • GTTiers => gtTiers
  • V => voltages
  • VNames => voltageNames
  • GetTierByVoltage => getTierByVoltage
  • GetByproductChanceMultiplier => getByproductChanceMultiplier
  • CalculateOverclockInternal => calculateOverclockInternal
  • CalculateOverclock => calculateOverclock

Function args and outputs are consistent with the linked source file.

Tag Creation and Code Evaluation

Common Evaluation Context

The common context provides with the following items:

{
  msg: {
    ...Message,
    author: User,
    channel: Channel
  },
  util: [object Util],
  overclocking: [object Overclocking]
}

See Data Structures and Libraries.

Most of the standard JavaScript global objects and libraries are available, such as:

Object, Function, Array, Number, parseFloat, parseInt, Infinity, NaN, undefined, Boolean, String, Symbol, Date, Promise, RegExp, Error, AggregateError, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, globalThis, JSON, Math, console, Intl, ArrayBuffer, Uint8Array, Int8Array, Uint16Array, Int16Array, Uint32Array, Int32Array, Float32Array, Float64Array, Uint8ClampedArray, BigUint64Array, BigInt64Array, DataView, Map, BigInt, Set, WeakMap, WeakSet, Proxy, Reflect, FinalizationRegistry, WeakRef, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, escape, unescape, eval, isFinite, isNaN, SharedArrayBuffer, Atomics, WebAssembly

Tag Evaluation Context

The tag context provides everything the common one does, additionally providing tag-related items:

{
  ...<common_evaluation_context>
  tag: {
    args?: string,
    body: string,
    name: string,
    owner: string,
  }
}

(tag.args is whatever passed after %t tag, e. g. foo bar if the message is %t tag foo bar, can be undefined)

JavaScript-Enabled Tag Creation

Tags must follow the next pattern to be treated as JavaScript:

%t add tag ```      <-- the newline is required!
  "code"
```
%t add tag ```js    <-- the newline is required!
  "code"
```

The last transferrable is used as the tag output. In the example above, the output would be "code".

image

Quirks

  • If the last transferrable value is null, undefined or an empty string, the bot will fail silently
  • If the response is a valid message link, the bot will automatically make an embed for it, provided it's both actually accessible and the channel isn't blacklisted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment