26 lines
783 B
TypeScript
26 lines
783 B
TypeScript
import { IIRCOptions } from '../types/irc.interfaces';
|
|
|
|
/**
|
|
* Estimate the length of the message the actual server will send to clients,
|
|
* you can use this information to truncate/split your messages.
|
|
*
|
|
* `:nickname!username@hostname command args :trailing\r\n`
|
|
* @param options IRC options (nick, hostname, username)
|
|
* @param command Command to be sent
|
|
* @param args Arguments for the command
|
|
* @returns Predictive length of the message without the trailing
|
|
*/
|
|
export const estimateMessagePrefixLength = (
|
|
options: IIRCOptions,
|
|
command: string,
|
|
args: string[],
|
|
) => {
|
|
const header =
|
|
options.nick.length +
|
|
(options.hostname || '').length +
|
|
(options.username || '').length +
|
|
4 +
|
|
2;
|
|
return command.length + args.join(' ').length + 3 + header;
|
|
};
|