Example #1
0
async def quotes(client, data):
    """main quote """
    conn = client.bot.dbs[data.server]
    message = data.split_message

    tables = db.get_table_names(conn)
    if 'quotes' not in tables:
        asyncio.create_task(
            client.message(
                data.target,
                ('Quote table uninitialized. Please ask your nearest bot'
                 'admin to run .qinit.')))

    if message[0] == 'add':
        quotedata = (data.target, message[1], data.nickname,
                     ' '.join(message[2:]), int(time.time()), '0')
        db.set_row(conn, 'quotes', quotedata)
        asyncio.create_task(client.message(data.target, 'Quote added.'))
        db.ccache()
        return
    elif message[0] == 'del':
        quotes = db.get_row(conn, 'quotes', 'nick', data.nickname)

        try:
            numarg = int(message[1])
            if numarg > 0:
                numarg -= 1
        except ValueError:
            asyncio.create_task(
                client.message(
                    data.target,
                    'You need to use a number when deleting quotes.'))
            return

        quotes = _remove_quotes(quotes)
        if len(quotes) > 0:
            try:
                # get quote to delete
                quote = quotes[numarg]
            except ValueError:
                asyncio.create_task(
                    client.message(
                        data.target,
                        f'You only have {str(len(quotes))} quote(s).'))
                return
            cur = conn.cursor()
            cur.execute("UPDATE quotes SET deleted='1' WHERE msg=? AND time=?",
                        (quote[3], quote[4]))
            del cur
            conn.commit()
            db.ccache()
            asyncio.create_task(client.message(data.target, 'Quote deleted.'))

            return
        else:
            asyncio.create_task(
                client.message(data.target, 'You have no quotes.'))
            return
    else:
        _search_quotes(client, data, conn, message)
Example #2
0
def _show_user_recent_tells(client, conn, recipient, show_only_unseen):
    tells = db.get_row(conn, 'tells', 'nick', recipient)
    # small sanity check

    if len(tells) <= 0:
        if show_only_unseen is False:
            asyncio.create_task(client.notice(recipient, 'You have no pending tells.'))
        return

    # sort tells
    tells.sort(key=_get_tell_time, reverse=True)

    # limit tells
    if len(tells) > tell_limit:
        tells = tells[0:tell_limit]

    if show_only_unseen is True:

        unseen_tell_found = 0

        for tell in tells:
            if str(tell[4]) == '0':
                if unseen_tell_found == 0:
                    asyncio.create_task(client.notice(recipient, 'You have new tells!'))
                    unseen_tell_found = 1

                _set_tell_seen(conn, tell)
                _send_tell_notice(client, recipient, tell)

    else:
        asyncio.create_task(client.notice(recipient, 'Here are your recent tells:'))
        for tell in tells:
            _set_tell_seen(conn, tell)
            _send_tell_notice(client, recipient, tell)
Example #3
0
def _check_reminder_exists(conn, reminder_name):

    rem_row = db.get_row(conn, 'reminders', 'name', reminder_name)

    if len(rem_row) == 0:
        return False
    else:
        return True
Example #4
0
async def cleartells(client, data):
    conn = client.bot.dbs[data.server]
    tells = db.get_row(conn, 'tells', 'nick', data.nickname.lower())
    
    for tell in tells:
        print(f'TELL_DEBUG: manual tell delete {tell[0]} {tell[2]} {tell[3]} {tell[5]}')
        _delete_tell(conn, tell)
    
    asyncio.create_task(client.notice(data.nickname, 'Your tells have been deleted.'))
Example #5
0
def _get_lastfm_nick(conn, irc_nick):
    names = db.get_column_names(conn, 'users')

    nicks = db.get_row(conn, 'users', 'nick', irc_nick)
    try:
        for i, name in enumerate(names):
            if name == 'lastfm':
                if nicks[0][i] == '':
                    return None
                else:
                    return nicks[0][i]
    except IndexError:
        return None
Example #6
0
def _get_reminder_text(conn, reminder_name):
    """Finds reminder text if reminder has any"""

    out = ''

    rem_row = db.get_row(conn, 'reminders', 'name', reminder_name)

    if len(rem_row) == 0:
        return out
    else:
        print(f'REMINDER_DEBUG: {rem_row}')
        out = rem_row[0][1]
        return out
Example #7
0
def _search_quotes(client, data, conn, message):
    if len(message) > 0 and len(data.message) > 0:

        if data.message[0] == '#':
            chansornicks = db.get_column(conn, 'channels', 'channel')
            quotes = db.get_row(conn, 'quotes', 'chan', message[0])
        else:
            print(message, data.message)
            if data.message[0] == '@':
                message[0] = message[0][1:]
                data.message = data.message[1:]
            print(message, data.message)
            chansornicks = db.get_column(conn, 'quotes', 'nick')
            quotes = db.get_row(conn, 'quotes', 'nick', message[0])
        argtuple = (message[0], )
        if argtuple in chansornicks:
            try:
                _display_quote(client, data, quotes, message[0], message[1])
            except IndexError:
                _display_quote(client, data, quotes, message[0], None)
        else:
            asyncio.create_task(
                client.message(data.target,
                               f'No quotes found for {message[0]}.'))
Example #8
0
async def quotes(client, data):
    """main quote hook"""
    conn = client.bot.dbs[data.server]
    split = data.message.split()

    tables = db.get_table_names(conn)
    if 'quotes' not in tables:
        asyncio.create_task(
            client.message(
                data.target,
                'Quote table uninitialized. Please ask your nearest bot admin to run .qinit.'
            ))

    #TODO: fix weird ass edgecase with users when a nick that corresponds to a command

    if len(split) > 1:
        if split[0] == 'add' or split[0] == 'a':
            nick = split[1].lower()

            quote = ' '.join(split[2:])
            quotedata = (
                data.target,
                nick,
                data.nickname,
                quote,
                int(time.time()),
                '0',
            )
            db.set_row(conn, 'quotes', quotedata)
            asyncio.create_task(client.notice(data.nickname, 'Quote added.'))
            db.ccache()
            return

        elif split[0] == 'delete' or split[0] == 'r' or split[0] == 'remove':
            nickquotes = db.get_row(conn, 'quotes', 'nick',
                                    data.nickname.lower())
            numarg = None

            try:
                numarg = int(split[1])
                if numarg > 0:
                    numarg -= 1
            except:
                asyncio.create_task(
                    client.message(
                        data.target,
                        'You need to use a number when deleting quotes.'))
                return

            nickquotes = remove_quotes(nickquotes)
            if len(nickquotes) > 0:
                try:
                    #get quote to delete
                    quote = nickquotes[numarg]
                except:
                    if len(nickquotes) == 1:
                        asyncio.create_task(
                            client.message(data.target,
                                           'You only have 1 quote.'))
                    else:
                        asyncio.create_task(
                            client.message(
                                data.target,
                                f'You only have {str(len(nickquotes))} quote(s).'
                            ))
                    return
                """gotta do custom query since i couldn't find anything in db.py that suits my needs.
                i'm using both the time and the quote itself because it's the quickest sure way to know that that quote is unique
                afaik it's very unlikely that the bot is fast enough to process two or more inputs within a second
                """

                cur = conn.cursor()
                cur.execute(
                    "UPDATE quotes SET deleted='1' WHERE msg=? AND time=?",
                    (quote[3], quote[4]))
                del cur
                conn.commit()
                db.ccache()
                asyncio.create_task(
                    client.notice(data.nickname, 'Quote deleted.'))

                return
            else:
                asyncio.create_task(
                    client.message(data.target, 'You have no quotes.'))
                return

    if len(split) > 0 and len(data.message) > 0:
        argtuple = split[0].lower(),

        #convert split[0] (we now know that it needs to be compared with a db) into a tuple, since we get db results in a tuple

        if data.message[0] == '#':
            channels = db.get_column(conn, 'channels', 'channel')

            if argtuple in channels:
                chanquotes = db.get_row(conn, 'quotes', 'chan',
                                        split[0].lower())
                try:
                    display_quote(client, data, chanquotes, split[0], split[1])
                except:
                    display_quote(client, data, chanquotes, split[0], None)

            else:
                asyncio.create_task(
                    client.message(data.target,
                                   f'No quotes found for {split[0]}.'))
        else:
            users = db.get_column(conn, 'quotes', 'nick')

            if argtuple in users:
                print(split[0])
                print(split[0].lower())
                nickquotes = db.get_row(conn, 'quotes', 'nick',
                                        split[0].lower())
                try:
                    display_quote(client, data, nickquotes, split[0], split[1])
                except:
                    display_quote(client, data, nickquotes, split[0], None)
            else:
                asyncio.create_task(
                    client.message(data.target,
                                   f'No quotes found for {split[0]}.'))