Nestor

Mon petit bot Discord
Log | Files | Refs

commit 8196cf59efb68d35c495f0faab0c030ee2626321
parent 003171bae1cb75afb7785545bc452c625ef8d498
Author: Doshirae <doshirae@lilo.org>
Date:   Wed,  8 Nov 2017 23:07:43 +0100

Added strawpoll fonctionnality

Diffstat:
Gemfile | 1+
Gemfile.lock | 6+++++-
Nestor.rb | 57+++++++++++++++++++++++++++++++++++++--------------------
dd.rb | 4++--
4 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/Gemfile b/Gemfile @@ -6,6 +6,7 @@ gem 'mechanize' gem 'nokogiri' #gem 'open-uri' gem 'configatron' +gem 'httparty' git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } diff --git a/Gemfile.lock b/Gemfile.lock @@ -16,6 +16,8 @@ GEM ffi (1.9.18) http-cookie (1.0.3) domain_name (~> 0.5) + httparty (0.15.6) + multi_xml (>= 0.5.2) mechanize (2.7.5) domain_name (~> 0.5, >= 0.5.1) http-cookie (~> 1.0) @@ -29,6 +31,7 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_portile2 (2.2.0) + multi_xml (0.6.0) net-http-digest_auth (1.4.1) net-http-persistent (2.9.4) netrc (0.11.0) @@ -58,8 +61,9 @@ PLATFORMS DEPENDENCIES configatron discordrb + httparty mechanize nokogiri BUNDLED WITH - 1.15.3 + 1.15.4 diff --git a/Nestor.rb b/Nestor.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby require 'bundler/setup' Bundler.require(:default) @@ -12,7 +12,7 @@ require_relative 'commandes.rb' # created bot, and eventually run it. bot = Discordrb::Commands::CommandBot.new token: configatron.token, client_id: 261161348124114945, prefix: '!' -# Commandes invite ==> +# invite ==> bot.command(:invite, chain_usable: false) do |event| # This simply sends the bot's invite URL, without any specific permissions, # to the channel. @@ -20,13 +20,13 @@ bot.command(:invite, chain_usable: false) do |event| end # <== -# Commande random ==> +# random ==> bot.command(:random, min_args: 0, max_args: 2, description: 'Generates a random number between 0 and 1, 0 and max or min and max.', usage: 'random [min/max] [max]') do |_event, min, max| random(min, max) end # <== -# Commande ping ==> +# ping ==> bot.command :ping do |event| # The `respond` method returns a `Message` object, which is stored in a variable `m`. The `edit` method is then called # to edit the message with the time difference between when the event was received and after the message was sent. @@ -35,10 +35,10 @@ bot.command :ping do |event| end # <== -# Commande dtc ==> +# 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 - # File.open("latestQuote.txt", 'r') do |file,latestQuote| + # File.open("latestQuote.txt", 'r') do |file,latestQuote| # latestQuote = file.gets # end # if num_quote <= latestQuote @@ -60,7 +60,7 @@ bot.command(:dtc, description: "Renvoie une quote avec un certain numéro, ou un end # <== -# Commandes pokemon ==> +# pokemon ==> bot.command(:pokelink, description: "Renvoie une page poképedia") do |event, *args| nom_pokemon = args.join('%20') event.respond "http://www.pokepedia.fr/#{nom_pokemon}" @@ -82,7 +82,7 @@ bot.command(:poke, description: "Renvoie le nom, les évolutions, et les talents # typesHTML = page.css('table tr th:contains("Types") + td a') # just got to figure out how to extract the title # types = typesHTML.filter("title") - # talents : + # talents : talents = page.css("table tr th:contains('Talents') + td a").text.split(/(?=[A-Z])/) talents[-2] += " (#{talents[-1]})" talents.pop @@ -108,7 +108,7 @@ bot.command(:poke, description: "Renvoie le nom, les évolutions, et les talents end # <== -# Commande xkcd ==> +# xkcd ==> bot.command(:xkcd, description: "Renvoie une page XKCD") do |event, *args| # "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 @@ -137,6 +137,34 @@ bot.command(:dd, min_args: 4, max_args: 4, description: "Donne l'heure de recup end # <== +# strawpoll ==> +bot.command(:strawpoll, description: "Créer un strawpoll", usage: "!strawpoll [q <question>] | choix1 | choix2 | choix3 | ...") do |event, *choices|# {{{# }}}# {{{# }}} + if choices.empty? + event.respond "Mais enfin ! Quelle curieuse idée de faire un sondage sans le moindre choix... On se croirait en Russie" + else + choices = choices.join(' ').split(' | ') + if choices[0] =~ /q\s.*/ + question = choices.shift[2..-1] + end + question ||= "Poll de #{event.user.name}" + json = HTTParty.post("https://strawpoll.me/api/v2/polls", body: {title: "#{question}", options: choices}.to_json).body + id = JSON.parse(json)["id"] + event.respond "Voici pour vous, mon cher\nhttps://strawpoll.me/#{id}" +end +end +# <== + +# eval ==> +bot.command(:eval, help_available: false) do |event, *code| + break unless event.channel.server.id == 169135745141964800 # Replace number with your ID + begin + eval code.join(' ') + rescue + "Il semblerait qu'une erreur soit apparue, très cher" + end +end +# <== + # Réponses aux messages ==> bot.message(containing: ['(╯°□°)╯︵ ┻━┻', '(ノಥ益ಥ)ノ ┻━┻', '(ノಠ益ಠ)ノ彡┻━┻']) do |event| event.respond '┬─┬ノ( º _ ºノ )' @@ -168,16 +196,6 @@ bot.message(containing: [/tg/i, /ta gueule/i]) do |event| end # <== -bot.command(:eval, help_available: false) do |event, *code| - break unless event.channel.server.id == 169135745141964800 # Replace number with your ID - - begin - eval code.join(' ') - rescue - "Il semblerait qu'une erreur soit apparue, très cher" - end -end - # command taht mention # bot.mention do |event| # # The `pm` method is used to send a private message (also called a DM or direct message) to the user who sent the @@ -186,4 +204,3 @@ end # end bot.run -# vim:foldmethod=marker:foldmarker=\=\=>,<\=\=:foldlevel=0 diff --git a/dd.rb b/dd.rb @@ -124,7 +124,7 @@ class Main mtn.min = "0#{mtn.min}".to_i if mtn.min < 10 pret = mtn + tempsSeconde pret.min = "0#{pret.min}".to_i if pret.min < 10 - + return "Il est actuellement #{mtn.hour}h#{mtn.min} et la dragodinde sera prete vers #{pret.hour}h#{pret.min}" end end @@ -146,6 +146,6 @@ if __FILE__ == $0 puts main.temps(jaugeVoulue) end -end +end # vim:foldmethod=marker:foldmarker=\=\=>,<\=\=:foldlevel=0