-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathisitup.rb
63 lines (56 loc) · 1.71 KB
/
isitup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'cinch'
require 'ostruct'
require 'open-uri'
require 'json'
require 'cgi'
require_relative "config/check_ignore"
module Cinch
module Plugins
class Isitup
include Cinch::Plugin
set :plugin_name, 'isitup'
set :help, <<-USAGE.gsub(/^ {6}/, '')
Is it just you, or is your favorite website down? Find out!
Usage:
* !isitup <url>: Checks to see if the given website is up or not.
USAGE
match /isitup (.+)/i
def execute(m, query)
return if check_ignore(m.user)
data = check(query)
return m.reply "There seems to be an issue, please contact my Master." if data.nil?
isitup_result(m, data)
end
def check(terms)
data = JSON.parse(open("http://isitup.org/#{terms}.json").read)
OpenStruct.new(
domain: data['domain'],
status: data['status_code'],
time: data['response_time']
)
rescue
nil
end
def isitup_result(m, data)
if data.status == 3
m.reply Format(:red, "That is not a valid domain!")
return;
end
if data.status == 2
m.reply "4The domain:13 #{data.domain}4 is down!"
return;
end
if data.status == 1
m.reply "3The domain: 13#{data.domain}3 is up! Response time: 13#{data.time}."
return;
end
end
end
end
end
## Written by Richard Banks for Eve-Bot "The Project for a Top-Tier IRC bot.
## E-mail: namaste@rawrnet.net
## Github: Namasteh
## Website: www.rawrnet.net
## IRC: irc.sinsira.net #Eve
## If you like this plugin please consider tipping me on gittip