Project

General

Profile

Download (2.45 KB) Statistics
| Branch: | Tag: | Revision:
#!/usr/bin/ruby -Ku

#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009-2011 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++


# to allow in-place run for test
$: << File.join(File.dirname(__FILE__), "..", "lib")

require 'cyborghood/cyborg'

module CyborgHood
class Guard < Cyborg
ROOM_PARAMS = {
'muc#roomconfig_allowinvites' => 0,
'muc#roomconfig_changesubject' => 0,
'muc#roomconfig_membersonly' => 1,
'muc#roomconfig_publicroom' => 1,
'muc#roomconfig_persistentroom' => 1,
'muc#roomconfig_roomsecret' => 'moderators',
}

def initialize
super {
@in_room = true
}
end

def run
super do
logger.debug "COIN !"
p @muc.roster.collect{|k, v| [k, v.show] }
#sleep 3
Thread.stop
p "pompompom"
p @muc.roster.collect{|k, v| [k, v.show] }
end
end

private

def on_missing_room
logger.info "CyborgHood HeadQuarters meeting room does not exist yet; creating..."

logger.debug "Fetching and checking room config form"
room_config_form = @muc.get_room_configuration
missing_params = ROOM_PARAMS.keys - room_config_form
unless missing_params.empty?
logger.fatal "CyborgHood HeadQuarters do not provide the following meeting room facilities: " + missing_params.join(", ")
quit(true)
end

logger.debug "Setting room configuration"
@muc.submit_room_configuration(ROOM_PARAMS)
end

def on_existing_room
logger.debug "Checking ownership"
unless @muc.owner?
logger.fatal "CyborgHood HeadQuarters meeting room has been taken over !!!"
quit(true)
end
end
end
end

#Jabber::debug = true

bot = CyborgHood::Guard.new

trap('INT') do
bot.ask_to_stop
end
trap('TERM') do
bot.ask_to_stop
end

bot.run

(2-2/9)