Builtins

Rune ships a compact standard library. Every builtin is available as a bare function, and most also work as methods. "abc".toUpperCase() and upper("abc") are the same call.

Output

Send text with say. It accepts any number of values. Pass an embed built with embed() to send an embed instead.

rune
2 lines
functiondoes
say(...)sends the values as a message
echo(...)same as say

Math

Rounding, powers, trigonometry, and clamping. Note that range returns a list.

functiondoes
min(a, b, ...)smallest of the numbers
max(a, b, ...)largest of the numbers
abs(x)absolute value
floor(x)rounds down
ceil(x)rounds up
round(x, digits)rounds, optionally to a number of digits
sqrt(x)square root
pow(a, b)a to the power of b
sin(x) cos(x) tan(x)trigonometry
log(x)natural log
log10(x)base 10 log
exp(x)e to the power of x
clamp(x, lo, hi)clamps x into the range
range(end)[0, 1, ..., end-1]
range(start, end)numbers from start to end-1
range(start, end, step)with a custom step

Random

Everything you need for games, giveaways, and dice.

functiondoes
random()a float between 0 and 1
randomFloat(lo, hi)a float in a range
randomInt(lo, hi)an integer in a range, both ends included
choose(list)a random item from a list
shuffle(list)a shuffled copy of a list
rune
3 lines

Strings

Case, splitting, slicing, searching, and padding. The string builtins also work as methods.

functiondoes
str(x)converts to a string
lower(s) / upper(s)changes case
capitalize(s)first letter upper, rest lower
title(s)first letter of each word upper
strip(s) / trim(s)removes surrounding whitespace
lstrip(s) / rstrip(s)removes whitespace on one side
split(s, sep)splits into a list
join(list, sep)joins a list into a string
replace(s, from, to)replaces every occurrence
substring(s, start, end)part of a string
slice(x, start, end)works on strings and lists
length(x) / len(x)size of a string, list, or dict
strlen(s)length of a string
indexOf(s, sub)position of sub, or -1
startsWith(s, pre) / endsWith(s, post)checks the start and end
contains(x, item) / includes(x, item)works on strings and lists
repeat(s, n)the string repeated
count(s, sub)how many times sub appears
charAt(s, i)the character at index i
reverse(x)works on strings and lists
format(s, ...)format("{0} and {1}", a, b)
padStart(s, n, pad) / padEnd(s, n, pad)pads to a length

Lists

Build, transform, and reduce lists. The higher-order functions take a tag function.

functiondoes
push(list, ...) / append(list, ...)adds to the end
pop(list)removes and returns the last
shift(list)removes and returns the first
unshift(list, ...) / prepend(list, ...)adds to the front
sort(list, ", ")returns a sorted copy
concat(list, ...)joins lists together
flatten(list)flattens one level
unique(list)removes duplicates
sum(list)adds up the numbers
first(list) / last(list)the ends
map(list, fn)applies fn to each item
filter(list, fn)keeps items where fn is true
reduce(list, fn, initial)folds the list
forEach(list, fn)runs fn for each item
find(list, fn)first item where fn is true
some(list, fn) / any(list, fn)true if any item matches
every(list, fn) / all(list, fn)true if all items match

Dictionaries

Inspect and mutate dicts without fuss.

functiondoes
keys(d)the keys as a list
values(d)the values as a list
entries(d) / items(d)[[key, value], ...]
has(d, key)true if the key exists
get(d, key, fallback)value or fallback
set(d, key, value)sets a key
delete(d, key) / remove(d, key)removes a key
merge(d, ...)a copy with others merged in
update(d, ...)merges into the dict in place

Conversion & JSON

Coerce values and move data in and out of JSON.

functiondoes
int(x) / float(x) / bool(x)converts a value
num(x) / number(x)converts to a number
jsonParse(s) / fromJson(s)parses JSON
jsonStringify(x) / toJson(x)turns a value into JSON
dump(x)pretty-printed JSON
base64Encode(s) / base64Decode(s)base64 conversion

Type checks

Ask what something is before you use it.

functiondoes
type(x) / typeof(x)number, string, array, dict, ...
isNumber(x) isString(x) isBool(x)checks the type
isArray(x) isDict(x)checks the type
isNull(x) isUndefined(x)checks the type
isFunction(x)true for tag functions
isEmbed(x)true for embeds

Dates

Timestamps are in milliseconds. now() returns seconds, nowMs() returns milliseconds.

functiondoes
now() / timestamp() / unix()current time in seconds
nowMs()current time in milliseconds
date(x)a date from a timestamp or string
strftime(date, format)formats a date
year(d) month(d) day(d)parts of a date
hour(d) minute(d) second(d)parts of a time

strftime codes

%Y %m %d %H %M %S %y %L: year, month, day, hour, minute, second, short year, and millisecond.

Regex

Build a pattern with regex(pattern, flags). Inside a string, escape a backslash so it survives. Write regex("\\d") for a digit.

functiondoes
regex(pattern, flags)builds a pattern
test(s, re)true if the pattern matches
match(s, re)first match, or all matches if the pattern is global
regexReplace(s, re, replacement)replaces every match
rune
2 lines

Markdown helpers

These wrap text in Fluxer formatting.

functionoutput
bold(s)**s**
italic(s)*s*
underline(s)s
strikethrough(s)s
spoiler(s)s
code(s)a code block
inlineCode(s)inline code
quote(s)a quote
link(text, url)a hyperlink

Mentions & users

Build mentions and read user dicts from the context globals.

functiondoes
mention(id)mentions a user, channel, or role by id
userMention(id) / channelMention(id)a specific mention
roleMention(id)a role mention
everyoneMention() / hereMention()pings everyone or here
userTag(d)username#discriminator for a user dict
displayName(d)the display name for a user dict
avatarURL(d)the avatar URL for a user dict