Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created February 15, 2018 08:27

Revisions

  1. WebReflection created this gist Feb 15, 2018.
    26 changes: 26 additions & 0 deletions irc.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/usr/bin/env node

    require('fs').readFile(process.argv[2], (err, data) => {
    if (err) return;
    const content = data.toString().trim();
    const re = /^\[(.+?)\]\s+<(.+?)>\s(.*)$/gm;
    const chat = [];
    let current = {};
    while (match = re.exec(content)) {
    if (match[2] !== current.name) {
    chat.push(current = {
    time: match[1],
    name: match[2],
    content: match[3]
    });
    } else {
    current.content += '\n\n' + match[3];
    }
    }
    console.log(chat.map(user =>
    `<sub><sup>[${user.time}]</sup></sub> **${user.name}**
    ${user.content.replace(/```[\S\s]+?```/g, $0 => $0.replace(/\n\n/g, '\n'))}
    - - -`
    ).join('\n\n'));
    });