Nestor

Mon petit bot Discord
Log | Files | Refs

commit 64c97a5a3e3670d4a85c0de9966f5a5c796d8b6b
parent 7865e10903e0dbdf27e5268f03f5006e47066409
Author: Doshirae <doshirae@doshirae.fr>
Date:   Fri, 22 Dec 2017 17:55:18 +0100

.

Diffstat:
Nestor.rb | 8+++-----
Nestor_telegram.rb | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
commandes.rb | 6++++++
doggo.png | 0
kitten.png | 0
5 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/Nestor.rb b/Nestor.rb @@ -146,10 +146,8 @@ end # doggo ==> bot.command(:doggo) do |event| # , description: "Créer un strawpoll", usage: "!strawpoll [q[m] <question>] | choix1 | choix2 | choix3 | ...\nq <question> → la question devient <question> (aucune question si le champ n'est pas là)\nqm <question> → question devient <question> et active le choix multiple des réponses") do |event, *choices| - File.open("doggo.png", 'w') do |file| - file.write HTTParty.get("https://www.randomdoggiegenerator.com/randomdoggie.php") - end - event.channel.send_file "doggo.png" + doggo() + event.channel.send_file File.new('doggo.png') end # <== @@ -159,7 +157,7 @@ bot.command(:exit, help_available: false) do |event| # able to shut your bot down whenever they wanted. break unless event.user.id == $DOSHI # Replace number with your ID - bot.send_message(event.channel.id, 'Bot is shutting down') + bot.send_message(event.channel.id, 'À bientôt j\'espère') exit end # <== diff --git a/Nestor_telegram.rb b/Nestor_telegram.rb @@ -0,0 +1,55 @@ +require 'telegram/bot' +require_relative "commandes.rb" +require_relative "config.rb" +require "configatron" + +token = configatron.telegram +Telegram::Bot::Client.run(token) do |bot| + bot.listen do |message| + case message.text + when "/doggo" + doggo() + bot.api.send_photo(chat_id: message.chat.id, photo: Faraday::UploadIO.new('doggo.png', 'image/png')) + when "/kitten" + kitten() + bot.api.send_photo(chat_id: message.chat.id, photo: Faraday::UploadIO.new('kitten.png', 'image/png')) + end + end +end + +=begin Exemples +# Custom keyboard +bot.listen do |message| + case message.text + when '/start' + question = 'London is a capital of which country?' + # See more: https://core.telegram.org/bots/api#replykeyboardmarkup + answers = + Telegram::Bot::Types::ReplyKeyboardMarkup + .new(keyboard: [%w(A B), %w(C D)], one_time_keyboard: true) + bot.api.send_message(chat_id: message.chat.id, text: question, reply_markup: answers) + when '/stop' + # See more: https://core.telegram.org/bots/api#replykeyboardremove + kb = Telegram::Bot::Types::ReplyKeyboardRemove.new(remove_keyboard: true) + bot.api.send_message(chat_id: message.chat.id, text: 'Sorry to see you go :(', reply_markup: kb) + end +end +# Inline keyboards +bot.listen do |message| + case message + when Telegram::Bot::Types::CallbackQuery + # Here you can handle your callbacks from inline buttons + if message.data == 'touch' + bot.api.send_message(chat_id: message.from.id, text: "Don't touch me!") + end + when Telegram::Bot::Types::Message + kb = [ + Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Go to Google', url: 'https://google.com'), + Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Touch me', callback_data: 'touch'), + Telegram::Bot::Types::InlineKeyboardButton.new(text: 'Switch to inline', switch_inline_query: 'some text') + ] + markup = Telegram::Bot::Types::InlineKeyboardMarkup.new(inline_keyboard: kb) + bot.api.send_message(chat_id: message.chat.id, text: 'Make a choice', reply_markup: markup) + end +end +=end diff --git a/commandes.rb b/commandes.rb @@ -45,3 +45,9 @@ def doggo file.write HTTParty.get("https://www.randomdoggiegenerator.com/randomdoggie.php") end end + +def kitten + File.open("kitten.png", 'w') do |file| + file.write HTTParty.get("http://www.randomkittengenerator.com/cats/rotator.php") + end +end diff --git a/doggo.png b/doggo.png Binary files differ. diff --git a/kitten.png b/kitten.png Binary files differ.