irclib/src/bot.ts

31 lines
967 B
TypeScript
Raw Permalink Normal View History

2022-09-23 17:38:41 +00:00
import { IRCSocketConnector } from './connector/net.connector';
import { IRCConnection } from './irc';
2022-09-23 17:38:41 +00:00
import { IIRCOptions } from './types/irc.interfaces';
2022-09-24 07:49:28 +00:00
import { formatstr } from './utility/formatstr';
2022-09-23 17:38:41 +00:00
export class IRCBot extends IRCConnection {
2022-09-23 17:38:41 +00:00
constructor(options: IIRCOptions) {
super(options, IRCSocketConnector);
}
/**
* Send a message to the server (`PRIVMSG`)
* @param to Recipient, a channel or a nick
* @param message Message to send
* @param args Additional arguments for message
*/
2022-09-23 17:38:41 +00:00
send(to: string, message: string, ...args: any[]) {
2022-09-24 07:49:28 +00:00
this.write('PRIVMSG %s :%s', to, formatstr(message, ...args));
2022-09-23 17:38:41 +00:00
}
/**
* Send a message to the server (`NOTICE`)
* @param to Recipient, a channel or a nick
* @param message Message to send
* @param args Additional arguments for message
*/
2022-09-23 17:38:41 +00:00
notice(to: string, message: string, ...args: any[]) {
2022-09-24 07:49:28 +00:00
this.write('NOTICE %s :%s', to, formatstr(message, ...args));
2022-09-23 17:38:41 +00:00
}
}