def Main(self): while True: rawdata = self.irc.recv(4096) try: data = rawdata.decode('utf-8') except UnicodeDecodeError: try: data = rawdata.decode('cp1252') except UnicodeDecodeError: try: data = rawdata.decode('iso8859-1') except: continue lines = str(data).split('\n') for line in lines: if len(line) < 1: continue Log = Logger.interpret(line) # reply to pings if Log['command'] == 'PING': self.ircSend('PONG :%s' % Log['trail'][0]) continue # SASL if self.info['SASL']: if Log['command'] == 'CAP': if Log['parameters'] [0] == '*' and Log['parameters'][1] == 'LS': self.ircSend('CAP REQ :%s' % ' '.join(Log['trail'])) continue if Log['parameters'] [1] == 'ACK': self.ircSend('AUTHENTICATE PLAIN') continue if Log['command'] == 'AUTHENTICATE' and Log['parameters'][0] == '+': sasl_token = '\0'.join([self.info['NICK'], self.info['NICK'], self.info['PASS']]) self.ircSend('AUTHENTICATE %s' % base64.b64encode(sasl_token.encode('utf-8')).decode('utf-8')) continue if Log['command'] == '903': self.ircSend('CAP END') self.ircSend('JOIN %s' % ','.join(self.info['CHAN'])) continue # checks when identified with nickserv if Log['command'] == 'NOTICE' and Log['nick'] == 'NickServ': if len(Log['trail']) > 3: if 'registered' in Log['trail'][3]: self.ircSend('PRIVMSG NickServ :identify %s' % self.info['PASS']) continue if Log['trail'][3] == 'identified': self.ircSend('JOIN %s' % ','.join(self.info['CHAN'])) continue # checks for INVITE received if Log['command'] == 'INVITE' and Log['parameters'][0] == self.info['NICK']: if Log['trail'][0] not in self.info['CHAN']: self.info['CHAN'].append(Log['trail'][0]) self.updateFile() self.ircSend('JOIN %s' % Log['trail'][0]) # checks channel join if Log['command'] == 'JOIN': if Log['nick'] == self.info['NICK']: self.activeDict[Log['parameters'][0]] = {} self.ircSend('WHO %s %%na' % Log['parameters'][0]) elif Log['nick'] not in self.activeDict[Log['parameters'][0]]: self.activeDict[Log['parameters'][0]][Log['nick']] = 0 if Log['nick'] not in list(self.userDict.values()): self.ircSend('WHOIS %s' % Log['nick']) continue # checks nick change if Log['command'] == 'NICK': if Log['nick'] == self.info['NICK']: self.info['NICK'] = Log['trail'][0] else: self.ircSend('WHOIS %s' % Log['trail'][0]) continue # parses NAMES result if str(Log['command']) == '353' and len(Log['parameters']) > 2: if Log['parameters'][-1] not in self.activeDict: self.activeDict[Log['parameters'][-1]] = {} for names in Log['trail']: names = names.lstrip('@+') if names != self.info['NICK']: self.activeDict[Log['parameters'][-1]][names] = 0 continue # parses WHOIS result if (str(Log['command']) == '330' or str(Log['command']) == '354') and len(Log['parameters']) > 2: if Log['parameters'][2] not in self.userDict: self.userDict[Log['parameters'][2]] = [] if Log['parameters'][1] not in self.userDict[Log['parameters'][2]] and Log['parameters'][1] != self.info['NICK']: self.userDict[Log['parameters'][2]].append(Log['parameters'][1]) self.updateFile() continue # updates active list if user leaves if Log['command'] == 'PART': if Log['nick'] in self.activeDict[Log['parameters'][0]]: del self.activeDict[Log['parameters'][0]][Log['nick']] continue if Log['command'] == 'QUIT': for channels in self.info['CHAN']: if Log['nick'] in self.activeDict[channels]: del self.activeDict[channels][Log['nick']] continue # checks when PRIVMSG received if Log['command'] == 'PRIVMSG': Log['context'] = Log['parameters'][0] # builds last spoke list if Log['context'] not in self.activeDict: self.activeDict[Log['context']] = {} self.activeDict[Log['context']][Log['nick']] = Log['time'] validList = [] for group in self.userDict.values(): validList.extend(group) if Log['nick'] not in validList and Log['cap'] == '+': self.ircSend('WHOIS %s' % Log['nick']) Soaker.Handler(self, Log) Commands.Handler(self, Log) URLInfo.Handler(self, Log)
def Main(self): while True: rawdata = self.irc.recv(4096) try: data = rawdata.decode('utf-8') except UnicodeDecodeError: try: data = rawdata.decode('cp1252') except UnicodeDecodeError: try: data = rawdata.decode('iso8859-1') except: continue lines = str(data).split('\n') for line in lines: if len(line) < 1: continue Log = Logger.interpret(line) self.fLog[Log['time']] = Log # reply to pings if Log['command'] == 'PING': self.ircSend('PONG :%s' % Log['trail'][0]) continue # SASL if self.info['SASL']: if Log['command'] == 'CAP': if Log['parameters'] [0] == '*' and Log['parameters'][1] == 'LS': self.ircSend('CAP REQ :%s' % ' '.join(Log['trail'])) continue if Log['parameters'] [1] == 'ACK': self.ircSend('AUTHENTICATE PLAIN') continue if Log['command'] == 'AUTHENTICATE' and Log['parameters'][0] == '+': sasl_token = '\0'.join([self.info['NICK'], self.info['NICK'], self.info['PASS']]) self.ircSend('AUTHENTICATE %s' % base64.b64encode(sasl_token.encode('utf-8')).decode('utf-8')) continue if Log['command'] == '903': self.ircSend('CAP END') self.ircSend('JOIN %s' % ','.join(self.info['CHAN'])) continue # checks when identified with nickserv if Log['command'] == 'NOTICE' and Log['nick'] == 'NickServ': if len(Log['trail']) > 3: if 'registered' in Log['trail'][3]: self.ircSend('PRIVMSG NickServ :identify %s' % self.info['PASS']) continue if Log['trail'][3] == 'identified': self.ircSend('JOIN %s' % ','.join(self.info['CHAN'])) continue # checks for INVITE received if Log['command'] == 'INVITE' and Log['parameters'][0] == self.info['NICK']: if Log['trail'][0] not in self.info['CHAN']: self.info['CHAN'].append(Log['trail'][0]) self.updateFile() self.ircSend('JOIN %s' % Log['trail'][0]) # checks channel join if Log['command'] == 'JOIN': if Log['nick'] == self.info['NICK']: self.activeDict[Log['parameters'][0]] = {} self.ircSend('WHO %s %%na' % Log['parameters'][0]) elif Log['nick'] not in self.activeDict[Log['parameters'][0]]: self.activeDict[Log['parameters'][0]][Log['nick']] = 0 if Log['nick'] not in list(self.userDict.values()): self.ircSend('WHOIS %s' % Log['nick']) continue # checks nick change if Log['command'] == 'NICK': if Log['nick'] == self.info['NICK']: self.info['NICK'] = Log['trail'][0] else: for channels in self.info['CHAN']: if Log['nick'] in self.activeDict[channels]: self.activeDict[channels][Log['trail'][0]] = self.activeDict[channels][Log['nick']] del self.activeDict[channels][Log['nick']] self.ircSend('WHOIS %s' % Log['trail'][0]) continue # parses NAMES result if str(Log['command']) == '353' and len(Log['parameters']) > 2: if Log['parameters'][-1] not in self.activeDict: self.activeDict[Log['parameters'][-1]] = {} for names in Log['trail']: names = names.lstrip('@+') if names != self.info['NICK']: self.activeDict[Log['parameters'][-1]][names] = 0 continue # parses WHOIS result if (str(Log['command']) == '330' or str(Log['command']) == '354') and len(Log['parameters']) > 2: if Log['parameters'][2] != str(0): if Log['parameters'][2] not in self.userDict: self.userDict[Log['parameters'][2]] = [] if Log['parameters'][1] not in self.userDict[Log['parameters'][2]] and Log['parameters'][1] != self.info['NICK']: self.userDict[Log['parameters'][2]].append(Log['parameters'][1]) self.updateFile() continue # updates active list if user leaves if Log['command'] == 'PART': if Log['nick'] in self.activeDict[Log['parameters'][0]]: del self.activeDict[Log['parameters'][0]][Log['nick']] continue if Log['command'] == 'QUIT': for channels in self.info['CHAN']: if Log['nick'] in self.activeDict[channels]: del self.activeDict[channels][Log['nick']] continue # checks when PRIVMSG received if Log['command'] == 'PRIVMSG': if Log['context'] not in self.info['UNLOAD'].keys(): self.info['UNLOAD'][Log['context']] = [] # builds last spoke list if Log['context'] not in self.activeDict: self.activeDict[Log['context']] = {} self.activeDict[Log['context']][Log['nick']] = Log['time'] validList = [] for group in self.userDict.values(): validList.extend(group) if Log['nick'] not in validList and Log['cap'] == '+': self.ircSend('WHOIS %s' % Log['nick']) if Log['host'] in self.info['OWNER'] + self.info['SUDOER']: if len(Log['trail']) > 1: def imports(): for name, val in globals().items(): if isinstance(val, types.ModuleType): yield val.__name__ try: if Log['trail'][0].lower() == '!load': if Log['trail'][1] in self.info['UNLOAD'][Log['context']]: self.info['UNLOAD'][Log['context']].remove(Log['trail'][1]) self.PRIVMSG(Log['context'],'Module \'%s\' loaded' % Log['trail'][1]) if Log['trail'][0].lower() == '!unload': if Log['trail'][1] in list(imports()) and Log['trail'][1] not in self.info['UNLOAD'][Log['context']]: self.info['UNLOAD'][Log['context']].append(Log['trail'][1]) self.PRIVMSG(Log['context'],'Module \'%s\' unloaded' % Log['trail'][1]) self.updateFile() if Log['trail'][0].lower() == '!reload': module = __import__(Log['trail'][1]) if Log['trail'][1] == 'IRCbot': self.ircSend('QUIT') self.irc.close() if Log['trail'][1] in list(imports()): importlib.reload(module) self.PRIVMSG(Log['context'],'Module \'%s\' reloaded' % Log['trail'][1]) except Exception as e: print(e) if Log['trail'][0] == '!quit': self.ircSend('QUIT') self.irc.close() sys.exit('User exited') if 'Soaker' not in self.info['UNLOAD'][Log['context']]: Soaker.Handler(self, Log) if 'Commands' not in self.info['UNLOAD'][Log['context']]: Commands.Handler(self, Log) if 'URLInfo' not in self.info['UNLOAD'][Log['context']]: URLInfo.Handler(self, Log)
def Main(self): while True: rawdata = self.irc.recv(4096) try: data = rawdata.decode('utf-8') except UnicodeDecodeError: try: data = rawdata.decode('cp1252') except UnicodeDecodeError: try: data = rawdata.decode('iso8859-1') except: continue lines = str(data).split('\n') for l in lines: if len(l) < 1: continue line = Logger.interpret(self.info,l) # reply to pings if line['command'] == 'PING': self.ircSend('PONG :%s' % line['trail'][0]) continue # SASL if self.info['SASL']: if line['command'] == 'CAP': if line['parameters'] [0] == '*' and line['parameters'][1] == 'LS': self.ircSend('CAP REQ :%s' % ' '.join(line['trail'])) continue if line['parameters'] [1] == 'ACK': self.ircSend('AUTHENTICATE PLAIN') continue if line['command'] == 'AUTHENTICATE' and line['parameters'][0] == '+': sasl_token = '\0'.join([self.info['NICK'], self.info['NICK'], self.info['PASS']]) self.ircSend('AUTHENTICATE %s' % base64.b64encode(sasl_token.encode('utf-8')).decode('utf-8')) continue if line['command'] == '903': self.ircSend('CAP END') self.ircSend('JOIN %s' % ','.join(self.info['CHAN'])) continue # checks when identified with nickserv if line['command'] == 'NOTICE' and line['nick'] == 'NickServ': if len(line['trail']) > 3: if 'registered' in line['trail'][3]: self.ircSend('PRIVMSG NickServ :identify %s' % self.info['PASS']) self.authed = True; continue if self.authed == True: self.ircSend('JOIN %s' % ','.join(self.info['CHAN'])) continue # checks for INVITE received if line['command'] == 'INVITE' and line['parameters'][0] == self.info['NICK']: if line['trail'][0] not in self.info['CHAN']: self.info['CHAN'].append(line['trail'][0]) self.updateFile() self.ircSend('JOIN %s' % line['trail'][0]) if Tracker.Handler(self, line): continue # checks when PRIVMSG received if line['command'] == 'PRIVMSG' and line['trail']: if line['parameters'][0].lower() == self.info['NICK'].lower() and line['trail'][0] == '\001VERSION\001': self.ircSend('NOTICE %s :\001VERSION MarcoRoboto:6.9:Micucksoft Winblows 10\001' % line['nick']) continue # builds last spoke list if line['context'] not in self.lastSeen: self.lastSeen[line['context']] = {} self.lastSeen[line['context']][line['nick']] = [line['time'], 'talk', ' '.join(line['trail']).encode('utf-8')] self.updateLastSeen() try: if line['host'] in self.info['OWNER'] + self.info['SUDOER']: def imports(): for name, val in globals().items(): if isinstance(val, types.ModuleType): yield val.__name__ if line['trail'][0] == '@reload' and line['trail'][1] in list(imports()): importlib.reload(sys.modules[line['trail'][1]]) if line['trail'][0] == '@do': self.ircSend(' '.join(line['trail'][1:])) if line['trail'][0] == '@quit': self.ircSend('QUIT') self.irc.close() sys.exit('User exited') if line['nick'].lower() not in [x.lower() for x in self.info['IGNORE']]: Commands.Handler(self, line) URLInfo.Handler(self, line) except Exception as e: print(e)