linkup-bot-lib
Version:
134 lines (133 loc) • 4.45 kB
TypeScript
/// <reference path="../types/hyperswarm.d.ts" />
/// <reference path="../types/corestore.d.ts" />
/// <reference path="../types/hyperdrive.d.ts" />
import Hyperswarm, { PeerDiscovery } from 'hyperswarm';
import { Message } from "./message/Message";
import Corestore from 'corestore';
import Hyperdrive from 'hyperdrive';
import { IconMessage } from "./message/IconMessage";
import { TypedEventEmitter } from "./util/TypedEventEmitter";
import { LinkUpEvents } from "./LinkUpEvents";
import { Command } from "./Command";
/**
* This class is the core component of the bot system. It handles connections to the Hyperswarm network, manages message sending and receiving, and emits events for various actions.
*/
export declare class Client extends TypedEventEmitter<LinkUpEvents> {
botName: string;
servePort: number | null;
storagePath: string | undefined;
swarm: Hyperswarm | undefined;
drive: Hyperdrive | undefined;
store: Corestore | undefined;
joinedRooms: Set<string> | undefined;
currentTopic: string | null;
botAvatar: string;
iconMessage: IconMessage | undefined;
discovery: PeerDiscovery | undefined;
commands: Command[];
private commandPrefix;
/**
* @param botName The name of the bot.
* @param commandPrefix Prefix for bot commands
* @since 1.0
* @constructor
* @author snxraven
*/
constructor(botName: string, commandPrefix: string);
/**
* @description Initializes the ServeDrive for serving files and audio.
* @since 1.0
* @author snxraven
*/
initializeServeDrive(): Promise<void>;
/**
* @description Returns a random port number.
* @since 1.0
* @author snxraven
* @return Random port number.
*/
getRandomPort(): number;
/**
* @description Fetches and sets the bot's avatar from a local file.
* @param filePath path to the local avatar file.
* @since 1.0
* @author snxraven
*/
fetchAvatar(filePath: string): Promise<void>;
/**
* @description Sets up the Hyperswarm network and connection handlers.
* @since 1.0
* @author snxraven
*/
setupSwarm(): void;
/**
* @description Joins a specified chat room.
* @since 1.0
* @author snxraven
* @param chatRoomID Chat room topic string
*/
joinChatRoom(chatRoomID: string): void;
/**
* @description Sends a text message.
* @since 1.0
* @author MiTask
* @param message Text message to send to the bot's current chat room.
*/
sendTextMessage(message: string): void;
/**
* @description Sends a file message.
* @since 1.0
* @author snxraven
* @param filePath Path to the file to send.
* @param fileType Type of the file to send.
*/
sendFileMessage(filePath: string, fileType: string): Promise<void>;
/**
* @description Sends an audio message.
* @since 1.0
* @author snxraven
* @param filePath Path to the audio file to send.
* @param audioType Type of the audio file to send.
*/
sendAudioMessage(filePath: string, audioType: string): Promise<void>;
/**
* @description Sends a generic message.
* @since 1.0
* @author MiTask
* @param message Message class (TextMessage, FileMessage or AudioMessage)
*/
sendMessage(message: Message): void;
/**
* @description Disconnects the bot and shuts down the Hyperswarm network.
* @since 1.0
* @author snxraven
*/
destroy(): Promise<void>;
/**
* @description Adds command to the bot Commands array
* @param command Command to register
* @since 1.2
* @author MiTask
*/
registerCommand(command: Command): void;
/**
* @description Removes command from the bot Commands array
* @param command Command to unregister
* @since 1.2
* @author MiTask
*/
unregisterCommand(command: Command): void;
/**
* @description Registers all classes that extend Command class on specified path
* @param path Path to search for commands (Must be full path. For example using __dirname)
* @since 1.2
* @author MiTask
*/
registerCommands(path: String): Promise<void>;
}
export type Constructor<T extends {} = {}> = new (...args: any[]) => T;
export type MaybeCommand = Constructor<Command> | {
default: Constructor<Command>;
} | {
[k: string]: Constructor<Command>;
};