def merge(self, name, userhost): """ add userhosts to user with name """ name = name.lower() for item in self.data: if item.name == name: userhost = stripident(userhost) item.userhosts.append(userhost) self.adduserhost(userhost, item) self.save() rlog(10, 'users', 'merged %s (%s) with %s' % (name, \ userhost, item.name)) return 1 return None
def getuser(self, userhost): """ get user for which userhost matches """ userhost = stripident(userhost) if userhost in self.userhosts: return self.userhosts[userhost] else: for i in self.compiled: if re.search(i, userhost): return self.compiled[i] for user in self.data: for i in user.userhosts: if i == userhost or i == stripped(userhost): return user return None
def parse(self, bot, rawstr): """ parse raw string into ircevent. """ self.bot = bot stats.up('events', bot.name) bot.nrevents += 1 rawstr = rawstr.rstrip() splitted = re.split('\s+', rawstr) # check if there is a prefix (: in front) if not rawstr[0] == ':': # no prefix .. 1st word is command splitted.insert(0, ":none!none@none") rawstr = ":none!none@none " + rawstr self.prefix = splitted[0][1:] # get nick/userhost nickuser = self.prefix.split('!') if len(nickuser) == 2: self.nick = nickuser[0] stats.up('events', self.nick) if self.bot.cfg['stripident'] or config['stripident']: self.userhost = stripident(nickuser[1]) else: self.userhost = nickuser[1] # set command self.cmnd = splitted[1] stats.up('events', self.cmnd) # split string based of postfix count .. nr of items ater the command if pfc.has_key(self.cmnd): self.arguments = splitted[2:pfc[self.cmnd] + 2] txtsplit = re.split('\s+', rawstr, pfc[self.cmnd] + 2) self.txt = txtsplit[-1] else: self.arguments = splitted[2:] # 1st argument is target if self.arguments: self.target = self.arguments[0] self.postfix = ' '.join(self.arguments) # check if target is text if self.target and self.target.startswith(':'): self.txt = ' '.join(self.arguments) # strip strarting ':' from txt if self.txt: if self.txt[0] == ":": self.txt = self.txt[1:] rlog(0, 'ircevent', "%s %s %s" % (self.cmnd, self.arguments, self.txt)) # set ircevent attributes if self.cmnd == 'PING': self.speed = 10 if self.cmnd == 'PRIVMSG': self.channel = self.arguments[0] elif self.cmnd == 'JOIN' or self.cmnd == 'PART': if self.arguments: self.channel = self.arguments[0] else: self.channel = self.txt elif self.cmnd == 'MODE': self.channel = self.arguments[0] elif self.cmnd == 'TOPIC': self.channel = self.arguments[0] elif self.cmnd == 'KICK': self.channel = self.arguments[0] elif self.cmnd == '353': self.channel = self.arguments[2] elif self.cmnd == '324': self.channel = self.arguments[1] if self.userhost: # userhost before possible stripident self.ruserhost = self.userhost # jabber compat .. this is userhost on irc self.stripped = self.userhost # determine user self.user = stripident(self.userhost).split('@')[0] self.origtxt = self.txt self.channel = self.channel.strip() stats.up('events', self.channel) self.origchannel = self.channel rlog(-1, 'ircevent', self) # show error try: nr = int(self.cmnd) if nr > 399: rlog(10, bot.name + '.error', '%s: %s %s' % (self.cmnd, \ self.arguments, self.txt)) except ValueError: pass return self
def parse(self, bot, rawstr): """ parse raw string into ircevent. """ self.bot = bot stats.up('events', bot.name) bot.nrevents += 1 rawstr = rawstr.rstrip() splitted = re.split('\s+', rawstr) # check if there is a prefix (: in front) if not rawstr[0] == ':': # no prefix .. 1st word is command splitted.insert(0, ":none!none@none") rawstr = ":none!none@none " + rawstr self.prefix = splitted[0][1:] # get nick/userhost nickuser = self.prefix.split('!') if len(nickuser) == 2: self.nick = nickuser[0] stats.up('events', self.nick) if self.bot.cfg['stripident'] or config['stripident']: self.userhost = stripident(nickuser[1]) else: self.userhost = nickuser[1] # set command self.cmnd = splitted[1] stats.up('events', self.cmnd) # split string based of postfix count .. nr of items ater the command if pfc.has_key(self.cmnd): self.arguments = splitted[2:pfc[self.cmnd]+2] txtsplit = re.split('\s+', rawstr, pfc[self.cmnd]+2) self.txt = txtsplit[-1] else: self.arguments = splitted[2:] # 1st argument is target if self.arguments: self.target = self.arguments[0] self.postfix = ' '.join(self.arguments) # check if target is text if self.target and self.target.startswith(':'): self.txt = ' '.join(self.arguments) # strip strarting ':' from txt if self.txt: if self.txt[0] == ":": self.txt = self.txt[1:] rlog(0, 'ircevent',"%s %s %s" % (self.cmnd, self.arguments, self.txt)) # set ircevent attributes if self.cmnd == 'PING': self.speed = 10 if self.cmnd == 'PRIVMSG': self.channel = self.arguments[0] elif self.cmnd == 'JOIN' or self.cmnd == 'PART': if self.arguments: self.channel = self.arguments[0] else: self.channel = self.txt elif self.cmnd == 'MODE': self.channel = self.arguments[0] elif self.cmnd == 'TOPIC': self.channel = self.arguments[0] elif self.cmnd == 'KICK': self.channel = self.arguments[0] elif self.cmnd == '353': self.channel = self.arguments[2] elif self.cmnd == '324': self.channel = self.arguments[1] if self.userhost: # userhost before possible stripident self.ruserhost = self.userhost # jabber compat .. this is userhost on irc self.stripped = self.userhost # determine user self.user = stripident(self.userhost).split('@')[0] self.origtxt = self.txt self.channel = self.channel.strip() stats.up('events', self.channel) self.origchannel = self.channel rlog(-1, 'ircevent', self) # show error try: nr = int(self.cmnd) if nr > 399: rlog(10, bot.name + '.error', '%s: %s %s' % (self.cmnd, \ self.arguments, self.txt)) except ValueError: pass return self