Example #1
0
def dinner(code, input):
    """fd -- WHAT DO YOU WANT FOR F*****G DINNER?"""
    err = '{red}EAT LEFT OVER PIZZA FOR ALL I CARE.'
    try:
        data = get(uri).read()
        results = re_mark.findall(data)
        if not results:
            return code.say(err)
        url, food = results[0][0], htmlescape(results[0][1])
        if hasattr(code.config, 'shortenurls'):
            if code.config.shortenurls:
                url = shorten(url)
        code.say('WHY DON\'T YOU EAT SOME F*****G {b}%s{b}. HERE IS THE RECIPE: %s' % (food.upper(), url))
    except:
        return code.say(err)
Example #2
0
def daemon(code, tc):
    while True:
        time.sleep(auto_check)

        # Here we do the work...
        for channel in tc:
            for tweet_item in tc[channel]:
                if tweet_item.startswith('#'):  # ID
                    data = get_tweets(uri_hash % urllib.quote(tweet_item))
                else:
                    data = get_tweets(uri_user % urllib.quote(tweet_item),
                                      tweet_item)
                if not data:
                    continue
                data = data[0]
                hash_str = hash(data['text'])
                db = database.get(code.nick, 'twitter')
                if not db:  # New data on new database, don't output anywhere..
                    database.set(code.nick, [hash_str], 'twitter')
                    continue
                if hash_str in db:
                    continue  # Same

                db.append(hash_str)
                database.set(code.nick, db, 'twitter')
                msg = format(data)
                if hasattr(code.config, 'shortenurls'):
                    if code.config.shortenurls:
                        urls = r_basicurl.findall(msg)
                        for url in urls:
                            msg = msg.replace(url, web.shorten(url))
                code.msg(channel, msg.decode('ascii', 'ignore'))
            db = database.get(code.nick, 'twitter')
            if db:
                if len(db) > 200:
                    db = db[-200:]
                    database.set(code.nick, db, 'twitter')
Example #3
0
File: irc.py Project: Csstform/Code
 def format(self, message, shorten_urls=True):
     '''
         formatting to support color/bold/italic/etc assignment
         and URL shortening in Codes responses
     '''
     message = uncharset(message)
     if self.config('shorten_urls') and shorten_urls:
         regex = re.compile(
             r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
             re.IGNORECASE).findall(message)
         for url in regex:
             try:
                 message = message.replace(url, shorten(url))
             except:
                 pass
     if not self.config('text_decorations'):
         return self.clear_format(message)
     try:
         for special in self.special_chars:
             message = message.replace('{%s}' %
                                       special, self.special_chars[special])
         return message
     except:
         return self.clear_format(message)
Example #4
0
File: irc.py Project: kamaal44/Code
 def format(self, message, shorten_urls=True):
     '''
         formatting to support color/bold/italic/etc assignment
         and URL shortening in Codes responses
     '''
     message = uncharset(message)
     if self.config('shorten_urls') and shorten_urls:
         regex = re.compile(
             r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
             re.IGNORECASE).findall(message)
         for url in regex:
             try:
                 message = message.replace(url, shorten(url))
             except:
                 pass
     if not self.config('text_decorations'):
         return self.clear_format(message)
     try:
         for special in self.special_chars:
             message = message.replace('{%s}' % special,
                                       self.special_chars[special])
         return message
     except:
         return self.clear_format(message)
Example #5
0
File: url.py Project: CHCMATT/Code
def get_title_auto(code, input):
    if input.startswith(code.prefix) or input.startswith('?'):
        return  # Prevent triggering of other plugins
    urls = re.findall('(?i)' + url_re, input)
    # If a user wants to spam... lets limit is to 3 URLs max, per line
    if len(urls) > 3:
        urls = urls[0:3]
    output = []
    for url in urls:
        # check to see if we should ignore this URL...
        if '.' not in url:
            break
        if url.startswith('.') or url.endswith('.'):
            break
        for bad in ignored:
            if bad.lower() in url.lower():
                skip = True
                break
            else:
                skip = False
        if skip:
            break
        # Lets get some data!
        data = get_url_data(url)
        if data:
            if hasattr(code.config, 'shortenurls'):
                if code.config.shortenurls:
                    url = web.shorten(url)
                else:
                    url = clean_url(url)
            else:
                url = clean_url(url)
            output.append('{blue}{b}%s{b}{c} - %s' % (web.uncharset(data), url))
    if not output:
        return
    return code.say(' | '.join(output))
Example #6
0
def daemon(code, tc):
    while True:
        time.sleep(auto_check)

        # Here we do the work...
        for channel in tc:
            for tweet_item in tc[channel]:
                if tweet_item.startswith('#'):  # ID
                    data = get_tweets(uri_hash % urllib.quote(tweet_item))
                else:
                    data = get_tweets(uri_user % urllib.quote(tweet_item), tweet_item)
                if not data:
                    continue
                data = data[0]
                hash_str = hash(data['text'])
                db = database.get(code.nick, 'twitter')
                if not db:  # New data on new database, don't output anywhere..
                    database.set(code.nick, [hash_str], 'twitter')
                    continue
                if hash_str in db:
                    continue  # Same

                db.append(hash_str)
                database.set(code.nick, db, 'twitter')
                msg = format(data)
                if hasattr(code.config, 'shortenurls'):
                    if code.config.shortenurls:
                        urls = r_basicurl.findall(msg)
                        for url in urls:
                            msg = msg.replace(url, web.shorten(url))
                code.msg(channel, msg.decode('ascii', 'ignore'))
            db = database.get(code.nick, 'twitter')
            if db:
                if len(db) > 200:
                    db = db[-200:]
                    database.set(code.nick, db, 'twitter')
Example #7
0
def format(tweet):
    return '{teal}(Twitter){c} %s ({purple}{b}@{b}%s{c}) - %s' % (tweet['text'], tweet['user'], web.shorten(tweet['url']))
Example #8
0
def format(tweet):
    return '{teal}(Twitter){c} %s ({purple}{b}@{b}%s{c}) - %s' % (
        tweet['text'], tweet['user'], web.shorten(tweet['url']))