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)
async def tell(client, data): """.tell - send a message to an user which is currently inactive""" conn = client.bot.dbs[data.server] split = data.split_message tables = db.get_table_names(conn) if 'tells' not in tables: asyncio.create_task( client.message( data.target, 'Tell table uninitialized, ask your nearest bot admin to restart the bot.' )) if len(split) > 1: recipient = split[0] recipient = recipient.lower() message = ' '.join(split[1:]) else: return telldata = (recipient, data.nickname, message, int(time.time()), '0', '0') db.set_row(conn, 'tells', telldata) db.ccache() asyncio.create_task( client.notice(data.nickname, 'Your message will be sent.'))
def _create_new_reminder(conn, rem_name, rem_text): """Is for creating new reminders in the db""" rem_text_trunc = rem_text[:max_reminder_len] rem_data = ( rem_name, rem_text_trunc, str(int(time.time())), str(int(time.time())), ) db.set_row(conn, 'reminders', rem_data) db.ccache()
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]}.'))