Skip to content

Commit

Permalink
add initial version of lets
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Jan 3, 2018
0 parents commit 987c59b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gather-lets
@@ -0,0 +1,2 @@
#!/bin/sh
grep -v 'goodideas' "$1" | awk -F'\t' $'$3 ~ /^let\'?s/ {print $3}'
2 changes: 2 additions & 0 deletions gather-whatif
@@ -0,0 +1,2 @@
#!/bin/sh
grep -v goodideas "$1" | awk -F'\t' $'$3 ~ /^what if/ {print $3}' | sort | uniq
2 changes: 2 additions & 0 deletions 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
52 changes: 52 additions & 0 deletions 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)
})
9 changes: 9 additions & 0 deletions package.json
@@ -0,0 +1,9 @@
{
"name": "lets",
"version": "1.0.0",
"main": "lets.js",
"bin": {
"lets": "lets.js"
},
"license": "MIT"
}

0 comments on commit 987c59b

Please sign in to comment.