Nestor

Mon petit bot Discord
Log | Files | Refs

commit 4ac1ee3232ed36434bb4e09fb0044d0fa8fa4023
parent add3fed4f60e405e226ea0d84907b4f01f596c3b
Author: Doshirae <doshirae@doshirae.fr>
Date:   Thu, 11 Jan 2018 23:14:28 +0100

Fixed conflict

Diffstat:
Nestor.rb | 13++++++++++---
Nestor_telegram.rb | 82++++++++++++++++++++++++++++++++++++++++---------------------------------------
doggo.png | 0
kitten.png | 0
4 files changed, 52 insertions(+), 43 deletions(-)

diff --git a/Nestor.rb b/Nestor.rb @@ -148,13 +148,20 @@ 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| - doggo() - event.channel.send_file File.new('doggo.png') +bot.command(:doggo) do |event| + doggo() + event.channel.send_file File.new('doggo.png') `rm doggo.png` end # <== +# kitten ==> +bot.command(:kitten) do |event| + kitten() + event.channel.send_file File.new('kitten.png') +end +# <== + # exit ==> bot.command(:exit, help_available: false) do |event| # This is a check that only allows a user with a specific ID to execute this command. Otherwise, everyone would be diff --git a/Nestor_telegram.rb b/Nestor_telegram.rb @@ -1,55 +1,57 @@ require 'telegram/bot' require_relative "commandes.rb" -require_relative "config.rb" require "configatron" +require_relative "config.rb" -token = configatron.telegram +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 + 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')) + else + bot.api.send_message(chat_id: message.chat.id, text: "Commande inconnue") + 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 + 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 + 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/doggo.png b/doggo.png Binary files differ. diff --git a/kitten.png b/kitten.png Binary files differ.