Пример #1
0
 def on_notice(self,who,text):
   if who == "NickServ!NickServ@services.":
     if text.find(' ACC ') != -1:
       stext  = text.split(' ')
       ns_nick = stext[0]
       ns_acc = stext[1]
       ns_status = stext[2]
       if ns_acc == "ACC":
         ns_link=Link(self,User(self,ns_nick),None)
         if ns_status == "3":
           log_info('NickServ says %s is identified' % ns_nick)
           self.registered_users.add(ns_link.identity())
           if self.on_identified:
             self.on_identified(ns_link,True)
         else:
           log_info('NickServ says %s is not identified' % ns_nick)
           self.registered_users.discard(ns_link.identity())
           if self.on_identified:
             self.on_identified(ns_link,False)
       else:
         log_error('ACC line not as expected...')
   return True
Пример #2
0
 def on_notice(self,who,text):
   if who == "NickServ!NickServ@services.":
     if text.find(' ACC ') != -1:
       stext  = text.split(' ')
       ns_nick = stext[0]
       ns_acc = stext[1]
       ns_status = stext[2]
       if ns_acc == "ACC":
         ns_link=Link(self,User(self,ns_nick),None)
         if ns_status == "3":
           log_info('NickServ says %s is identified' % ns_nick)
           self.registered_users.add(ns_link.identity())
           if self.on_identified:
             self.on_identified(ns_link,True)
         else:
           log_info('NickServ says %s is not identified' % ns_nick)
           self.registered_users.discard(ns_link.identity())
           if self.on_identified:
             self.on_identified(ns_link,False)
       else:
         log_error('ACC line not as expected...')
   return True
Пример #3
0
  def _parse_dm(self,msg):
    if msg.sender.screen_name.lower() == self.login.lower() and not force_parse_self:
      log_log('Ignoring DM from self')
      return

    log_info('Twitter: parsing DM from %s: %s' % (msg.sender.screen_name,msg.text))
    link=Link(self,User(self,msg.sender.screen_name),None,None)
    for line in msg.text.split('\n'):
      exidx=line.find('!')
      if exidx!=-1 and len(line)>exidx+1 and line[exidx+1] in string.ascii_letters and self.is_acceptable_command_prefix(line[:exidx]):
        cmd=line[exidx+1:].split(' ')
        cmd[0] = cmd[0].strip(' \t\n\r')
        log_info('Found command from %s: %s' % (link.identity(), str(cmd)))
        if self.on_command:
          self.on_command(link,cmd)
Пример #4
0
    def _parse_dm(self, msg):
        if msg.sender.screen_name.lower() == self.login.lower(
        ) and not force_parse_self:
            log_log('Ignoring DM from self')
            return

        log_info('Twitter: parsing DM from %s: %s' %
                 (msg.sender.screen_name, msg.text))
        link = Link(self, User(self, msg.sender.screen_name), None, None)
        for line in msg.text.split('\n'):
            exidx = line.find('!')
            if exidx != -1 and len(line) > exidx + 1 and line[
                    exidx +
                    1] in string.ascii_letters and self.is_acceptable_command_prefix(
                        line[:exidx]):
                cmd = line[exidx + 1:].split(' ')
                cmd[0] = cmd[0].strip(' \t\n\r')
                log_info('Found command from %s: %s' %
                         (link.identity(), str(cmd)))
                if self.on_command:
                    self.on_command(link, cmd)
Пример #5
0
            group = None
            self.items_cache[item.fullname] = item
            link = Link(self, User(self, author), group, item)
            for line in item.body.split('\n'):
                if is_pm:
                    exidx = line.find('!')
                    if exidx != -1 and len(line) > exidx + 1 and line[
                            exidx +
                            1] in string.ascii_letters and self.is_acceptable_command_prefix(
                                line[:exidx]):
                        cmd = line[exidx + 1:].split(' ')
                        while '' in cmd:
                            cmd.remove('')
                        cmd[0] = cmd[0].strip(' \t\n\r')
                        log_info('Found command from %s: %s' %
                                 (link.identity(), str(cmd)))
                        if self.on_command:
                            self.on_command(link, cmd)

                else:
                    # reddit special: +x as a reply means tip
                    if not is_pm and hasattr(item, 'parent_id'):
                        if re.search(
                                "\+[0-9]*(\.[0-9]*)?[\t ]+" + self.keyword,
                                line) or re.search(
                                    self.keyword + "[\t ]+\+[0-9]*(\.[0-9]*)?",
                                    line):
                            line = line.replace(self.keyword, '').strip()
                            if self.on_command:
                                try:
                                    parent_item = next(
Пример #6
0
    if is_pm or item.body.lower().find(self.keyword.lower()) >= 0:
      group=None
      #if not is_pm and hasattr(item,'subreddit'):
      #  group=Group(self,item.subreddit.display_name)
      group = None
      self.items_cache[item.fullname]=item
      link=Link(self,User(self,author),group,item)
      for line in item.body.split('\n'):
        if is_pm:
          exidx=line.find('!')
          if exidx!=-1 and len(line)>exidx+1 and line[exidx+1] in string.ascii_letters and self.is_acceptable_command_prefix(line[:exidx]):
            cmd=line[exidx+1:].split(' ')
            while '' in cmd:
              cmd.remove('')
            cmd[0] = cmd[0].strip(' \t\n\r')
            log_info('Found command from %s: %s' % (link.identity(), str(cmd)))
            if self.on_command:
              self.on_command(link,cmd)

        else:
          # reddit special: +x as a reply means tip
          if not is_pm and hasattr(item,'parent_id'):
            if re.search("\+[0-9]*(\.[0-9]*)?[\t ]+"+self.keyword,line) or re.search(self.keyword+"[\t ]+\+[0-9]*(\.[0-9]*)?",line):
              line=line.replace(self.keyword,'').strip()
              if self.on_command:
                try:
                  parent_item=self.reddit.get_info(thing_id=item.parent_id)
                  if not hasattr(parent_item,'author'):
                    raise RuntimeError('Parent item has no author')
                  author=parent_item.author.name
                  match=re.search("\+[0-9]*(\.[0-9]*)?",line)
Пример #7
0
      link=Link(self,User(self,author),group,item)
      for line in item.body.split('\n'):
        if is_pm:
          exidx=line.find('!')
          if exidx!=-1 and len(line)>exidx+1 and line[exidx+1] in string.ascii_letters and self.is_acceptable_command_prefix(line[:exidx]):
            cmd=line[exidx+1:].split(' ')
            while '' in cmd:
              cmd.remove('')
            cmd[0] = cmd[0].strip(' \t\n\r')
            try:
              if cmd[0] == u'tip' and cmd[1][0:3] == u'/u/':
                log_info("Subbing out /u/ from username")
                cmd[1] = cmd[1][3:]
            except:
              pass
            log_info('Found command from %s: %s' % (link.identity(), str(cmd)))
            if self.on_command:
              self.on_command(link,cmd)

        else:
          # reddit special: +x as a reply means tip
          if not is_pm and hasattr(item,'parent_id'):
            if re.search("\+[0-9]*(\.[0-9]*)?[\t ]+"+self.keyword,line) or re.search(self.keyword+"[\t ]+\+[0-9]*(\.[0-9]*)?",line):
              line=line.replace(self.keyword,'').strip()
              if self.on_command:
                try:
                  parent_item=next(self.reddit.info([item.parent_id]))
                  if not hasattr(parent_item,'author'):
                    raise RuntimeError('Parent item has no author')
                  author=parent_item.author.name
                  match=re.search("\+[0-9]*(\.[0-9]*)?",line)