@averagehelper/corde
Version:
A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)
110 lines (109 loc) • 4.29 kB
TypeScript
import { Client, Collection, Guild, Message, MessageEmbed, MessageReaction } from "discord.js";
import { MessageData, RoleData } from "../types";
import { Events } from "./events";
/**
* Encapsulation of Discord Client with all specific
* functions for corde test.
*/
export declare class CordeBot extends Events {
/**
* Observes if corde bot is **ready**.
* This is invoked after onReady in Discord.Client.
* Used to initialize some data for CordeBot.
* **Do not use onReady declared in Events if the intention is to ensure that
* cordebot is ready for usage**
*/
get onStart(): import("rxjs").Observable<boolean>;
private readonly _onStart;
private readonly _prefix;
private readonly _guildId;
private readonly _channelId;
private readonly _waitTimeOut;
private readonly _testBotId;
private textChannel;
private _reactionsObserved;
/**
* Starts new instance of Discord client with its events.
*
* @param prefix Corde bot prefix.
* @param guildId Guild id where corde bot is located in.
* @param channelId Channel id where corde bot is located in.
* @param waitTimeOut Timeout for message wait.
* @param testBotId id of testing bot.
*/
constructor(prefix: string, guildId: string, channelId: string, waitTimeOut: number, testBotId: string, client: Client);
private get guild();
/**
* Authenticate Corde bot to the installed bot in Discord server.
*
* @param token Corde bot token
*
* @returns Promise resolve for success connection, or a promise
* rejection with a formatted message if there was found a error in
* connection attempt.
*/
login(token: string): Promise<string>;
/**
* Destroy client connection.
*/
logout(): void;
/**
* Sends a pure message without prefix it.
* @param message Data to be send to channel
*/
sendMessage(message: string | number | MessageEmbed): Promise<Message>;
/**
* Send a message to a channel defined in configs.
*
* @see Runtime
*
* @param message Message without prefix that will be sent to defined server's channel
* @description The message is concatenated with the stored **prefix** and is sent to the channel.
*
* @return Promise rejection if a testing bot does not send any message in the timeout value setted,
* or a resolve for the promise with the message returned by the testing bot.
*/
sendTextMessage(message: string): Promise<Message>;
/**
* Observes for a message send by the testing bot after corde bot
* send it's message.
*/
awaitMessagesFromTestingBot(): Promise<Message>;
/**
* Observes for reactions in a message
*/
waitForAddedReactions(message: Message, totalReactions?: number): Promise<Collection<string, MessageReaction>>;
waitForAddedReactions(message: Message, reactions?: string[]): Promise<Collection<string, MessageReaction>>;
private createWaitForAdedReactionsFilter;
private defineMaxReactionsToWaitForAddedReactions;
waitForRemovedReactions(message: Message, take: number): Promise<MessageReaction[]>;
/**
* Checks if corde bot is connected
*/
isLoggedIn(): boolean;
findMessage(filter: (message: Message) => boolean): Promise<Message>;
findMessage(data: MessageData): Promise<Message>;
findPinnedMessage(messageData: MessageData): Promise<Message>;
fetchRole(id: string): Promise<import("discord.js").Role>;
hasRole(roleData: RoleData): Promise<boolean>;
findRole(roleData: RoleData): Promise<import("discord.js").Role>;
getRoles(): Collection<string, import("discord.js").Role>;
/**
* Search for messages based in a filter query.
*/
private _findMessage;
/**
* Get a channel based in the id stored in configs.
*
* @see Runtime
*/
private loadChannel;
private responseAuthorIsTestingBot;
private createWatchResponseConfigs;
private loadClientEvents;
private buildLoginErrorMessage;
private validateMessageAndChannel;
findGuild(guildId: string): Guild;
findChannel(guild: Guild, channelId: string): import("discord.js").GuildChannel;
private convertToTextChannel;
}