107 lines
2.4 KiB
TypeScript
107 lines
2.4 KiB
TypeScript
import { Protocol } from './protocol';
|
|
|
|
export enum EMessageType {
|
|
message = 'message',
|
|
roomJoin = 'room_join',
|
|
roomLeave = 'room_leave',
|
|
roomKick = 'room_kick',
|
|
nameChange = 'name_change',
|
|
edit = 'edit',
|
|
protocolStart = 'protocol_start',
|
|
protocolExit = 'protocol_exit',
|
|
custom = 'custom'
|
|
}
|
|
|
|
/**
|
|
* Message target specification. ID and name are mandatory,
|
|
* and they could be the same, depending on the protocol.
|
|
*/
|
|
export interface IMessageTarget {
|
|
id: string;
|
|
name: string;
|
|
server?: string;
|
|
}
|
|
|
|
/**
|
|
* Message format
|
|
*/
|
|
export interface IMessage {
|
|
/**
|
|
* Uniquely identify this message
|
|
*/
|
|
id?: any;
|
|
/**
|
|
* Type of the message. See EMessageType
|
|
*/
|
|
type: EMessageType;
|
|
/**
|
|
* Data included in the message. Could be an object or a string.
|
|
* Use `text` to get text value.
|
|
*/
|
|
data: any;
|
|
/**
|
|
* Text value of the message.
|
|
*/
|
|
text: string;
|
|
/**
|
|
* Source protocol of the message.
|
|
*/
|
|
source: Protocol;
|
|
/**
|
|
* If the sender has not registered themselves.
|
|
* Applicable to, for example, NickServ of IRC.
|
|
*/
|
|
guest?: boolean;
|
|
/**
|
|
* The room where the message was sent in.
|
|
*/
|
|
target?: IMessageTarget;
|
|
/**
|
|
* Information about the sender.
|
|
*/
|
|
sender?: IMessageTarget;
|
|
/**
|
|
* Full ID of the sender (`plugin/protocol/id`).
|
|
*/
|
|
fullSenderID?: string;
|
|
/**
|
|
* Full ID of the room (`plugin/protocol/(s:server)/id`).
|
|
*/
|
|
fullRoomID?: string;
|
|
/**
|
|
* The time the message was sent.
|
|
*/
|
|
time: Date;
|
|
/**
|
|
* True if the message is a direct message to the bot.
|
|
*/
|
|
direct?: boolean;
|
|
/**
|
|
* True when resolve has been called at least once.
|
|
*/
|
|
resolved: boolean;
|
|
/**
|
|
* Bot's response to this message. Will be passed to the protocol,
|
|
* which usually sends it through the formatter and then to the service
|
|
* it is connected to.
|
|
* @param args Message data
|
|
*/
|
|
resolve(...args: any[]): void;
|
|
/**
|
|
* Bot's error response to this message. Will be passed to the protocol,
|
|
* which usually sends `error.message` directly to the target of the message
|
|
* @param error Error
|
|
*/
|
|
reject(error: Error): void;
|
|
/**
|
|
* Insert a mention into the response
|
|
* @param target UserTarget to mention (i.e. `msg.sender`)
|
|
*/
|
|
mention(target: IMessageTarget): string;
|
|
/**
|
|
* Same as `resolve`, but replies (on supported protocols) instead.
|
|
* @param args Message data
|
|
*/
|
|
reply?(...args: any[]): void;
|
|
}
|