irc.py

changeset 132
a22c50f52a23
parent 124
7b2cd8b1ba86
child 140
631451eecefc
equal deleted inserted replaced
131:7349e9c6176b 132:a22c50f52a23
30 import socket 30 import socket
31 import sys 31 import sys
32 import re 32 import re
33 import modulecore as ModuleCore 33 import modulecore as ModuleCore
34 import traceback 34 import traceback
35 import time
35 from configfile import Config 36 from configfile import Config
36 import bt as Bt 37 import bt as Bt
37 import hgpoll as HgPoll 38 import hgpoll as HgPoll
38 39
39 CLIF_CONNECTED = (1 << 1) 40 CLIF_CONNECTED = (1 << 1)
41 CtcpChar = '\001' 42 CtcpChar = '\001'
42 BoldChar = '\002' 43 BoldChar = '\002'
43 ColorChar = '\003' 44 ColorChar = '\003'
44 45
45 all_clients = [] 46 all_clients = []
47 ClientsByName = {}
46 48
47 class RestartError (Exception): 49 class RestartError (Exception):
48 def __init__ (self, value): 50 def __init__ (self, value):
49 self.message = value 51 self.message = value
50 def __str__ (self): 52 def __str__ (self):
97 self.commandprefix = Config.get_value ('commandprefix', default='.') 99 self.commandprefix = Config.get_value ('commandprefix', default='.')
98 all_clients.append (self) 100 all_clients.append (self)
99 asyncore.dispatcher.__init__ (self) 101 asyncore.dispatcher.__init__ (self)
100 self.create_socket (socket.AF_INET, socket.SOCK_STREAM) 102 self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
101 self.connect ((self.host, self.port)) 103 self.connect ((self.host, self.port))
104 ClientsByName[self.name] = self
102 105
103 def register_to_irc (self): 106 def register_to_irc (self):
104 ident = Config.get_value ('ident', default='cobalt') 107 ident = Config.get_value ('ident', default='cobalt')
105 gecos = Config.get_value ('gecos', default='cobalt') 108 gecos = Config.get_value ('gecos', default='cobalt')
106 self.write ("PASS %s" % self.password) 109 self.write ("PASS %s" % self.password)
133 def send_all_now (self): 136 def send_all_now (self):
134 for line in self.send_buffer: 137 for line in self.send_buffer:
135 if self.verbose: 138 if self.verbose:
136 print "[%s] <- %s" % (self.name, line) 139 print "[%s] <- %s" % (self.name, line)
137 self.send ("%s\n" % line) 140 self.send ("%s\n" % line)
141 time.sleep (0.25)
138 self.send_buffer = [] 142 self.send_buffer = []
139 143
140 def handle_read (self): 144 def handle_read (self):
141 lines = self.recv (4096).splitlines() 145 lines = self.recv (4096).splitlines()
142 for utfline in lines: 146 for utfline in lines:

mercurial