Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,27 @@ | ||
module.exports = (bot) -> | ||
|
||
is_url = /(https?[\w:\/\.;&\?_\-\#=]+)/g; | ||
|
||
resolve = (url, cb)-> | ||
if is_url.test url | ||
url = url.match(is_url)[0] | ||
bot.fetchHTML url, ($)-> | ||
if $ | ||
stack = [] | ||
stack.push $("title").eq(0).text().replace(/\s\s+/g, "").replace(/ /g,"").replace(/\n/g, "") | ||
opis = $("meta[name=description]").attr("content") | ||
if opis | ||
stack.push opis.replace(/\s\s+/g, "").replace(/ /g,"").replace(/\n/g, "") | ||
cb stack.join("\n") | ||
bot.fetchHTML url, ($)-> | ||
if $ | ||
stack = [] | ||
stack.push $("title").eq(0).text().replace(/\s\s+/g, "").replace(/ /g,"").replace(/\n/g, "") | ||
opis = $("meta[name=description]").attr("content") | ||
if opis | ||
stack.push opis.replace(/\s\s+/g, "").replace(/ /g,"").replace(/\n/g, "") | ||
cb stack.join("\n") | ||
|
||
bot.on 'user:talk', (r) -> | ||
if is_url.test r.text | ||
is_url = /(?:.+)?(https?:\/\/[\S]+)(?:.+)?/ig; | ||
url = is_url.exec(r.text) | ||
if url | ||
msg = "#{r.text} @#{moment().toString()}" | ||
redis.rpush("irc:zgodovina:#{r.nick}", msg) | ||
resolve r.text, r.reply | ||
resolve url[1], r.reply | ||
|
||
bot.regexp /^\.url (.+)/i, | ||
".url <nick> Prikaži urlje, ki jih je objavil <nick>" | ||
(match, r) -> | ||
nick = match[1] | ||
redis.lrange("irc:zgodovina:#{nick}", -5, 5).then (data)-> | ||
for msg in data | ||
r.reply msg | ||
|
||
bot.regexp /^\.nalozi (.+)/i, | ||
".nalozi <url> Prikaži opis in naslov za <url>" | ||
(match, r) -> | ||
key = match[1] | ||
resolve key, r.reply | ||
r.reply msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters