Ejemplo n.º 1
0
  def _connect(self,host,port,login,password,delay):
    self.host=host
    self.port=port
    self.login=login
    self.password=password
    self.line_delay=delay

    log_info('Connecting to IRC at %s:%u' % (host, port))
    self.last_send_time=0
    self.last_ping_time = time.time()
    self.quitting = False
    self.buffered_data = ""
    self.userstable=dict()
    self.registered_users=set()
    try:
      self.irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
      if self.use_ssl:
        try:
          raise RuntimeError('')
          self.irc_ssl_context = ssl.create_default_context()
          self.sslirc = self.irc_ssl_context.wrap_socket(self.irc, host)
          self.sslirc.connect ( ( host, port ) )
        except Exception,e:
          log_warn('Failed to create SSL context, using fallback code: %s' % str(e))
          self.irc.connect ( ( host, port ) )
          self.sslirc = socket.ssl(self.irc)
    except Exception, e:
      log_error( 'Error initializing IRC: %s' % str(e))
      return False
Ejemplo n.º 2
0
    def _connect(self, host, port, login, password, delay):
        self.host = host
        self.port = port
        self.login = login
        self.password = password
        self.line_delay = delay

        log_info('Connecting to IRC at %s:%u' % (host, port))
        self.last_send_time = 0
        self.last_ping_time = time.time()
        self.quitting = False
        self.buffered_data = ""
        self.userstable = dict()
        self.registered_users = set()
        try:
            self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            if self.use_ssl:
                try:
                    raise RuntimeError('')
                    self.irc_ssl_context = ssl.create_default_context()
                    self.sslirc = self.irc_ssl_context.wrap_socket(
                        self.irc, host)
                    self.sslirc.connect((host, port))
                except Exception, e:
                    log_warn(
                        'Failed to create SSL context, using fallback code: %s'
                        % str(e))
                    self.irc.connect((host, port))
                    self.sslirc = socket.ssl(self.irc)
        except Exception, e:
            log_error('Error initializing IRC: %s' % str(e))
            return False
Ejemplo n.º 3
0
def DisableWithdraw(link, cmd):
    global withdraw_disabled
    if link:
        log_warn('DisableWithdraw: disabled by %s' % link.identity())
    else:
        log_warn('DisableWithdraw: disabled')
    withdraw_disabled = True
Ejemplo n.º 4
0
def DisableWithdraw(link,cmd):
  global withdraw_disabled
  if link:
    log_warn('DisableWithdraw: disabled by %s' % link.identity())
  else:
    log_warn('DisableWithdraw: disabled')
  withdraw_disabled = True
Ejemplo n.º 5
0
 def update(self):
   try:
     data=self._getline()
   except Exception,e:
     log_warn('Exception from IRCNetwork:_getline, we were probably disconnected, reconnecting in %s seconds' % self.timeout_seconds)
     time.sleep(5)
     self.last_ping_time = time.time()
     self._reconnect()
     return True
Ejemplo n.º 6
0
 def _parse(self,item,is_pm):
   if not hasattr(item,'author'):
     return
   if not hasattr(item.author,'name'):
     log_warn('author of %s has no name field, ignored' % str(item.id))
     try:
       item.mark_as_read()
     except Exception,e:
       log_warning('Failed to mark %s as read: %s' % (item.id,str(e)))
     return
Ejemplo n.º 7
0
def GetIdentityFromPaymentID(p):
  if not redis_hexists("paymentid",p):
    log_log('PaymentID %s not found' % p)
    return None
  identity = redis_hget("paymentid",p)
  log_log('PaymentID %s => %s' % (p, str(identity)))
  # HACK - grandfathering pre-network payment IDs
  if identity.index(':') == -1:
    log_warn('Pre-network payment ID found, assuming freenode')
    identity = "freenode:"+identity
  return identity
Ejemplo n.º 8
0
def GetIdentityFromPaymentID(p):
    if not redis_hexists("paymentid", p):
        log_log('PaymentID %s not found' % p)
        return None
    identity = redis_hget("paymentid", p)
    log_log('PaymentID %s => %s' % (p, str(identity)))
    # HACK - grandfathering pre-network payment IDs
    if identity.index(':') == -1:
        log_warn('Pre-network payment ID found, assuming freenode')
        identity = "freenode:" + identity
    return identity
Ejemplo n.º 9
0
 def update(self):
     try:
         data = self._getline()
     except Exception, e:
         log_warn(
             'Exception from IRCNetwork:_getline, we were probably disconnected, reconnecting in %s seconds'
             % self.timeout_seconds)
         time.sleep(5)
         self.last_ping_time = time.time()
         self._reconnect()
         return True
Ejemplo n.º 10
0
 def _parse(self,item,is_pm):
   if not hasattr(item,'author'):
     return
   if not hasattr(item.author,'name'):
     log_warn('author of %s has no name field, ignored' % str(item.id))
     if True:
       try:
         item.mark_read()
       except Exception,e:
         log_warn('Failed to mark %s as read: %s' % (item.id,str(e)))
     return
Ejemplo n.º 11
0
        return time.time() - self.known[nick] if nick in self.known else 0

    def update(self):
        try:
            data = self._getline()
        except Exception, e:
            log_warn(
                'Exception from IRCNetwork:_getline, we were probably disconnected, reconnecting in %s seconds'
                % self.timeout_seconds)
            time.sleep(5)
            self.last_ping_time = time.time()
            self._reconnect()
            return True
        if data == None:
            if time.time() - self.last_ping_time > self.timeout_seconds:
                log_warn('%s seconds without PING, reconnecting in 5 seconds' %
                         self.timeout_seconds)
                time.sleep(5)
                self.last_ping_time = time.time()
                self._reconnect()
            return True

        data = data.strip("\r\n")
        self._log_IRCRECV(data)

        # consider any IRC data as a ping
        self.last_ping_time = time.time()

        if data.find(self.welcome_line) != -1:
            self.userstable = dict()
            self.registered_users.clear()
            if not self.use_sasl:
Ejemplo n.º 12
0
    if re.match("%s[\t ]*[:,]?$"%config.tipbot_name, s):
      return True
    return False

  def update(self):
    try:
      data=self._getline()
    except Exception,e:
      log_warn('Exception from IRCNetwork:_getline, we were probably disconnected, reconnecting in %s seconds' % self.timeout_seconds)
      time.sleep(5)
      self.last_ping_time = time.time()
      self._reconnect()
      return True
    if data == None:
      if time.time() - self.last_ping_time > self.timeout_seconds:
        log_warn('%s seconds without PING, reconnecting in 5 seconds' % self.timeout_seconds)
        time.sleep(5)
        self.last_ping_time = time.time()
        self._reconnect()
      return True

    data = data.strip("\r\n")
    self._log_IRCRECV(data)

    # consider any IRC data as a ping
    self.last_ping_time = time.time()

    if data.find ( self.welcome_line ) != -1:
      self.userstable = dict()
      self.registered_users.clear()
      if not self.use_sasl:
Ejemplo n.º 13
0
                    log_warn('Failed to mark %s as read: %s' %
                             (item.id, str(e)))
            return

        author = self.canonicalize(item.author.name)
        if author and author == self.canonicalize(self.login):
            return

        if item.id in self.last_seen_ids:
            log_log('Already seen %s %.1f hours ago by %s: %s (%s), skipping' %
                    (item.id, age / 3600, str(author), repr(title),
                     repr(item.body)))
            try:
                item.mark_read()
            except Exception, e:
                log_warn('Failed to mark %s as read: %s' % (item.id, str(e)))
            return

        age = time.time() - item.created_utc
        ts = long(float(item.created_utc))
        title = item.link_title if hasattr(item, 'link_title') else None

        log_log(
            'Parsing new item %s from %.1f hours ago by %s: %s (%s)' %
            (item.id, age / 3600, str(author), repr(title), repr(item.body)))
        self.last_seen_ids.add(item.id)
        redis_sadd('reddit:last_seen_ids', item.id)

        if is_pm or item.body.lower().find(self.keyword.lower()) >= 0:
            group = None
            #if not is_pm and hasattr(item,'subreddit'):