Example #1
0
 def make_event(self,
                origin,
                channel,
                txt,
                event=None,
                wait=0,
                showall=False,
                nooutput=False,
                cbtype=""):
     """ insert an event into the callbacks chain. """
     if event: e = cpy(event)
     else: e = EventBase(bot=self)
     e.cbtype = cbtype or "CMND"
     e.origin = origin or "test@test"
     e.auth = e.origin
     e.userhost = e.origin
     e.channel = channel
     if 'socket' in repr(channel): e.socket = channel
     e.txt = unicode(txt)
     e.nick = (event and event.nick) or stripident(e.userhost.split('@')[0])
     e.showall = showall
     e.nooutput = nooutput
     e.wait = wait
     e.closequeue = False
     e.bind(self)
     return e
Example #2
0
File: users.py Project: code2u/jsb
 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
Example #3
0
File: users.py Project: code2u/jsb
 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
Example #4
0
 def make_event(self, origin, channel, txt, event=None, wait=0, showall=False, nooutput=False, cbtype=""):
     """ insert an event into the callbacks chain. """
     if event: e = cpy(event)
     else: e = EventBase(bot=self)
     e.cbtype = cbtype or "CMND"
     e.origin = origin or "test@test"
     e.auth = e.origin
     e.userhost = e.origin
     e.channel = channel
     if 'socket' in repr(channel): e.socket = channel
     e.txt = unicode(txt)
     e.nick = (event and event.nick) or stripident(e.userhost.split('@')[0])
     e.showall = showall
     e.nooutput = nooutput
     e.wait = wait
     e.closequeue = False
     e.bind(self)
     return e
Example #5
0
 def parse(self, bot, rawstr):
     """ parse raw string into ircevent. """
     self.bottype = "irc"
     self.bot = bot
     self.ttl = 2
     self.speed = 4
     rawstr = rawstr.rstrip()
     splitted = re.split('\s+', rawstr)
     if not rawstr[0] == ':':
         assert bot.cfg
         splitted.insert(
             0, u":%s!%s@%s" %
             (bot.cfg.nick, bot.cfg.username, bot.cfg.server))
         rawstr = u":%s!%s@%s %s" % (bot.cfg.nick, bot.cfg.username,
                                     bot.cfg.server, rawstr)
     self.prefix = splitted[0][1:]
     nickuser = self.prefix.split('!')
     try:
         self.userhost = nickuser[1]
         self.nick = stripident(nickuser[0])
     except IndexError:
         self.userhost = None
         self.nick = None
         self.isservermsg = True
     self.cmnd = splitted[1]
     self.cbtype = self.cmnd
     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:]
     if self.arguments: self.target = self.arguments[0]
     self.postfix = ' '.join(self.arguments)
     if self.target and self.target.startswith(':'):
         self.txt = ' '.join(self.arguments)
     if self.txt:
         if self.txt[0] == ":": self.txt = self.txt[1:]
         if self.txt: self.usercmnd = self.txt.split()[0]
     if self.cmnd == 'PING': self.speed = 9
     if self.cmnd == 'PRIVMSG':
         self.channel = self.arguments[0]
         if '\001' in self.txt: self.isctcp = True
     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:
         self.ruserhost = self.userhost
         self.stripped = self.userhost
         self.auth = self.userhost
         try:
             self.hostname = self.userhost.split("@")[1]
         except:
             self.hostname = None
     self.origtxt = self.txt
     if self.channel:
         self.channel = self.channel.strip()
         self.origchannel = self.channel
         if self.channel == self.bot.cfg.nick:
             logging.warn("irc - msg detected - setting channel to %s" %
                          self.userhost)
             self.msg = True
             self.channel = self.userhost
     if not self.channel:
         for c in self.arguments:
             if c.startswith("#"): self.channel = c
     try:
         nr = int(self.cmnd)
         if nr > 399 and not nr == 422:
             logging.error(
                 '%s - %s - %s - %s' %
                 (self.bot.cfg.name, self.cmnd, self.arguments, self.txt))
     except ValueError:
         pass
     self.prepare()
     return self