Nestor

Mon petit bot Discord
Log | Files | Refs

commit 9efd37802fff41f579034c7d7dd21b5727fccdc1
parent 4ac1ee3232ed36434bb4e09fb0044d0fa8fa4023
Author: Doshirae <doshirae@doshirae.fr>
Date:   Fri, 12 Jan 2018 12:57:21 +0100

Made xkcd command work

Diffstat:
Nestor.rb | 15+++++++--------
commandes.rb | 10++++++++++
doggo.png | 0
kitten.png | 0
4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Nestor.rb b/Nestor.rb @@ -113,12 +113,10 @@ end bot.command(:xkcd, description: "Renvoie une page XKCD") do |event, num| # "https://xkcd.com/#{num}" page = Nokogiri::HTML(open("https://xkcd.com/#{num}")) # TODO : Recuperer l'image sur le site, et l'upload sur le chat - if num.nil? or num.to_i == num - `curl -o xkcd.png $(curl https://xkcd.com/#{num}/ | grep "Image URL (for hotlinking/embedding):" | cut -d : -f 2-)` - event.respond "https://xkcd.com/#{num}" + url = xkcd(num) + event.respond url event.channel.send_file File.new('xkcd.png') `rm xkcd.png` - end end # <== @@ -149,16 +147,17 @@ end # doggo ==> bot.command(:doggo) do |event| - doggo() - event.channel.send_file File.new('doggo.png') + doggo() + event.channel.send_file File.new('doggo.png') `rm doggo.png` end # <== # kitten ==> bot.command(:kitten) do |event| - kitten() - event.channel.send_file File.new('kitten.png') + kitten() + event.channel.send_file File.new('kitten.png') + `rm kitten.png` end # <== diff --git a/commandes.rb b/commandes.rb @@ -51,3 +51,13 @@ def kitten file.write HTTParty.get("http://www.randomkittengenerator.com/cats/rotator.php") end end + +def xkcd(num=nil) + if num =~ /\d+/ or num.nil? # soit un nombre soit rien du tout + `curl -o xkcd.png $(curl https://xkcd.com/#{num}/ | grep "Image URL (for hotlinking/embedding):" | cut -d : -f 2-)` + + "https://xkcd.com/#{num}" + else + "Il me faut soit un entier, soit rien, très cher" + end +end diff --git a/doggo.png b/doggo.png Binary files differ. diff --git a/kitten.png b/kitten.png Binary files differ.