Generic Bot APIs - salty-outlaws/generic-bot GitHub Wiki
Generic Bot exposes multiple APIs which can be consumed when making a plugin.
When Generic Bot first loads plugins, it calls a method "RegisterCommands" for each of the loaded plugins. This is of the format RegisterCommands(pluginName)
. As a plugin developer - you can treat this like the entry point to your plugin or a init method.
The plugin framework exposes the following methods which can be used in the plugin.
function | summary | signature |
---|---|---|
rGet | Rest Get | RGet(url string) string |
rPut | Rest Put | RPost(url string, body string) string |
rPost | Rest Post | RPut(url string, body string) string |
rPatch | Rest Patch | RPatch(url string, body string) string |
rDelete | Rest Delete | RDelete(url string) |
mUpsert | mongo upsert | MUpsert(dbName, coll, id string, data map[string]any) bool |
mGet | mongo get | MGet(dbName, coll, id string) map[string]any |
mDelete | mongo delete | MDelete(dbName, coll, id string) bool |
mFind | mongo db find | MFind(dbName, coll string, query map[string]any, sort map[string]int) []map[string]any |
jsonToMap | converts json string to map | JsonToMap(val string) map[string]any |
jsonListToMapList | converts json string to list of maps | JsonListToMapList(val string) []map[string]any |
stringSplit | String Split | StringSplit(value string, delimeter string) []string |
stringJoin | String Join | StringJoin(values []string, delimeter string) string |
stringReplaceFirst | String ReplaceFirst | StringReplaceFirst(value, old, new string) string |
stringReplace | String Replace | StringReplace(value, old, new string) string |
tagToId | converts discord @user to userId | DiscordTagToId(value string) string |
idToTag | converts discord userId to @user tag | DiscordIdToTag(value string) string |
random | returns a random number in the given range | RandomNumber(from int, to int) int |
yesno | returns a random true or false | YesNo() bool |
log | log from a plugin | Log(msg any) |
embed | embed output type | Embed(title, summary string, field map[string]string) string |
image | image output type | Image(link string) string |
text | text output type | Text(message string) string |
RegisterCommand | allow registering commands and prefix from plugin | RegisterCommand(plugin, prefix, command, function string) |