def db_try_delete_device(device: Device) -> bool: where = util.db_get_where_string('key', device.key, is_text_type=True) query = f'DELETE FROM devices WHERE {where}' success = core.db_try_execute(query) if success: DEVICES.remove_device_by_key(device.key) return success
async def test(ctx, action, *, params): print(f'+ called command test(ctx, {action}, {params}) by {ctx.author}') if action == 'utcnow': utcnow = util.get_utcnow() txt = util.get_formatted_datetime(utcnow) await ctx.send(txt) elif action == 'init': core.init_db() await ctx.send('Initialized the database from scratch') await util.try_delete_original_message(ctx) elif (action == 'select' or action == 'selectall') and params: query = f'SELECT {params}' result, error = core.db_fetchall(query) if error: await ctx.send(error) elif result: await ctx.send(result) else: await ctx.send('The query didn\'t return any results.') elif action == 'query' and params: query = f'{params}' success, error = core.db_try_execute(query) if not success: await ctx.send(error) else: await ctx.send( f'The query \'{params}\' has been executed successfully.')
def _db_update_server_setting(guild_id: int, settings: dict) -> bool: where = util.db_get_where_string('guildid', guild_id, is_text_type=True) set_string = ', '.join( [f'{key} = {value}' for key, value in settings.items()]) query = f'UPDATE serversettings SET {set_string} WHERE {where}' success = core.db_try_execute(query) return success
def db_create_server_settings(guild_id: int) -> bool: if db_get_has_settings(guild_id): return True else: query = f'INSERT INTO serversettings (guildid, dailydeleteonchange) VALUES ({guild_id}, {util.db_convert_boolean(True)})' success = core.db_try_execute(query) return success
def update_daily_channel(guild_id, channel_id=None, can_post=True): query = 'UPDATE daily SET ' if channel_id != None: query += 'channelid = \'{}\', '.format(channel_id) query += 'canpost = {} WHERE guildid = \'{}\''.format( convert_can_post(can_post), guild_id) success = core.db_try_execute(query) return success
def _db_try_update_device(device: Device) -> bool: key = util.db_convert_text(device.key) checksum = util.db_convert_text(device.checksum) can_login_until = util.db_convert_timestamp(device.can_login_until) where = util.db_get_where_string('key', device.key, is_text_type=True) query = f'UPDATE devices SET (key, checksum, loginuntil) = ({key}, {checksum}, {can_login_until}) WHERE {where}' success = core.db_try_execute(query) return success
def _db_try_create_device(device: Device) -> bool: db_key = util.db_convert_text(device.key) db_checksum = util.db_convert_text(device.checksum) db_login_until = util.db_convert_timestamp(device.can_login_until) query = f'INSERT INTO devices VALUES ({db_key}, {db_checksum}, {db_login_until})' success = core.db_try_execute(query) if success: DEVICES.add_device_by_key(device.key) return success
def insert_daily_channel(guild_id, channel_id): query = 'INSERT INTO daily (guildid, channelid, canpost) VALUES ({},{},TRUE)'.format( guild_id, channel_id) success = core.db_try_execute(query) return success
def delete_daily_channel(guild_id): query = 'DELETE FROM daily WHERE guildid = \'{}\''.format(guild_id) success = core.db_try_execute(query) return success
def db_delete_server_settings(guild_id: int) -> bool: where = util.db_get_where_string('guildid', guild_id, is_text_type=True) query = f'DELETE FROM serversettings WHERE {where}' success = core.db_try_execute(query) return success