def _clear_reminder(conn, rem_name): """Is for appending to old reminders in the db""" db.set_cell(conn, 'reminders', 'msg', '', 'name', rem_name) db.set_cell(conn, 'reminders', 'last_updated', str(int(time.time())), 'name', rem_name) db.ccache()
async def inittell(client): """Is used to initialize the tell database""" conn = client.bot.dbs[client.server_tag] print (f'Initializing tell table in /persist/db/{client.server_tag}.db...') db.init_table(conn, 'tells', tell_columns) db.ccache() print ('Tell initialization complete.')
def _delete_tell(conn, tell): """ Is used to delete tells """ cur = conn.cursor() cur.execute('DELETE FROM tells WHERE msg=? AND time=? AND seen_time=?', (tell[2], tell[3], tell[5])) conn.commit() db.ccache()
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.'))
async def reminit(client): """Db init command, run once on startup""" conn = client.bot.dbs[client.server_tag] print(('Initializing reminder database table' f'in /persist/db/{client.server_tag}.db...')) db.init_table(conn, 'reminders', reminder_columns) db.ccache() print('Reminder initialization complete.')
async def quoteinit(client, data): """admin only quote db table initiation hook, since trying to init on every quote(even though the db functions account for that) is kinda wasteful""" conn = client.bot.dbs[data.server] print(f'Initializing quote table in /persist/db/{data.server}.db...') db.init_table(conn, 'quotes', quote_columns) db.ccache() print('Initialization complete.')
def _set_tell_seen(conn, tell): """ Is used to set a tell's status to seen """ if tell[4] == '1': return cur = conn.cursor() cur.execute("UPDATE tells SET seen='1', seen_time=? WHERE msg=? AND time=?", (str(int(time.time())), tell[2], tell[3])) del cur conn.commit() db.ccache()
def _append_reminder(conn, rem_name, rem_text): """Is for appending to old reminders in the db""" old_rem_text = _get_reminder_text(conn, rem_name) new_rem_text = f'{old_rem_text} and {rem_text}' rem_text_trunc = new_rem_text[:max_reminder_len] db.set_cell(conn, 'reminders', 'msg', rem_text_trunc, 'name', rem_name) db.set_cell(conn, 'reminders', 'last_updated', str(int(time.time())), 'name', rem_name) db.ccache()
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()