Esempio n. 1
0
 def get_users(self, chan):
     nicks = []
     if not chan in self.userstable:
         return []
     for nick in self.userstable[chan]:
         nicks.append(Link(self, User(self, nick), Group(self, chan)))
     return nicks
Esempio n. 2
0
 def get_active_users(self, seconds, chan):
     nicks = []
     if not chan in self.userstable:
         return []
     now = time.time()
     for nick in self.userstable[chan]:
         t = self.userstable[chan][nick]
         if t == None:
             continue
         dt = now - t
         if dt < 0:
             log_error(
                 "IRCNetwork:get_active_users: %s active in %s in the future"
                 % (nick, chan))
             continue
         if dt < seconds:
             nicks.append(Link(self, User(self, nick), Group(self, chan)))
     return nicks
Esempio n. 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)
Esempio n. 4
0
    def _parse_tweet(self, msg):
        if msg.user.screen_name.lower() == self.login.lower(
        ) and not force_parse_self:
            log_log('Ignoring tweet from self')
            return

        log_info('Twitter: parsing tweet from %s: %s' %
                 (msg.user.screen_name, msg.text))

        # twitter special: +x means tip the user mentioned with a @
        for line in msg.text.split('\n'):
            line = line.lower()
            line = line.replace(self.keyword, '', 1).strip()
            log_log('After removal: %s' % line)
            if re.match(username_regexp + "[ \t]*" + amount_regexp,
                        line) or re.match(
                            amount_regexp + "[ \t]*" + username_regexp, line):
                link = Link(self, User(self, msg.user.screen_name), None, msg)
                match = re.search(username_regexp, line)
                if not match:
                    continue
                target = match.group(0)
                match = re.search(amount_regexp,
                                  line.replace(target, '').strip())
                if not match:
                    continue
                amount = match.group(0)
                if self.on_command:
                    try:
                        synthetic_cmd = [
                            'tip',
                            target.replace('@', '').strip(),
                            amount.replace('+', '').strip()
                        ]
                        log_log('Running synthetic command: %s' %
                                (str(synthetic_cmd)))
                        self.on_command(link, synthetic_cmd)
                    except Exception, e:
                        log_error('Failed to tip %s: %s' % (target, str(e)))
Esempio n. 5
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
Esempio n. 6
0
        account = GetAccount(identity)
        balance = redis_hget("balances", account)
        if balance == None:
            balance = 0
        balance = long(balance)
        if units > balance:
            link.send("You only have %s" % (AmountToString(balance)))
            return

        userlist = link.network.get_users(group.name)
        log_log("users in %s: %s" %
                (group.name, str([user.identity() for user in userlist])))
        userlist.remove(link)
        for n in config.no_rain_to_nicks:
            i = IdentityFromString(link, n)
            l = Link(link.network, User(link.network, NickFromIdentity(i)),
                     group)
            if l in userlist:
                userlist.remove(l)
        if users == None or users > len(userlist):
            users = len(userlist)
            everyone = True
        else:
            everyone = False
        if users == 0:
            link.send("Nobody eligible for rain")
            return
        if units < users:
            link.send("This would mean not even an atomic unit per nick")
            return
        log_info("%s wants to rain %s on %s users in %s" %
Esempio n. 7
0
 def add_known(self, nick):
     self.known[nick] = time.time()
     self.registered_users.discard(
         Link(self, User(self, nick), None).identity())
     log_info("now known: " + Link(self, User(self, nick), None).identity())
Esempio n. 8
0
 def evict_known(self, nick):
     del self.known[nick]
     self.registered_users.discard(
         Link(self, User(self, nick), None).identity())
     log_info("now unknown: " +
              Link(self, User(self, nick), None).identity())
Esempio n. 9
0
                                who_chan_user = who_chan_user[1:]
                            self.userstable[who_chan][who_chan_user] = None
                        self.add_known(who_chan_user)
                    log_log("New list of users in %s: %s" %
                            (who_chan, str(self.userstable[who_chan].keys())))
                except Exception, e:
                    log_error('Failed to parse "353" line: %s: %s' %
                              (data, str(e)))

            elif action == 'PRIVMSG':
                self.update_last_active_time(chan, GetNick(who))
                # resplit to avoid splitting text that contains ':'
                text = data.split(' :', 1)[1]
                if self.on_event:
                    self.on_event('message',
                                  link=Link(self, User(self,
                                                       GetNick(who), who),
                                            Group(self, chan)),
                                  message=text)
                exidx = text.find('!')
                if exidx != -1 and len(text) > exidx + 1 and text[
                        exidx +
                        1] in string.ascii_letters and self.is_acceptable_command_prefix(
                            text[:exidx]):
                    cmd = text.split('!')[1]
                    cmd = cmd.split(' ')
                    while '' in cmd:
                        cmd.remove('')
                    cmd[0] = cmd[0].strip(' \t\n\r')

                    log_log('Found command from %s: "%s" in channel "%s"' %
                            (who, str(cmd), str(chan)))
Esempio n. 10
0

def Ban(link, cmd):
    link.send("disabled")  # need to ban by ident
    return

    try:
        who = cmd[1]
    except Exception, e:
        link.send("usage: ban <nick>")
        return
    group = link.group
    if not group:
        link.send("Not in a channel")
        return
    l = Link(link.network, User(link.network, who), group)
    BanUser(l)


def Mute(link, cmd):
    link.send("disabled")  # need to mute by ident
    return

    try:
        who = cmd[1]
    except Exception, e:
        link.send("usage: mute <nick>")
        return
    group = link.group
    if not group:
        link.send("Not in a channel")
Esempio n. 11
0
        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'):
            #  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)