Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mimikadze/cea4bd19db4c79c063f3911cc2593b37 to your computer and use it in GitHub Desktop.
Save mimikadze/cea4bd19db4c79c063f3911cc2593b37 to your computer and use it in GitHub Desktop.
#!/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