UNPKG

corde

Version:

A simple library for Discord bot tests

125 lines (124 loc) 3.83 kB
import { Channel, Client, Collection, Guild, GuildChannel, Message, MessageEmbed, Role, TextChannel, } from "discord.js"; import { ICordeBot, IMessageIdentifier, IRoleIdentifier, IVoiceChannelState, Primitive, } from "../types"; import { Events } from "./events"; /** * Encapsulation of Discord Client with all specific * functions for corde test. */ export declare class CordeBot implements ICordeBot { readonly events: Events; private readonly _prefix; private readonly _guildId; private readonly _channelId; private readonly _testBotId; private readonly _client; private _voiceConnection?; private textChannel; private _isReady; /** * 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, testBotId: string, client: Client, ); get client(): Client; get guild(): Guild; get roleManager(): import("discord.js").RoleManager; get channel(): TextChannel; get testBotId(): string; get voiceConnection(): IVoiceChannelState | undefined; get id(): string | undefined; /** * 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>; fetchChannel(id: string): Promise<Channel | undefined>; fetchGuild(id: string): Promise<Guild | undefined>; /** * Destroy client connection. */ logout(): void; /** * Sends a pure message without prefix it. * @param message Data to be send to channel */ sendMessage(message: Primitive | 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: Primitive, channelId?: string): Promise<Message>; private findChannelById; /** * Checks if corde bot is connected */ isLoggedIn(): boolean; findMessage(filter: (message: Message) => boolean): Promise<Message | undefined>; findMessage(data: IMessageIdentifier): Promise<Message | undefined>; fetchRole(id: string): Promise<Role | null>; fetchRoles(): Promise<import("discord.js").RoleManager>; hasRole(roleIdentifier: IRoleIdentifier): Promise<boolean>; findRole(roleIdentifier: IRoleIdentifier): Promise<Role | undefined>; getRoles(): Collection<string, 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 loadClientEvents; private buildLoginErrorMessage; private validateMessageAndChannel; findGuild(guildId: string): Guild; findChannel(channelId: string): GuildChannel | undefined; findChannel(guild: Guild, channelId: string): GuildChannel | undefined; joinVoiceChannel(channelId: string): Promise<IVoiceChannelState>; isInVoiceChannel(): boolean; isStreamingInVoiceChannel(): boolean; stopStream(): void; leaveVoiceChannel(): void; private convertToTextChannel; }