Example #1
0
def link_del(message, from_id, bacon):
    match = links_del_matcher.match(message)
    url = match.group(1)

    user_id = bacon.sqlite.execute(
        'SELECT user_id FROM users WHERE jid=?', (jid_to_userhost(from_id),)).fetchone()[0]
    bacon.sqlite.execute(
        'DELETE FROM plugin_links WHERE user_id=? AND url=?', (user_id, url))
    return "URL %s removed." % url
Example #2
0
def link_list(message, from_id, bacon):
    user_id = bacon.sqlite.execute(
        'SELECT user_id FROM users WHERE jid=?', (jid_to_userhost(from_id),)).fetchone()[0]
    urls = bacon.sqlite.execute(
        'SELECT url, tags FROM plugin_links WHERE user_id=? ORDER BY -time',
        (user_id,)).fetchall()
    return_str = ""
    for url in urls:
        return_str += "%s  Tags: %s\n" % (url[0], url[1])
    return return_str
Example #3
0
def link_search(message, from_id, bacon):
    match = links_search_matcher.match(message)
    tags = match.group(1).split()

    user_id = bacon.sqlite.execute(
        'SELECT user_id FROM users WHERE jid=?', (jid_to_userhost(from_id),)).fetchone()[0]

    return_str = ""
    used_urls = []
    for tag in tags:
        urls = bacon.sqlite.execute(
        'SELECT url, tags FROM plugin_links WHERE user_id=? AND tags LIKE ?', (user_id, "%%%s%%" % tag,)).fetchall()
        for url in urls:
            if url not in used_urls:
                return_str += "%s  Tags: %s\n" % (url[0], url[1])
                used_urls.append(url)
                
    if return_str == "":
        return "No results."
    else:
        return return_str
Example #4
0
def link(message, from_id, bacon):
    matches = url_matcher.match(message)
    url = matches.group(1)
    tags = matches.group(2)
        
    user_id = bacon.sqlite.execute(
        'SELECT user_id FROM users WHERE jid=?', (jid_to_userhost(from_id),)).fetchone()[0]

    if len(bacon.sqlite.execute(
        'SELECT link_id FROM plugin_links WHERE user_id=? AND url=?',
        (user_id, url)).fetchall()) == 0:

        # Insert if it doesn't exist
        bacon.sqlite.execute(
            'INSERT INTO plugin_links (url, tags, user_id, time) VALUES (?, ? ,? ,?)',
            (url, tags, user_id, time.time()))
    else:
        bacon.sqlite.execute(
            'UPDATE plugin_links SET tags=?, time=?', (tags, time.time()))

    #logging.debug("Link: Saving link %s, for user %s. Tags: %s" % (url, user_id, tags))
    
    return "URL %s added." % url