class IrcTest(unittest.TestCase): def setUp(self): self.irc = Irc('localhost', 6667, 'foo') def test_strip_trailing_cr(self): message = b'foobar\r' self.assertEqual(self.irc.strip_trailing_cr(message), message[:-1]) def test_strip_crlf(self): message = b'foo\nbar\rbaz\r\nquux\n\r' self.assertEqual(self.irc.strip_cr_and_lf(message), b'foobarbazquux') def test_split_n(self): message = 'a' * 510 * 10 parts = list(self.irc.split_n(message, 510)) self.assertEqual(len(parts), 10) for part in parts: self.assertEqual(len(part), 510) def test_split_n_one_part(self): message = 'a' parts = list(self.irc.split_n(message, 510)) self.assertEqual(len(parts), 1) for part in parts: self.assertEqual(len(part), 1) def test_split_n_empty(self): message = [] parts = list(self.irc.split_n(message, 510)) self.assertEqual(parts, [])
def save(self): """ saves channels and state. """ self.channels.save() self.userhosts.save() Irc.save(self)
def _handle_mode(self, message): prefix, command, parameters = Irc.split_message(message) # Auto-join servers after MODE received from NickServ. if prefix.lower() == ':nickserv': for channel in self.config['channels']: self._send_message(Irc.join(channel))
def _handle_privmsg(self, message): prefix, command, parameters = Irc.split_message(message) sender, user, ident = Irc.split_prefix(prefix) channel, msg = parameters.split(" ", 1) self.send_event("privmsg", msg[1:], sender, channel) if prefix is None: logger.debug("Malformed PRIVMSG: %s", message) return tokens = parameters.split(' ') # Handles the case of ": <text>". Someone started their message with a space. if tokens[1] == ':': privmsg_command = tokens[2] message = "{} {}".format(privmsg_command, " ".join(tokens[2:])) else: privmsg_command = tokens[1][1:] message = "{} {}".format(privmsg_command, " ".join(tokens[2:])) # CTCP PRIVMSGs if privmsg_command == '\x01PING': self._send_message(Irc.ctcp_pong(sender, message)) if privmsg_command == '\x01ACTION': pass elif privmsg_command[0] == '\x01': logger.debug('Missing CTCP command %s', privmsg_command)
def __init__(self, cfg={}, users=None, plugs=None, *args, **kwargs): Irc.__init__(self, cfg, users, plugs, *args, **kwargs) if self.state: if not self.state.has_key("opchan"): self.state["opchan"] = [] if not self.state.has_key("joinedchannels"): self.state["joinedchannels"] = []
def handle_privmsg(self, ievent): """ check if PRIVMSG is command, if so dispatch. """ if ievent.nick in self.nicks401: logging.debug("%s - %s is available again" % (self.name, ievent.nick)) self.nicks401.remove(ievent.nick) if not ievent.txt: return chat = re.search(dccchatre, ievent.txt) if chat: if self.users.allowed(ievent.userhost, 'USER'): start_new_thread(self._dccconnect, (ievent.nick, ievent.userhost, chat.group(1), chat.group(2))) return if '\001' in ievent.txt: Irc.handle_privmsg(self, ievent) return ievent.bot = self ievent.sock = self.sock chan = ievent.channel if chan == self.nick: ievent.msg = True ievent.speed = 4 ievent.printto = ievent.nick ccs = ['!', '@', self.cfg['defaultcc']] self.privwait.check(ievent) if ievent.isresponse: return if self.cfg['noccinmsg'] and self.msg: self.put(ievent) elif ievent.txt[0] in ccs: self.put(ievent) return self.put(ievent) if not ievent.iscmnd(): self.privwait.check(ievent)
def _handle_server_ping(self, message): prefix, command, parameters = Irc.split_message(message) # PONG any server PINGs with the same parameters. self._send_message(Irc.server_pong(parameters)) self.send_event( "server_ping", datetime.datetime.strftime(datetime.datetime.now(), '%H:%M:%S'))
def __init__(self, cfg): Irc.__init__(self, cfg) # object used to wait for PRIVMSG self.privwait = Privwait() # channels where we are op if not self.state.has_key('opchan'): self.state['opchan'] = [] self.userchannels = Dol() outmonitor.start()
def _handle_notice(self, message): # CTCP PONG if message.split(" ")[3] == ":\x01PING": time_stamp = ".".join(message.split(" ")[-2:])[:-1] time_taken = round(time.time() - float(time_stamp[:-1]), 2) prefix, command, parameters = Irc.split_message(message) user, ident, host = Irc.split_prefix(prefix) self.send_event("pong", str(time_taken), user)
def _handle_part(self, message): prefix, command, parameters = Irc.split_message(message) sender, user, ident = Irc.split_prefix(prefix) if sender == self.config['nick']: channel = parameters.split(" ")[0] self.users.pop(channel) self.send_event("part", channel)
def _handle_join(self, message): prefix, command, parameters = Irc.split_message(message) sender, user, ident = Irc.split_prefix(prefix) if sender == self.config['nick']: channel = parameters[1:] self.channels.append(channel) self.users[channel] = [] self.send_event("join", channel)
def _handle_433(self, message): prefix, command, parameters = Irc.split_message(message) if re.search("Nickname is already in use", parameters): self.config['nick'] = "_{}".format(self.config['nick']) self._send_message(Irc.nick(self.config['nick'])) self._send_message( Irc.user(self.config['user'], self.config['unused'], self.config['owner'])) self._send_message( Irc.mode(self.config['nick'], self.config['mode']))
def exit(self): """ save data, quit the bot and do shutdown. """ if self.connectok.isSet(): try: self._raw('QUIT :%s' % self.cfg['quitmsg']) except IOError: pass self.stop() partyline.stop(self) Irc.exit(self) self.save() rlog(10, self.name, 'exit') return 1
def onmessage(self, msg): Irc.onmessage(self, msg) # chan = message's channel or None chan = getattr(msg, "target", None) if chan and not ischannel(chan): chan = None # get a list of handlers handlers = list(self._get_handlers(chan)) iscommand = lambda word: any(word in handler for handler in handlers) # command = "title" for Privmsgs with "♥title" / "bot: title" / pm "title" # command = 123 for Numerics command = None if type(msg) is Privmsg and len(msg): first = msg[0] if msg.tomyself: if iscommand(first): # "cmd hello" in private command = msg.command = first msg.splitmsg = msg.splitmsg[1:] elif first[0] == conf.get("prefix", tag=self.tag, chan=chan): if iscommand(first[1:]): # "♥cmd hello" in #chan command = msg.command = first[1:] msg.splitmsg = msg.splitmsg[1:] elif len(msg) > 1 and first[:-1] == self.me[0] and first[-1] in (",", ":"): if iscommand(msg[1]): # "bot: hello" in #chan command = msg.command = msg[1] msg.splitmsg = msg.splitmsg[2:] elif type(msg) is Numeric: command = msg.num # assemble the list of functions that are to be run # together with their arguments funcs = [] for handler in handlers: for mtype in reversed(msg.__class__.__mro__[:-1]): if mtype in handler: funcs.append((handler[mtype], None)) if command and command in handler: funcs.append((handler[command], chan)) # sort functions according to their priority # and launch them funcs.sort(key=lambda tu: tu[0].priority) try: for func, chan in funcs: self._onmessage(func, msg, chan) except HaltMessage as e: self.onexception(e) return
def handle_ievent(self, ievent): """ check for callbacks, call Irc method. """ try: Irc.handle_ievent(self, ievent) if ievent.cmnd == 'JOIN' or ievent.msg: if ievent.nick in self.nicks401: self.nicks401.remove(ievent.nick) if ievent.cmnd != "PRIVMSG": i = IrcEvent() i.copyin(ievent) i.bot = self i.sock = self.sock ievent.nocb = True self.doevent(i) except: handle_exception()
def _process_message(self, message): """Process IRC messages.""" message = message.decode('utf-8') # self.send_event("recv", message) _, command, _ = Irc.split_message(message) self.irc_events.get(command, self._no_handle)(message)
class Bot: def __init__(self, config): self.config = config self.irc = Irc(config) self.game = Game() def run(self): last_start = time.time() while True: new_messages = self.irc.recv_messages(1024) if not new_messages: continue for message in new_messages: button = message['message'].lower() username = message['username'] if not self.game.is_valid_button(button): continue if self.config['start_throttle']['enabled'] and button == 'start': if time.time() - last_start < self.config['start_throttle']['time']: continue if button == 'start': last_start = time.time() pbutton(username, button) self.game.push_button(button)
def join(self, channel, password=None): """ join a channel .. use optional password. """ result = Irc.join(self, channel, password) if result != 1: return result if not self.channels.has_key(channel): # init channel data self.channels.setdefault(channel, {}) chan = self.channels[channel] # if password is provided set it got = False if password: chan['key'] = password got = True # check for control char .. if its not there init to ! if not chan.has_key('cc'): chan['cc'] = self.cfg['defaultcc'] or '!' got = True if not chan.has_key('perms'): chan['perms'] = [] got = True if not chan.has_key('mode'): chan['mode'] = "" got = True if got: self.channels.save() self.getchannelmode(channel) return 1
def say(self, printto, what, who=None, how='msg', fromm=None, speed=5): """ output what to printto. """ # check if printto is a queue if so put output to the queue if type(printto) == type(Queue.Queue): printto.put_nowait('[%s] %s' % (self.name, what)) return # check if bot is in notice mode notice = False try: notice = self.channels[printto]['notice'] except (KeyError, TypeError): pass if notice: how = 'notice' Irc.say(self, printto, what, who, how, fromm, speed)
def _resume(self, data, botname, reto=None): """ resume the bot. """ if not Irc._resume(self, data, botname, reto): return 0 for channel in self.state["joinedchannels"]: self.who(channel) return 1
def handle_ievent(self, ievent): """ check for callbacks, call Irc method. """ try: # call parent method Irc.handle_ievent(self, ievent) # check for callbacks if ievent.cmnd == 'JOIN' or ievent.msg: if ievent.nick.lower() in self.nicks401: self.nicks401.remove(ievent.nick.lower()) i = Ircevent() i.copyin(ievent) i.bot = self i.sock = self.sock callbacks.check(self, i) except: handle_exception()
def _resume(self, data, reto): """ resume the bot. """ if not Irc._resume(self, data, reto): return 0 for i in self.state['joinedchannels']: periodical.addjob(15, 1, self.who, self, i) return 1
def handle_privmsg(self, ievent): """ check if PRIVMSG is command, if so dispatch. """ if ievent.nick in self.nicks401: logging.debug("%s - %s is available again" % (self.cfg,name, ievent.nick)) self.nicks401.remove(ievent.nick) if not ievent.txt: return ievent.nodispatch = False chat = re.search(dccchatre, ievent.txt) if chat: if self.users.allowed(ievent.userhost, 'USER'): start_new_thread(self._dccconnect, (ievent.nick, ievent.userhost, chat.group(1), chat.group(2))) return if '\001' in ievent.txt: Irc.handle_privmsg(self, ievent) return ievent.bot = self ievent.sock = self.sock chan = ievent.channel self.put(ievent)
def __init__(self): self.config_path = "config/" self.module_path = "modules/" self.configure() self.irc = Irc(self.nick, self.channel) # load modules here self.module_handler = ModuleHandler(self.module_path, self.irc) self.parser = Parser(self.irc, self.module_handler, self.module_path) # always load the following: self.module_handler.load_module("loader", delay=False, startup=True) self.module_handler.load_module("core", delay=False, startup=True) self.module_handler.load_module("rand", delay=False, startup=True) self.module_handler.load_module("cheese", delay=False, startup=True) self.module_handler.load_module("images", delay=False, startup=True) self.module_handler.load_module("stackoverflow", delay=False, startup=True) self.module_handler.load_module("mood", delay=False, startup=True) self.module_handler.load_module("wiki", delay=False, startup=True) self.module_handler.load_module("shorty", delay=False, startup=True) self.module_handler.load_module("numfact", delay=False, startup=True)
def init_loop(self): logger.info("Client started.") if self._init_socket() is not None: if self.config['ssl']: ssl_info = self.sock.cipher() if ssl_info: logger.info( "SSL Cipher (%s), SSL Version (%s), SSL Bits (%s)", *ssl_info) # IRC RFC2812:3.1 states that a client needs to send a nick and # user message in order to register a connection. # Most servers mandate that the user's real name be the owner. self._send_message(Irc.nick(self.config['nick'])) self._send_message( Irc.user(self.config['user'], self.config['unused'], self.config['owner'])) else: self.stop()
def main(): lines = open('config.yml').read() config = yaml.load(lines) twitch = config['twitch'] revlo = config['revlo'] irc = Irc(twitch) token = revlo['api_key'] reward_id = int(revlo['reward_id']) print("Press Ctrl+C to kill the bot") try: while True: songs = scan_song_redemptions(token, reward_id) request_songs_to_nightbot(irc, twitch, songs) songs = [] time.sleep(60) except KeyboardInterrupt: print("Leaving channel") finally: irc.leave(twitch['channel'])
def _part_event(self, event): event_type, data = event message = data[0][0] destination = data[0][1] if data[0][2][0] == '#': destination = data[0][2] channel = message.split(" ")[1] if channel[0] == '#': self._send_response("Parting {}".format(channel), destination) self._send_message(Irc.part(channel, "Parting :)"))
def _ping_event(self, event): event_type, data = event message = data[0][0] sender = data[0][1] try: user = message.split(" ")[1] except: self._send_response("Command: ping <user>", sender) unix_timestamp = str(time.time()).replace(".", " ") self._send_message(Irc.ctcp_ping(user, unix_timestamp)) logger.info("Pinging {}".format(user))
def dissect(tcp): """Runs all TCP dissectors. @param conn: connection. @param data: payload data. """ ptcp = {} # populate array of connections of Cuckoo default report ptcp["layer"] = 4 # Source port ptcp["protocol_name"] = "TCP" ptcp["sport"] = tcp.sport # Source port ptcp["dport"] = tcp.dport # Destination port ptcp["seqnum"] = tcp.seq # Sequence number ptcp["acknum"] = tcp.flags # Acknowledge number ptcp["off"] = tcp.off # Data offset ptcp["reserved"] = 0 # Reserved - always 0 ptcp["cb"] = Tcp.tcp_flags(tcp.data) # Verify flag of control bits ptcp["win"] = tcp.win # Window ptcp["cksum"] = tcp.sum # Checksum ptcp["urp"] = tcp.urp # Urgent Pointer ptcp["options"] = tcp.opts # Options ptcp["padding"] = '' # TODO not present in dpkt.ip.IP (maybe computed) # HTTP if http.check(tcp.data): ptcp["payload"] = http.dissect(tcp.data) # SMTP. elif smtp.check(tcp): ptcp["payload"] = smtp.dissect(tcp.data) # IRC elif irc.check(tcp): ptcp["payload"] = irc.dissect(tcp.data) # DNS elif dns.check(tcp): ptcp["payload"] = dns.dissect(tcp.data) # Unknown Protocol else: ptcp["payload"] = "unknown protocol on layer " + str( ptcp["layer"] + 1) return ptcp
def dissect(tcp): """Runs all TCP dissectors. @param conn: connection. @param data: payload data. """ ptcp = {} # populate array of connections of Cuckoo default report ptcp["layer"] = 4 # Source port ptcp["protocol_name"] = "TCP" ptcp["sport"] = tcp.sport # Source port ptcp["dport"] = tcp.dport # Destination port ptcp["seqnum"] = tcp.seq # Sequence number ptcp["acknum"] = tcp.flags # Acknowledge number ptcp["off"] = tcp.off # Data offset ptcp["reserved"] = 0 # Reserved - always 0 ptcp["cb"] = Tcp.tcp_flags(tcp.data) # Verify flag of control bits ptcp["win"] = tcp.win # Window ptcp["cksum"] = tcp.sum # Checksum ptcp["urp"] = tcp.urp # Urgent Pointer ptcp["options"] = tcp.opts # Options ptcp["padding"] = '' # TODO not present in dpkt.ip.IP (maybe computed) # HTTP if http.check(tcp.data): ptcp["payload"] = http.dissect(tcp.data) # SMTP. elif smtp.check(tcp): ptcp["payload"] = smtp.dissect(tcp.data) # IRC elif irc.check(tcp): ptcp["payload"] = irc.dissect(tcp.data) # DNS elif dns.check(tcp): ptcp["payload"] = dns.dissect(tcp.data) # Unknown Protocol else: ptcp["payload"] = "unknown protocol on layer " + str(ptcp["layer"]+1) return ptcp
def _handle_userlist_update(self, message): prefix, command, parameters = Irc.split_message(message) split_params = parameters.split(' ') users = split_params[3:][:-1] # Remove leading ':' from first user. users[0] = users[0][1:] channel = split_params[2] if channel not in self.users: self.users[channel] = users else: self.users[channel].extend(users) self.send_event("users", channel, self.users[channel]) logger.info(" J | Joined channels: {}".format(self.users))
def _send_response(self, message, original_sender=None, destination=None): """ Sends a response to the correct location, whether a channel or query""" if destination is not None and destination[ 0] == '#' and message is not None: pass elif original_sender is not None and message is not None: destination = original_sender else: destination = None if destination is not None: msg = Irc.privmsg(destination, message) self._send_message(msg) self.send_event("send_privmsg", str(message), self.config['nick'], destination)
def start(self): broker = Broker(self.rxq, self.txq) broker.find_plugins() irc = Irc(self.rxq, self.txq) self.irc_p = Process(target=irc.start) self.broker_p = Process(target=broker.start) self.irc_p.start() self.broker_p.start() for input in settings.INPUTS: input_path = path.join(settings.INPUTS_DIR, "%s.py" % input) if path.isfile(input_path): module = load_source(input, input_path) p = Process(target=module.input, args=(self.rxq, )) self.inputs.append(p) p.start() else: # warning pass
def on_connect(con): # This protocol is responsible by spawning # the event LOAD. It takes care of spawning a CLOSE # event when the connection is over. Stdout(con) # This protocol is responsible by installing a dump method # into the con instance. It takes care of sending everything # that goes through the dump method. Stdin(con) # This protocol is used to break the stream of data into chunks delimited # by '\r\n'. So, if the network sends 'data1\r\ndata2\r\ndata3\r\n' it will # spawns three times the event FOUND. It will carry 'data1', 'data2', 'data3'. Shrug(con) # This untwisted protocol is a tiny implementation of irc protocol. # It handles about 80% of the irc events. It is possible to be improved # and handle 100% of all irc events. Irc(con) # We want to print out on the screen all data that comes from the irc server. xmap(con, LOAD, lambda con, data: sys.stdout.write('%s\n' % data)) # When the connection is over we need to destroy the Spin instance. The # lose function takes care of doing that for us. xmap(con, CLOSE, lambda con, err: lose(con)) # When the event 'PRIVMSG' happens then we will have our handle # on_privmsg called. You could experiment other irc commands. xmap(con, 'PRIVMSG', on_privmsg) # When the irc server requires us to send back a PONG :server. xmap(con, 'PING', on_ping) # Our nick. con.dump('NICK %s\r\n' % NICK) con.dump('USER %s %s %s :%s\r\n' % (IRC_X, IRC_Y, IRC_Z, IRC_W)) # Finally, it joins the channel. con.dump('JOIN %s\r\n' % CHANNEL)
class Gouda: def __init__(self): self.config_path = "config/" self.module_path = "modules/" self.configure() self.irc = Irc(self.nick, self.channel) # load modules here self.module_handler = ModuleHandler(self.module_path, self.irc) self.parser = Parser(self.irc, self.module_handler, self.module_path) # always load the following: self.module_handler.load_module("loader", delay=False, startup=True) self.module_handler.load_module("core", delay=False, startup=True) self.module_handler.load_module("rand", delay=False, startup=True) self.module_handler.load_module("cheese", delay=False, startup=True) self.module_handler.load_module("images", delay=False, startup=True) self.module_handler.load_module("stackoverflow", delay=False, startup=True) self.module_handler.load_module("mood", delay=False, startup=True) self.module_handler.load_module("wiki", delay=False, startup=True) self.module_handler.load_module("shorty", delay=False, startup=True) self.module_handler.load_module("numfact", delay=False, startup=True) def configure(self): config = ConfigLoader(self.config_path + "settings.ini") self.nick = config.get_nick() self.network = config.get_network() self.port = config.get_port() self.channel = config.get_channel() def run(self): self.irc.connect(self.network, self.port) while True: data = self.irc.receive() self.irc.pong(data) self.irc.knock_check(data) line = self.irc.read(data) # send line to parser # parser is where modules are loaded etc self.parser.run(line)
def join(self, channel, password=None): """ join a channel .. use optional password. """ result = Irc.join(self, channel, password) if result != 1: return result chan = ChannelBase(channel, self.botname) got = False if password: chan.setkey('IRC',password) got = True if not chan.data.cc: chan.data.cc = self.cfg.defaultcc or '!' got = True if not chan.data.perms: chan.data.perms = [] got = True if not chan.data.mode: chan.data.mode = "" got = True if got: chan.save() self.getchannelmode(channel) return 1
def join(self, channel, password=None): """ join a channel .. use optional password. """ chan = ChannelBase(channel, self.cfg.name) if password: chan.data.key = password.strip() chan.save() result = Irc.join(self, channel, chan.data.key) if result != 1: return result got = False if not chan.data.cc: chan.data.cc = self.cfg.globalcc or '' got = True if not chan.data.perms: chan.data.perms = [] got = True if not chan.data.mode: chan.data.mode = "" got = True if got: chan.save() self.getchannelmode(channel) return 1
def join(self, channel, password=None): """ join a channel .. use optional password. """ chan = ChannelBase(channel, self.cfg.name) if password: chan.data.key = password.strip() chan.save() # logging.warn("%s - using key %s for channel %s" % (self.cfg.name, chan.data.key, channel)) result = Irc.join(self, channel, chan.data.key) if result != 1: return result got = False if not chan.data.cc: chan.data.cc = self.cfg.defaultcc or "!" got = True if not chan.data.perms: chan.data.perms = [] got = True if not chan.data.mode: chan.data.mode = "" got = True if got: chan.save() self.getchannelmode(channel) return 1
def reconnect(self): """ reconnect and if succesfull join channels. """ if Irc.reconnect(self): self.joinchannels()
def send(self, txt): """ call Irc send and check for monitor callbacks. """ Irc.send(self, str(txt)) outmonitor.put(self, str(txt))
def setUp(self): self.irc = Irc('localhost', 6667, 'foo')
def handle_privmsg(self, ievent): """ check if PRIVMSG is command, if so dispatch. """ if ievent.nick in self.nicks401: rlog(10, self.name, "%s is available again" % ievent.nick) self.nicks401.remove(ievent.nick) if not ievent.txt: return # check if it is a dcc chat request chat = re.search(dccchatre, ievent.txt) if chat: # check if the user is known if users.allowed(ievent.userhost, 'USER'): # start connection start_new_thread(self._dccconnect, (ievent.nick, ievent.userhost, chat.group(1), chat.group(2))) return # see if base class method would handle it if '\001' in ievent.txt: Irc.handle_privmsg(self, ievent) return # set bot and socket in ircevent ievent.bot = self ievent.sock = self.sock chan = ievent.channel.lower() # check for /msg if chan == self.nick.lower(): ievent.msg = 1 ievent.speed = 7 ievent.printto = ievent.nick ccs = ['!', '@', self.cfg['defaultcc']] # check for PRIVMSG waiting callback self.privwait.check(ievent) if ievent.isresponse: return if not self.cfg['noccinmsg']: plugins.trydispatch(self, ievent) elif ievent.txt[0] in ccs: ievent.txt = ievent.txt[1:] plugins.trydispatch(self, ievent) return ievent.printto = chan # see if we can get channel control character try: cchar = self.channels[chan]['cc'] except LookupError: cchar = self.cfg['defaultcc'] or '!' except TypeError: cchar = self.cfg['defaultcc'] or '!' # see if cchar matches, if so dispatch ievent.speed = 5 if ievent.txt[0] in cchar: ievent.cc = ievent.txt[0] ievent.txt = ievent.txt[1:] plugins.trydispatch(self, ievent) return # see if were adressed, if so dispatch txtlist = ievent.txt.split(':', 1) if txtlist[0].lower() == self.nick.lower(): if len(txtlist) < 2: return ievent.txt = txtlist[1].strip() plugins.trydispatch(self, ievent) return # habbie addressing mode txtlist = ievent.txt.split(',', 1) if txtlist[0].lower() == self.nick.lower(): if len(txtlist) < 2: return ievent.txt = txtlist[1].strip() plugins.trydispatch(self, ievent) return # check for PRIVMSG waiting callback self.privwait.check(ievent)
from irc import Irc; #from triage import TriageHandler; import threading; import passwordholder; #config stuff mainchannel = '#risucraftt' triagechannel = '#modinstallhelp' #initial enable state. 0 = disabled, -1 = testing, 1 = enabled enabled = -1 ###### iconn = Irc() iconn.nick = 'InstallHelper' iconn.ident = 'RikBots' iconn.realname = 'Bot' def init1(): global ircthread,iconn; iconn.on_ready.__iadd__(init2) ircthread = threading.Thread(target=iconn.connect,args=("irc.esper.net",6667)) ircthread.start() def init2(): global iconn,triageInst; print "identifying to nickserv" iconn.msg("NickServ","IDENTIFY %s %s" % (passwordholder.nickservUser,passwordholder.nickservPass)) print "joining channels" iconn.join(triagechannel) iconn.join(mainchannel) triageInst = TriageHandler(iconn)
def __init__(self, config): self.config = config self.irc = Irc(config) self.game = Game()
from irc import Irc from database import Database from config import get_parameters from ddate import Ddate # send_lag = 1 #depricated? # by default ignore the other bot jamaal ignorelist = [u"jamaal"] # grab config options = get_parameters() # seed channels list with default from config channels = ["#%s" % (options[u"CHANNEL"])] # get 'default' database object db = Database() # get IRC object laamaj = Irc(options["SERVER"], 6667, options["NICK"], options["IDENT"], options["REALNAME"]) DDATE = None @laamaj.add_on_connected def connectJoinChannels(connection, server): """ Join channels when connecting. """ print(u"Connected to %s" % (server)) for channel in channels: connection.join(channel) print(u"Joined channel %s" % (channel)) @laamaj.add_on_connected def connectScheduleDdate(connection, server):
def __init__(self, cfg={}, users=None, plugs=None, *args, **kwargs): Irc.__init__(self, cfg, users, plugs, *args, **kwargs) self.privwait = Privwait() if self.state: if not self.state.has_key('opchan'): self.state['opchan'] = [] if not self.state.has_key('joinedchannels'): self.state['joinedchannels'] = []
#!/usr/bin/python2.6 from irc import Irc from ircLoader import IrcLoader from optparse import OptionParser ## Command line parser to enable raw output parser = OptionParser() parser.add_option( "-r", "--raw", action="store_true", dest="raw", default=False, help="Print the raw IRC data instead of formatting it.", ) (options, args) = parser.parse_args() datloader = IrcLoader() irc = Irc(datloader, options) irc.startIrc()