Skip to content

Commit

Permalink
Add: Split apt to new file
Browse files Browse the repository at this point in the history
Add: Search files
  • Loading branch information
Janez Troha committed Jan 13, 2014
1 parent cae0ff6 commit ba15ec7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 27 deletions.
1 change: 1 addition & 0 deletions bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require("./scripts/servisi")(bot)
require("./scripts/seen")(bot)
require("./scripts/set-get")(bot)
require("./scripts/vreme")(bot)
require("./scripts/apt")(bot)
require("./scripts/url")(bot)
-if process.env.T_CK?
require("./scripts/novickar")(bot)
Expand Down
39 changes: 39 additions & 0 deletions scripts/apt.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = (bot) ->

bot.regexp /^.apt (.+)/,
".apt <paket> -- Najde pakete po imenu na packages.ubuntu.com",
(match, r) ->

apt = (paket, cb)=>
url = "http://packages.ubuntu.com/search?suite=all&searchon=names&keywords=#{encodeURI(paket)}"
bot.fetchHTML url , ($)->
if $?
paketi = []
for paket in $("#psearchres h3")
arches = []
for arch in $(paket).next().find("li .resultlink")
arches.push $(arch).text().trim()
paketi.push "#{$(paket).text().replace("Package ","")} {#{arches.join(", ")}}"
cb paketi.join "\n"
else
cb "Ne najdem"

apt match[1].trim(), (answer)->
r.reply answer

bot.regexp /^.aptf (.+)/,
".aptf <ime_datoteke> -- Najde pakete po vsebini na packages.ubuntu.com",
(match, r) ->
aptf = (paket, cb)=>
url = "http://packages.ubuntu.com/search?searchon=contents&keywords=#{encodeURI(paket)}&mode=exactfilename&suite=saucy&arch=any"
bot.fetchHTML url , ($)->
if $?
paketi = []
for paket in $("td.file")
paketi.push [$(paket).text().trim(), $(paket).next().text().trim()].join(" > ")
cb paketi.join "\n"
else
cb "Ne najdem"

aptf match[1].trim(), (answer)->
r.reply answer
21 changes: 0 additions & 21 deletions scripts/servisi.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,6 @@ module.exports = (bot) ->
res = new HowDoI f, "stackexchange.com"
res.get_answer (answer)->
r.reply answer

bot.regexp /^.apt (.+)/,
".apt <paket> -- Najde pakete po imenu v packages.ubuntu.com",
(match, r) ->

apt = (paket, cb)=>
url = "http://packages.ubuntu.com/search?suite=all&searchon=names&keywords=#{encodeURI(paket)}"
bot.fetchHTML url , ($)->
if $?
paketi = $("#psearchres h3").map (i, el) ->
return $(this).text()
cisti = []
for paket in paketi
cisti.push paket.replace "Package ", ""
cb cisti.join ", "
else
console.log e
cb "Ne najdem"

apt match[1].trim(), (answer)->
r.reply answer

bot.regexp /^.pretvori ([\d,.]+) (.+) (.+)/,
".pretvori <vrednost> <valuta> <valuta> -- Pretvori med valutami (primer .pretvori 10 eur usd)",
Expand Down
21 changes: 21 additions & 0 deletions test/apt.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
chai = require 'chai'
should = chai.should()
expect = chai.expect

fat = require '../lib/fat_tests'

describe 'apt.coffee', ->
this.timeout 16000
bot = require("../scripts/apt")(new fat.BotTest())

it 'test .apt libssl-dev', (done)->
bot.test ".apt libssl-dev", (msg)->
expect(msg).to.be.a('string')
msg.should.equal 'libssl-dev {lucid, lucid-updates, precise, precise-updates, quantal, quantal-updates, raring, raring-updates, saucy, saucy-updates, trusty}'
done()

it 'test .aptf evp.h', (done)->
bot.test ".aptf evp.h", (msg)->
expect(msg).to.be.a('string')
msg.should.equal '/usr/include/hcrypto/evp.h > heimdal-dev\n/usr/include/heimdal/hcrypto/evp.h > heimdal-multidev\n/usr/include/openssl/evp.h > libssl-dev\n/usr/include/xmlsec1/xmlsec/openssl/evp.h > libxmlsec1-dev'
done()
7 changes: 1 addition & 6 deletions test/servisi.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,4 @@ describe 'servisi.coffee', ->
bot.test ".imdb The Hobbit The Desolation of Smaug", (msg)->
expect(msg).to.be.a('string')
expect(msg.length).to.be.at.least 140
done()

it 'test .stran ubuntu.si', (done)->
bot.test ".stran ubuntu.si", (msg)->
expect(msg).to.be.a('string')
done()
done()

0 comments on commit ba15ec7

Please sign in to comment.