Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tmijs/irc-parser
https://github.com/tmijs/irc-parser
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tmijs/irc-parser
- Owner: tmijs
- License: mit
- Created: 2024-08-01T06:53:22.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-05T10:05:02.000Z (2 months ago)
- Last Synced: 2024-10-05T17:16:12.561Z (about 1 month ago)
- Language: JavaScript
- Size: 41 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @tmi.js/irc-parser
IRC parsing package for the `@tmi.js/chat` library
# Install
```bash
npm i @tmi.js/irc-parser
```# Usage
```ts
import {
parse, parseTagsFromString, parseTag, parsePrefix,
format, formatTags, formatChannel, formatPrefix,
unescapeIrc, escapeIrc
} from '@tmi.js/irc-parser';
import type {
IrcMessage, ChannelString,
ParsedTags, ParsedTagData, ParseTagCallbackFn,
FormatMessage
} from '@tmi.js/irc-parser';function handleMessage(ircString: string) {
const ircMessage = parse(ircString, (key, value, params) => {
switch(key) {
case 'aNumberKey': return [ key, parseInt(value, 10) ];
case 'aBooleanKey': return [ key, value === '1' || value === 'true' ];
}
return [ key, value ];
});
const { channel, command, params, prefix, tags } = ircMessage;
switch(command) {
case 'PING':
ws.send(format({ command: 'PONG' }));
break;
case 'PRIVMSG':
console.log(`[${channel}] <${prefix.user}> ${params[0]}`);
if(params[0].startsWith('!help')) {
ws.send(format({ command: 'PRIVMSG', channel, params: [ helpString ] }));
}
break;
}
}
```