Finally working version
This commit is contained in:
parent
65108cffea
commit
e19085bf17
@ -16,6 +16,30 @@
|
|||||||
net = require 'net'
|
net = require 'net'
|
||||||
|
|
||||||
module.exports = (robot) ->
|
module.exports = (robot) ->
|
||||||
|
match_all = (regex, str) ->
|
||||||
|
matches = []
|
||||||
|
str.replace regex, ->
|
||||||
|
arr = [].slice.call arguments, 0
|
||||||
|
extras = arr.splice -2
|
||||||
|
arr.index = extras[0]
|
||||||
|
arr.input = extras[1]
|
||||||
|
matches.push arr
|
||||||
|
matches
|
||||||
|
|
||||||
|
concat = (list) -> list.reduce (x, y) -> x.concat y
|
||||||
|
|
||||||
|
escape = (str) ->
|
||||||
|
str.replace(/\d|\?|#/g, '') # not supported
|
||||||
|
.replace( /\ /g, '%20') # spaces
|
||||||
|
|
||||||
|
doge_url = (text) ->
|
||||||
|
"http://dogr.io/#{escape text}.png?split=false"
|
||||||
|
|
||||||
|
shiba = (res, words) ->
|
||||||
|
word = words.filter (x) -> x.length > 4
|
||||||
|
prefix = [ 'much', 'such', 'many', 'very']
|
||||||
|
(res.random prefix) + ' ' + (res.random words)
|
||||||
|
|
||||||
run_command = (command, callback) ->
|
run_command = (command, callback) ->
|
||||||
client = net.connect robot.adapter.port, robot.adapter.host, ->
|
client = net.connect robot.adapter.port, robot.adapter.host, ->
|
||||||
client.write command+'\n'
|
client.write command+'\n'
|
||||||
@ -26,17 +50,17 @@ module.exports = (robot) ->
|
|||||||
client.end()
|
client.end()
|
||||||
|
|
||||||
get_history = (chat, size, callback) ->
|
get_history = (chat, size, callback) ->
|
||||||
regex = /^(?:\d+ )?\[(.+)\] (.+) [»«><]+ (.+)/
|
regex = /\[(.+)\] (.+) [>«»]+ ((?:(?!\n(\[|\d))[\s\S])+)/g
|
||||||
parse_line = (x) ->
|
parse_line = (x) ->
|
||||||
date: x[1]
|
date: x[1]
|
||||||
peer: x[2].replace chat + ' ', ''
|
peer: x[2].replace chat + ' ', ''
|
||||||
text: x[3].trim()
|
text: x[3].trim().replace '\n', ' '
|
||||||
run_command "history #{chat} #{size}", (lines) ->
|
run_command "history #{chat} #{size}", (lines) ->
|
||||||
callback (parse_line i.match regex for i in lines)
|
callback ((match_all regex, lines.join '\n').map parse_line)
|
||||||
|
|
||||||
robot.respond /doge(?: (\d+))?/, (res) ->
|
robot.respond /doge(?: (\d+))?/, (res) ->
|
||||||
n = res.match[1] || 10
|
n = res.match[1] || 10
|
||||||
get_history res.message.room, n, (history) ->
|
get_history res.message.room, n, (history) ->
|
||||||
words = [].concat (message.text.split() for message in history)
|
words = concat (message.text.split ' ' for message in history)
|
||||||
sample = res.random words for _ in [0..5]
|
sample = (res.random ['wow', shiba res, words] for _ in [0..8])
|
||||||
#do doge meme with sample
|
res.send (doge_url sample.join '/')
|
Loading…
Reference in New Issue
Block a user