Nestor

Mon petit bot Discord
Log | Files | Refs

commit 394b90fe3928f0c01b670d5b9d600dc690a81103
parent 237d67dd0264c67826132aded3194b1ee9ee5ab1
Author: Doshirae <romainchaix@protonmail.com>
Date:   Sun,  8 Jan 2017 13:37:00 +0100

Working

Diffstat:
.gitignore | 1+
nestor.rb | 10+++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1,2 @@ config.rb +latestQuote.txt diff --git a/nestor.rb b/nestor.rb @@ -46,7 +46,14 @@ end # Commande dtc {{{ bot.command(:dtc, description: "Renvoie une quote avec un certain numéro, ou une au hasard", usage: 'dtc [numéro_quote]') do |event, num_quote| if num_quote - "http://danstonchat.com/#{num_quote}.html" + # File.open("latestQuote.txt", 'r') do |file,latestQuote| + # latestQuote = file.gets + # end + # if num_quote <= latestQuote + "http://danstonchat.com/#{num_quote}.html" + # else + # "La quote existe pas fdp" + # end else mechanize = Mechanize.new page = mechanize.get('http://danstonchat.com/latest.html') @@ -54,6 +61,7 @@ bot.command(:dtc, description: "Renvoie une quote avec un certain numéro, ou un latestQuote = link.click url = latestQuote.uri.to_s.split('') # transform the url into a string, and then into an array latestQuoteNumber = url.grep(/\d+/).join.to_i # grep digits into that array (\d means [0-9]), join it into a string, and make that an integer + File.open("latestQuote.txt", 'w') {|file| file.write(latestQuoteNumber) } random = rand(1..latestQuoteNumber) "http://danstonchat.com/#{random}.html" end