Created
May 17, 2016 09:27
-
-
Save mimikadze/cea4bd19db4c79c063f3911cc2593b37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rubygems" | |
require "bundler/setup" | |
ROOT = Pathname.new(::File.expand_path('../', __FILE__)) | |
ENVIRONMENT = ENV.fetch('STAGE', 'development') | |
Bundler.require :default, ENVIRONMENT | |
Dotenv.load ROOT.join(".env") | |
TOKEN = ENV.fetch("TOKEN") | |
def online? | |
`ping -c 1 spalmalo.dev.kg`[/(\d)(\spackets)?\sreceived/,1] == "1" | |
end | |
def matching_requiest? text | |
text =~ /((дали|есть)\s.*(интернет|свет|электричество))|(интернет|свет|электричество)\s*(дали|есть).*\?/i | |
end | |
Telegram::Bot::Client.run(TOKEN) do |bot| | |
bot.listen do |message| | |
if matching_requiest?(message.text) | |
text = online? ? "В офисе есть и свет и интернет" : "В офисе точно нет интернета и, может быть, света тоже нет." | |
bot.api.send_message(chat_id: message.chat.id, text: text) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment