diff --git a/gather-lets b/gather-lets new file mode 100755 index 0000000..34eef7f --- /dev/null +++ b/gather-lets @@ -0,0 +1,2 @@ +#!/bin/sh +grep -v 'goodideas' "$1" | awk -F'\t' $'$3 ~ /^let\'?s/ {print $3}' diff --git a/gather-whatif b/gather-whatif new file mode 100755 index 0000000..94b716d --- /dev/null +++ b/gather-whatif @@ -0,0 +1,2 @@ +#!/bin/sh +grep -v goodideas "$1" | awk -F'\t' $'$3 ~ /^what if/ {print $3}' | sort | uniq diff --git a/gather-wonder b/gather-wonder new file mode 100755 index 0000000..5800608 --- /dev/null +++ b/gather-wonder @@ -0,0 +1,2 @@ +#!/bin/sh +grep -v goodideas "$1" | awk -F'\t' $'$3 ~ /^(i|do you ever|do you|but i) wonder/ {print $3}' | sort | uniq diff --git a/lets.js b/lets.js new file mode 100755 index 0000000..e9e9e33 --- /dev/null +++ b/lets.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node +const {promisify} = require('util') +const fs = require('fs') +const irc = require('irc') + +const readFile = promisify(fs.readFile) + +const getLib = lib => readFile(`/usr/chee/lib/${lib}`) + +const whatifs = getLib('whatif') +const lets = getLib('lets') +const wonders = getLib('wonder') + +const getLine = async getBuffer => { + const buffer = await getBuffer + const lines = buffer.toString().split(/\n/) + return lines[Math.floor(Math.random() * lines.length)] +} + +const letLine = () => getLine(lets) +const whatifLine = () => getLine(whatifs) +const wonderLine = () => getLine(wonders) + +const channel = '#chee-fanclub' +const client = new irc.Client('chat.freenode.net', 'goodideas', { + channels: [channel], + userName: 'goodideas', + realName: 'goodideas' +}) + +client.addListener('message', (from, to, message) => { + let line + + switch(message.toLowerCase()) { + case 'let\'s': + case 'lets': + line = await letLine() + break + case 'what if': + case 'whatif': + line = await whatifLine() + break + case 'wonder': + case 'i wonder': + line = await wonderLine() + break + default: + line = null + } + + line && client.say(channel, line) +}) diff --git a/package.json b/package.json new file mode 100644 index 0000000..cd65f89 --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "lets", + "version": "1.0.0", + "main": "lets.js", + "bin": { + "lets": "lets.js" + }, + "license": "MIT" +}