Created
May 23, 2009 23:53
-
-
Save skammer/116882 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
require 'rubygems' | |
require 'blather/client' | |
setup '[email protected]', 'pass' | |
when_ready { puts "Connected ! send messages to #{jid.stripped}." } | |
subscription :request? do |s| | |
write s.approve! | |
end | |
message :chat?, :body => 'exit' do |m| | |
say m.from, 'Exiting ...' | |
shutdown | |
end | |
message :chat?, :body => /status/ do |m| | |
# Don't blame my code. I know it sucks. | |
# So, here I'm generating some system statistics | |
system_status = `uname -srp` + `uptime` + `df -h /|tail -1| awk '{ print "HDD: "$4" free and "$3" used." }'` | |
# Adding some HTML goodness | |
html_message = "<b>System status on #{Time.now.strftime("%a %b %d")}</b>\n" + | |
system_status.gsub("HDD", "<b>HDD</b>").gsub("load averages", "<b>load averages</b>") | |
# And here's the best part. I believe this is pretty straightforward way to add | |
# HTML formatting to messages. | |
say m.from, :html => html_message, | |
:plain => "System status on #{Time.now.strftime("%a %b %d")}\n" + system_status | |
end | |
message :chat?, :body => "uptime" do |m| | |
# In case I don't specify whether I'm using plain or HTML, plain is used as default | |
say m.from, `uptime` | |
end | |
message :chat?, :body => /trim_html_down_to_plain_text/ do |m| | |
# In case only HTML is specified, all tags are gsubbed from the original message | |
# and resulting string is used as plaintext part of the message | |
say m.from, :html => "<i>Some random text</i><br/><b>Sould be also sent as plain text</b>" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment