async def character_remove(bot, context): """Removes a character entry.""" clean_name = context.arguments[0].clean_name data.db_delete( bot, 'characters', where_arg='clean_name=%s AND owner_id=%s', input_args=(clean_name, context.author.id)) return Response(content="Character deleted.")
async def remove_text(bot, context): text_type, entry_id = context.arguments table_name = 'txyz_' + TYPE_NAMES[text_type] data.db_delete(bot, table_name, where_arg='key=%s', input_args=[entry_id], safe=False) return Response( content='Removed {} entry {}.'.format(table_name[5:-1], entry_id))
async def character_forceremove(bot, context): """Forcibly removes the character of the given user.""" owner = context.arguments[0] if data.is_mod(bot, member=owner): if not data.is_admin(bot, context.guild, context.author.id): raise CBException("Cannot remove characters of other bot moderators.") character_search = utilities.clean_text(context.arguments[1]) search_result = _user_character_search(bot, context.author, owner, character_search) character = search_result[1][search_result[0]] data.db_delete( bot, 'characters', where_arg='clean_name=%s AND owner_id=%s', input_args=(character.clean_name, owner.id)) return Response(content="Character forcefully deleted.")
async def awoo_reset(bot, context): """Removes the given user from the database.""" user = context.arguments[0] removed = data.db_delete(bot, 'awoo', where_arg='user_id=%s', input_args=[user.id]) if not removed: raise CBException("User not in violation database.") return Response(content="User removed from the database.")
async def _schedule_timer(bot, entry, delay): task_comparison = bot.schedule_timer await asyncio.sleep(0.5) logger.debug("Scheduler sleeping for %s seconds...", delay) await asyncio.sleep(delay) if task_comparison is not bot.schedule_timer: logger.debug("_schedule_timer was not cancelled! Cancelling this scheduler...") return if int(time.time() + 1) < entry.time: logger.warn("_schedule_timer was about to delete the entry early! Restarting loop...") asyncio.ensure_future(_start_scheduler(bot)) return try: deleted = data.db_delete( bot, 'schedule', where_arg='id=%s', input_args=[entry.id], safe=False) except Exception as e: logger.warn("_schedule_timer failed to delete a schedule entry. %s", e) if deleted: try: logger.debug("_schedule_timer done sleeping for %s seconds!", delay) function = getattr(bot.plugins[entry.plugin], entry.function) late = delay < -60 asyncio.ensure_future(function( bot, entry.time, entry.payload, entry.search, entry.destination, late, entry.info, entry.id)) except Exception as e: logger.warn("Failed to execute scheduled function: %s", e) asyncio.ensure_future(_start_scheduler(bot))
def remove_schedule_entries(bot, plugin_name, search=None, destination=None, custom_match=None, custom_args=[]): """Removes the entries given the search or match arguments.""" if custom_match: where_arg = custom_match input_args = custom_args else: where_arg = 'plugin = %s' input_args = [plugin_name] if search is not None: where_arg += ' AND search = %s' input_args.append(search) if destination is not None: where_arg += ' AND destination = %s' input_args.append(destination) data.db_delete(bot, 'schedule', where_arg=where_arg, input_args=input_args)
async def _schedule_timer(bot, raw_entry, delay): task_comparison = bot.schedule_timer await asyncio.sleep(0.5) logger.debug("_schedule_timer sleeping for %s seconds...", delay) await asyncio.sleep(delay) if task_comparison is not bot.schedule_timer: logger.debug( "_schedule_timer was not cancelled! Cancelling this scheduler...") return try: cursor = data.db_select(bot, select_arg='min(time)', from_arg='schedule') minimum_time = cursor.fetchone()[0] data.db_delete(bot, 'schedule', where_arg='time=%s', input_args=[minimum_time], safe=False) except Exception as e: logger.warn("_schedule_timer failed to delete schedule entry. %s", e) raise e try: logger.debug("_schedule_timer done sleeping for %s seconds!", delay) scheduled_time, plugin, function, payload, search, destination, info = raw_entry if payload: payload = json.loads(payload) plugin = bot.plugins[plugin] function = getattr(plugin, function) late = delay < -60 asyncio.ensure_future( function(bot, scheduled_time, payload, search, destination, late)) except Exception as e: logger.warn("Failed to execute scheduled function: %s", e) raise e asyncio.ensure_future(_start_scheduler(bot))
def remove_schedule_entries( bot, plugin_name, search=None, destination=None, custom_match=None, custom_args=[]): """Removes the entries given the search or match arguments.""" if custom_match: where_arg = custom_match input_args = custom_args else: where_arg = 'plugin = %s' input_args = [plugin_name] if search is not None: where_arg += ' AND search = %s' input_args.append(search) if destination is not None: where_arg += ' AND destination = %s' input_args.append(destination) return data.db_delete(bot, 'schedule', where_arg=where_arg, input_args=input_args)
async def remove_text(bot, context): text_type, entry_id = context.arguments table_name = 'txyz_' + TYPE_NAMES[text_type] data.db_delete(bot, table_name, where_arg='key=%s', input_args=[entry_id], safe=False) return Response(content='Removed {} entry {}.'.format(table_name[5:-1], entry_id))