Nestor

Mon petit bot Discord
Log | Files | Refs

commit a25958e5cc27b09165a27c78a32a9f1b54fe52f0
parent 879c19af92862a09de2cb1876448b0e679fb4491
Author: Doshirae <doshirae@doshirae.fr>
Date:   Wed,  4 Apr 2018 18:07:29 +0200

Sanitized the dl feature

Diffstat:
Nestor.rb | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/Nestor.rb b/Nestor.rb @@ -121,10 +121,17 @@ end # <== bot.command(:dl) do |event, img| - if img =~ /(jpe?g|png|gif)$/ - `curl -o img.png #{img}` - event.channel.send_file File.new('img.png') - `rm img.png` + require "net/http" + if idx = uri =~ /jpe?g|png|gif$/ + ext = uri[idx..-1] + response = Net::HTTP.get_response(URI(uri)) + if response.code == 200 + open("img.#{ext}", 'w+') { |f| f.write(response.body) } + event.channel.send_file File.new("img.#{ext}") + `rm img.#{ext}` + else + "L'url n'est pas correcte" + end else "Je ne peux pas poster un fichier qui ne soit pas une image, enfin !" end