Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 97 lines (78 sloc) 2.497 kB
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
1 require 'yaml'
2
d07d7c1 @danopia Include account.rb in the main file now so I can start using it
authored
3 require 'account'
768e1c3 @danopia Added group.rb to start ripping LDAP out of GroupServ before it's too…
authored
4 require 'group'
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
5 require 'user'
6 require 'channel'
7 require 'bot'
8
9 module BitServ
10 class Services
95e2a2e @danopia Only handle one uplink per services instance. The link is still abstr…
authored
11 attr_accessor :bots, :config, :me, :uplink, :uplink_type, :hooks
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
12
13 def running?
14 @running
15 end
16 def run!
95e2a2e @danopia Only handle one uplink per services instance. The link is still abstr…
authored
17 return true if running?
18 return false unless @uplink_type # TODO: error
19
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
20 @running = true
95e2a2e @danopia Only handle one uplink per services instance. The link is still abstr…
authored
21
22 conf = @config['uplink']
23 @uplink = EM.connect conf['hostname'], conf['port'], @uplink_type, self, conf
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
24 end
25
26 def initialize(config_file = nil)
27 @config = YAML.load open(config_file)
28 @me = @config['hostname']
29
30 @bots = []
31 @hooks = {}
32 @running = false
113bcc5 @danopia Load bots dynamically from the config
authored
33
34 load_bots
538f92e @danopia Autoload uplink from conf
authored
35 load_uplink
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
36 end
37
5e7b9d1 @danopia Handle ctrl-c (but not very well; chanserv won't QUIT and the globops…
authored
38 def shutdown message='Shutting down'
39 emit :on_shutdown, message
95e2a2e @danopia Only handle one uplink per services instance. The link is still abstr…
authored
40 @uplink.oper_msg message
5e7b9d1 @danopia Handle ctrl-c (but not very well; chanserv won't QUIT and the globops…
authored
41 end
42
113bcc5 @danopia Load bots dynamically from the config
authored
43 def load_bots
f3b946b @danopia Finished reworking how bots load
authored
44 @config['bots'].each do |conf|
45 require File.join(File.dirname(__FILE__), 'bots', conf['class'].downcase)
46 bot = BitServ.const_get(conf['class']).new(self, conf)
47 @uplink.introduce_bot bot if running?
113bcc5 @danopia Load bots dynamically from the config
authored
48 end
c6e4682 @danopia Moving the bots to a new instance-based layout
authored
49 end
50
5b41073 @danopia New hooks are working. ChanServ joins all channels again.
authored
51 def add_handler event, bot, &blck
52 @hooks[event.to_sym] ||= []
53 @hooks[event.to_sym] |= [bot] # hmm...
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
54 end
55
56 def emit event, *args
57 return false unless @hooks.has_key? event.to_sym
5b41073 @danopia New hooks are working. ChanServ joins all channels again.
authored
58 @hooks[event.to_sym].each do |bot|
59 bot.send "on_#{event}", *args
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
60 end
61 end
62
cf09282 @danopia Added is_services_channel? to Services to clean up the on_new_channel…
authored
63 def is_services_channel? channel
64 channel.name.downcase == @config['services-channel'].downcase
65 end
66
538f92e @danopia Autoload uplink from conf
authored
67 def load_uplink
68 proto = @config['uplink']['protocol']
69 require File.join(File.dirname(__FILE__), 'protocols', proto)
70 proto = BitServ::Protocols.constants.find {|const| const.downcase == proto.downcase }
71 self.uplink = BitServ::Protocols.const_get proto
72 end
73
95e2a2e @danopia Only handle one uplink per services instance. The link is still abstr…
authored
74 def uplink= type
75 return false if running? # TODO: error
76 @uplink_type = type
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
77 end
78
79 def message origin, user, message
80 user = user.nick if user.is_a? User # TODO: implement User#to_s?
95e2a2e @danopia Only handle one uplink per services instance. The link is still abstr…
authored
81 @uplink.message origin, user, format(message)
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
82 end
83 def notice origin, user, message
84 user = user.nick if user.is_a? User # TODO: implement User#to_s?
95e2a2e @danopia Only handle one uplink per services instance. The link is still abstr…
authored
85 @uplink.notice origin, user, format(message)
02f7f42 @danopia Moving a lot of stuff around. It's hella hard to test this because it…
authored
86 end
87
88 def log origin, action, message
89 message origin, @config['services-channel'], "#{action.upcase}: #{message}"
90 end
91
92 def format message
93 message.gsub "^B", "\002"
94 end
95 end
96 end
Something went wrong with that request. Please try again.