Nestor

Mon petit bot Discord
Log | Files | Refs

commit 008f0fb54a6e41743b4ebee6a894177e0eec7a98
parent 12c65428f4dc3532df67890bf6f9a3d0ed69854e
Author: Doshirae <doshirae@lilo.org>
Date:   Sat,  2 Dec 2017 12:28:05 +0100

Moved strawpoll command to commandes.rb

Diffstat:
commandes.rb | 46++++++++++++++++++++++++++++++++++------------
1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/commandes.rb b/commandes.rb @@ -1,19 +1,41 @@ require_relative "insultotron.rb" +require "httparty" + def random(*args) - if args[1] - max = args[1].to_i - min = args[0].to_i - elsif args[0] - max = args[0].to_i - min = 0 - else - max = 1.to_f - min = 0.to_f - end - rand(min..max) + if args[1] + max = args[1].to_i + min = args[0].to_i + elsif args[0] + max = args[0].to_i + min = 0 + else + max = 1.to_f + min = 0.to_f + end + rand(min..max) end def insulte(mode = nil) - "#{Insulte.new(mode)}" + "#{Insulte.new(mode)}" +end + + +def strawpoll(name, *choices) + if choices.empty? + return "Mais enfin ! Quelle curieuse idée de faire un sondage sans le moindre choix... On se croirait en Russie" + else + choices = choices.join(' ').split(' | ') + multi = false + if choices[0] =~ /q\s.*/ + question = choices.shift[2..-1] + elsif choices[0] =~ /qm\s.*/ + question = choices.shift[2..-1] + multi = true + end + question ||= "Poll de #{name}" + json = HTTParty.post("https://strawpoll.me/api/v2/polls", body: {title: "#{question}", options: choices, multi: multi}.to_json).body + id = JSON.parse(json)["id"] + return "Voici pour vous, mon cher\nhttps://strawpoll.me/#{id}" + end end