Sha256: 1060aeed77d6bc721134d2bae376773108a16386b3d78988bc2becd62617ccd4
Contents?: true
Size: 854 Bytes
Versions: 1
Compression:
Stored size: 854 Bytes
Contents
require 'uri' module Lita module Handlers # Checks if a website is down or not. class Down < Handler HTTP_PREFIX = 'http://' HTTP_HTTPS_REGEX = %r{^http(s)?://} HELP = { 'Is example.com down?' => 'Checks if example.com is down.' } route(/^Is\s+(?<host>.+)\s+down\?/i, :down, help: HELP) def down(response) host = response.match_data[:host] host.prepend(HTTP_PREFIX) unless host.match(HTTP_HTTPS_REGEX) uri = URI.parse(host) if reachable?(uri) response.reply("It's just you. #{uri.host} is up.") else response.reply("It's not just you! #{uri.host} looks down from here.") end end private def reachable?(uri) !!http.head(uri) rescue false end Lita.register_handler(self) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lita-down-1.0.1 | lib/lita/handlers/down.rb |