Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Cool Fire
nanobot4
Commits
0fb7ca2e
Commit
0fb7ca2e
authored
Mar 07, 2017
by
Cool Fire
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add plugin to set topic of #news to "istheinternetonfire.com" status.
parent
8b279449
Pipeline
#246
passed with stages
in 14 minutes and 58 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
plugins/internetonfire.rb
plugins/internetonfire.rb
+65
-0
No files found.
plugins/internetonfire.rb
0 → 100644
View file @
0fb7ca2e
#!/usr/bin/env ruby
# Plugin that monitors istheinternetonfire.com
class
Internetonfire
require
'json'
require
'open-uri'
def
initialize
(
status
,
config
,
output
,
irc
,
timer
)
@status
=
status
@config
=
config
@output
=
output
@irc
=
irc
@timer
=
timer
@url
=
'https://istheinternetonfire.com/status.json'
@timer
=
3600
@recent
=
''
@channel
=
'#news'
@prefix
=
'Tech news & security bulletins'
if
(
@status
.
threads
&&
@config
.
threads
)
@retr_thread
=
Thread
.
new
{
check_state
}
end
end
# Default action for this plugin
def
main
(
nick
,
user
,
host
,
from
,
msg
,
arguments
,
con
)
end
# Method to be called when the plugin is unloaded
def
unload
if
(
@status
.
threads
&&
@config
.
threads
)
@retr_thread
.
exit
end
return
true
end
private
def
check_state
loop
do
begin
response
=
open
(
@url
).
read
state
=
JSON
.
parse
(
response
)[
'status'
]
# Check if changed since last time
if
@recent
==
state
raise
'No update'
else
@recent
=
state
# Set topic
@irc
.
topic
(
@channel
,
"
#{
@prefix
}
| Is the internet on fire?
#{
state
}
"
)
end
rescue
Exception
=>
e
# Silently fail
@output
.
debug
(
"Error while reading status:
#{
e
.
message
}
\n
"
)
end
# Wait for a bit before fetching again
sleep
(
@timer
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment