Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Handle ctrl-c (but not very well; chanserv won't QUIT and the globops…
Browse files Browse the repository at this point in the history
… doesn't get received)
  • Loading branch information
danopia committed Jan 11, 2010
1 parent cf09282 commit 5e7b9d1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bitserv.rb
Expand Up @@ -28,6 +28,11 @@

services.add_uplink BitServ::ServerLink

trap "INT" do
services.shutdown "Caught interupt"
exit
end

EventMachine.run do
services.run! # TODO: Have two different calls, one that connects and
# one that starts EM and then connects. Possibly #connect to connect
Expand Down
4 changes: 4 additions & 0 deletions bots/chanserv.rb
Expand Up @@ -9,5 +9,9 @@ def on_new_channel link, channel
# end
#end
end

def on_shutdown message
@services.call_uplinks :quit_clone, self.nick, 'Shutting down'
end
end
end
8 changes: 8 additions & 0 deletions server_link.rb
Expand Up @@ -45,6 +45,10 @@ def ping
send '8', @me
end

def oper_msg message
send ":#{@me}", 'GLOBOPS', message
end

def force_join channel, bot
send ":#{@me}", '~', channel.timestamp.to_i, channel.name, '+', ":@#{bot.nick}"
puts "hi"
Expand All @@ -63,6 +67,10 @@ def introduce_bots
introduce_clone bot.nick
end
end

def quit_clone nick, message='Leaving'
send ":#{nick}", 'QUIT', message
end

def message origin, user, message
user = user.nick if user.is_a? User # TODO: implement User#to_s?
Expand Down
7 changes: 6 additions & 1 deletion services.rb
Expand Up @@ -28,6 +28,11 @@ def initialize(config_file = nil)
@running = false
end

def shutdown message='Shutting down'
emit :on_shutdown, message
call_uplinks :oper_msg, message
end

def load_bot type, *args
@bots << type.new(self, *args)
end
Expand Down Expand Up @@ -74,7 +79,7 @@ def connect_uplink uplink

def call_uplinks method, *args
@uplinks.each do |uplink|
uplink.call method, *args
uplink[:instance].__send__ method, *args # don't collide with send-to-server
end
end

Expand Down

0 comments on commit 5e7b9d1

Please sign in to comment.