Skip to content

Commit

Permalink
docs!
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed May 5, 2024
1 parent ddccfba commit 658c0e7
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 57 deletions.
1 change: 0 additions & 1 deletion packages/lightning/deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.7.0",
"exports": {
".": "./mod.ts",
"./cli": "./src/cli/mod.ts",
"./plugins": "./src/plugins.ts",
"./types": "./src/types.ts",
"./utils": "./src/utils.ts"
Expand Down
3 changes: 3 additions & 0 deletions packages/lightning/mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* @module
* Lightning is a Typescript-based chatbot that supports
* bridging multiple chat platforms via plugins.
*/

export { bridges } from './src/bridges/mod.ts';
export { lightning } from './src/lightning.ts';
export { plugin } from './src/plugins.ts';
export * from './src/types.ts';
Expand Down
18 changes: 9 additions & 9 deletions packages/lightning/src/bridges/command_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function join(
opts: command_arguments,
l: lightning
): Promise<[boolean, string]> {
if (await l.bridge.is_in_bridge(opts.channel)) {
if (await l.bridges.is_in_bridge(opts.channel)) {
return [
false,
"To do this, you can't be in a bridge. Try leaving your bridge first."
Expand All @@ -22,7 +22,7 @@ export async function join(
}

const plugin = l.plugins.get(opts.platform);
const bridge = (await l.bridge.get_bridge({
const bridge = (await l.bridges.get_bridge({
id: `lightning-bridge-${id}`
})) || {
allow_editing: false,
Expand All @@ -37,7 +37,7 @@ export async function join(
data: await plugin!.create_bridge(opts.channel)
});

await l.bridge.set_bridge(bridge);
await l.bridges.set_bridge(bridge);

return [true, 'Joined a bridge!'];
}
Expand All @@ -46,15 +46,15 @@ export async function leave(
opts: command_arguments,
l: lightning
): Promise<[boolean, string]> {
const bridge = await l.bridge.get_bridge({
const bridge = await l.bridges.get_bridge({
channel: opts.channel
});

if (!bridge) {
return [true, "You're not in a bridge, so try joining a bridge first."];
}

await l.bridge.set_bridge({
await l.bridges.set_bridge({
...bridge,
channels: bridge.channels.filter(
i => i.id !== opts.channel && i.plugin !== opts.platform
Expand All @@ -67,7 +67,7 @@ export async function leave(
export async function reset(opts: command_arguments, l: lightning) {
if (!opts.opts.name)
opts.opts.name =
(await l.bridge.get_bridge({ channel: opts.channel }))?.id ||
(await l.bridges.get_bridge({ channel: opts.channel }))?.id ||
opts.channel;

let [ok, text] = await leave(opts, l);
Expand All @@ -78,7 +78,7 @@ export async function reset(opts: command_arguments, l: lightning) {
}

export async function toggle(opts: command_arguments, l: lightning) {
const bridge = await l.bridge.get_bridge({ channel: opts.channel });
const bridge = await l.bridges.get_bridge({ channel: opts.channel });

if (!bridge) {
return "You're not in a bridge right now. Try joining one first.";
Expand All @@ -96,13 +96,13 @@ export async function toggle(opts: command_arguments, l: lightning) {

bridge[setting] = !bridge[setting];

await l.bridge.set_bridge(bridge);
await l.bridges.set_bridge(bridge);

return 'Toggled that setting!';
}

export async function status(args: command_arguments, l: lightning) {
const current = await l.bridge.get_bridge(args);
const current = await l.bridges.get_bridge(args);

if (!current) {
return "You're not in any bridges right now.";
Expand Down
6 changes: 3 additions & 3 deletions packages/lightning/src/bridges/handle_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export async function handle_message(
): Promise<void> {
const bridge =
type === 'create_message'
? await lightning.bridge.get_bridge(msg)
: await lightning.bridge.get_bridge_message(msg.id);
? await lightning.bridges.get_bridge(msg)
: await lightning.bridges.get_bridge_message(msg.id);

if (!bridge) return;

Expand Down Expand Up @@ -101,7 +101,7 @@ async function get_reply_id(
) {
if ('replytoid' in msg && msg.replytoid) {
try {
const bridge_from_msg = await lightning.bridge.get_bridge_message(
const bridge_from_msg = await lightning.bridges.get_bridge_message(
msg.replytoid
);

Expand Down
5 changes: 3 additions & 2 deletions packages/lightning/src/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { create_message, log_error } from './utils.ts';

/** an instance of lightning */
export class lightning extends EventEmitter<plugin_events> {
bridge: bridges;
/** the bridge system */
bridges: bridges;
/** the commands registered */
commands: Map<string, command>;
/** the config used */
Expand All @@ -29,7 +30,7 @@ export class lightning extends EventEmitter<plugin_events> {
this.commands = new Map(config.commands);
this.redis = new RedisClient(redis_conn);
this.listen_commands();
this.bridge = new bridges(this);
this.bridges = new bridges(this);
this.load(this.config.plugins);
}

Expand Down
140 changes: 101 additions & 39 deletions packages/lightning/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { lightning } from './lightning.ts';
import type { plugin } from './plugins.ts';

/** attachments within a message */
export interface attachment {
/** alt text for images */
alt?: string;
Expand All @@ -15,11 +16,11 @@ export interface attachment {
}

/** channel within a bridge */
export interface bridge_channel<datatype = unknown> {
export interface bridge_channel<data_type = unknown> {
/** the id of this channel */
id: string;
/** the data needed to bridge this channel */
data: datatype;
data: data_type;
/** the plugin used to bridge this channel */
plugin: string;
}
Expand All @@ -38,13 +39,19 @@ export interface bridge_document {
use_rawname: boolean;
}

/** the constructor for a plugin */
export interface create_plugin<T extends plugin<T['config']>> {
type: new (l: lightning, config: T['config']) => T;
config: T['config'];
/** the way to make a plugin */
export interface create_plugin<
plugin_type extends plugin<plugin_type['config']>
> {
/** the actual constructor of the plugin */
type: new (l: lightning, config: plugin_type['config']) => plugin_type;
/** the configuration options for the plugin */
config: plugin_type['config'];
/** what version the plugin supports */
support: string;
}

/** configuration options for bolt */
export interface config {
/** a list of plugins */
// deno-lint-ignore no-explicit-any
Expand Down Expand Up @@ -79,55 +86,104 @@ export interface command_arguments {
reply: (message: message<unknown>, optional?: unknown) => Promise<void>;
}

/** options when parsing a command */
export interface command_options {
/** this will be the key passed to options.opts in the execute function */
argument_name?: string;
/** whether or not the argument provided is required */
argument_required?: boolean;
/** an array of commands that show as subcommands */
subcommands?: command[];
}

/** commands are a way for users to interact with the bot */
export interface command {
/** the name of the command */
name: string;
/** an optional description */
description?: string;
options?: {
/** this will be the key passed to options.opts in the execute function */
argument_name?: string;
/** whether or not the argument provided is required */
argument_required?: boolean;
/** an array of commands that show as subcommands */
subcommands?: command[];
};
/** options when parsing the command */
options?: command_options;
/** a function that returns a message */
execute: (options: command_arguments) => Promise<string> | string;
}

export interface deleted_message<t> {
/** a representation of a message that has been deleted */
export interface deleted_message<platform_message> {
/** the message's id */
id: string;
/** the channel the message was sent in */
channel: string;
/** the platform the message was sent on */
platform: platform<t>;
platform: platform<platform_message>;
/**
* the time the message was sent/edited as a temporal instant
* @see https://tc39.es/proposal-temporal/docs/instant.html
*/
timestamp: Temporal.Instant;
}

/** the author of an embed */
export interface embed_author {
/** the name of the author */
name: string;
/** the url of the author */
url?: string;
/** the icon of the author */
icon_url?: string;
}

/** a field within an embed */
export interface embed_field {
/** the name of the field */
name: string;
/** the value of the field */
value: string;
/** whether or not the field is inline */
inline?: boolean;
}

/** the footer of an embed */
export interface embed_footer {
/** the footer text */
text: string;
/** the icon of the footer */
icon_url?: string;
}

/** media inside of an embed */
export interface embed_media {
/** the height of the media */
height?: number;
/** the url of the media */
url: string;
/** the width of the media */
width?: number;
}

/** a discord-style embed */
export interface embed {
author?: { name: string; url?: string; icon_url?: string };
/** the author of the embed */
author?: embed_author;
/** the color of the embed */
color?: number;
/** the text in an embed */
description?: string;
fields?: { name: string; value: string; inline?: boolean }[];
footer?: { text: string; icon_url?: string };
/** fields within the embed */
fields?: embed_field[];
/** a footer shown in the embed */
footer?: embed_footer;
/** an image shown in the embed */
image?: embed_media;
/** a thumbnail shown in the embed */
thumbnail?: embed_media;
/** the time (in epoch ms) shown in the embed */
timestamp?: number;
/** the title of the embed */
title?: string;
/** a site linked to by the embed */
url?: string;
/** a video inside of the embed */
video?: Omit<embed_media, 'url'> & { url?: string };
}

Expand All @@ -145,22 +201,29 @@ export interface err {
message: message<unknown>;
}

export interface message<t> extends deleted_message<t> {
/** the author of a message */
export interface message_author {
/** the nickname of the author */
username: string;
/** the author's username */
rawname: string;
/** a url pointing to the authors profile picture */
profile?: string;
/** a url pointing to the authors banner */
banner?: string;
/** the author's id on their platform */
id: string;
/** the color of an author */
color?: string;
}

/** a message recieved by a plugin */
export interface message<platform_message>
extends deleted_message<platform_message> {
/** the attachments sent with the message */
attachments?: attachment[];
author: {
/** the nickname of the author */
username: string;
/** the author's username */
rawname: string;
/** a url pointing to the authors profile picture */
profile?: string;
/** a url pointing to the authors banner */
banner?: string;
/** the author's id on their platform */
id: string;
/** the color of an author */
color?: string;
};
/** the author of the message */
author: message_author;
/** message content (can be markdown) */
content?: string;
/** discord-style embeds */
Expand All @@ -177,15 +240,16 @@ export interface migration {
from: versions;
/** the version to translate to */
to: versions;
/** translate a document from one version to another */
/** a function to translate a document */
translate: (data: [string, unknown][]) => [string, unknown][];
}

export interface platform<t> {
/** the platform that recieved a message */
export interface platform<message_type> {
/** the name of a plugin */
name: string;
/** the platforms representation of a message */
message: t;
message: message_type;
/** the webhook the message was sent with */
webhookid?: string;
}
Expand All @@ -206,8 +270,6 @@ export type plugin_events = {

/** all of the versions with migrations to/from them */
export enum versions {
/** versions after commit 7de1cf2 but below 0.5 */
FourBeta = '0.4-beta',
/** versions 0.5 through 0.6 */
Five = '0.5',
/** versions 0.7 and above*/
Expand Down
Loading

0 comments on commit 658c0e7

Please sign in to comment.