async def ready(bot: commands.bot.Bot) -> None: channel = check(bot) bot.channel = channel # necessary from cron tasks, context.channel is used in others functions log.info('CTFdBot is coming !') to_send = f'Hello, it seems that it\'s the first time you are using my services.\nYou might use ' \ f'`{bot.command_prefix}help` to know more about my features.' embed_color, embed_name = 0x000000, "CTFd Bot" await interrupt(channel, to_send, embed_color=embed_color, embed_name=embed_name)
def run(bot): chats = execute("select * from chats;") data = [] for chat in chats: data.append([chat, bot]) with Pool(workers) as p: p.map(_update, data) for file in listdir(): if ('.png' in file or ('file' in file and 'Pip' not in file and 'Proc' not in file)) and path.isfile(file): remove(file) log.info("Chats updated")
def make_answer(question, dataset): try: input_question = question if input_question == "": serv.save_log(get_log(question, dataset, "error", "Void question")) log.info("answer", extra=get_log(question, dataset, "error", "Void question")) return "Void question" statistics = serv.get_statistics() if "-d=" in input_question: dataset = input_question[input_question.find("-d=") + 3:] input_question = input_question[0:input_question.find("-d=")] input_question = prepare_question(input_question) if dataset == "": ds = serv.find_dataset(input_question) if ds["type"] == "one": dataset = ds["dataset"] elif ds["type"] == "none": serv.save_log( get_log(question, dataset, "error", "No suitable dataset")) log.info("answer", extra=get_log(question, dataset, "error", "No suitable dataset")) return "No suitable dataset. Please, remake your question by the rules (use \"/rules\" command)" else: s = "There are several suitable datasets: " for name in ds["dataset"]: dst = serv.get_dataset(name) s += dst["name"] + " (" + dst["description"] + "), " s = s[:-2] s += ". \nSpecify the one you need with the \"-d\" key at the end of the question." serv.save_log( get_log(question, dataset, "error", "Several suitable datasets")) log.info("answer", extra=get_log(question, dataset, "error", "Several suitable datasets")) return s ds = serv.get_dataset(dataset) if not ds: serv.save_log( get_log(question, dataset, "error", "No such dataset in the database")) log.info("answer", extra=get_log(question, dataset, "error", "No such dataset in the database")) return "Wrong dataset. There is no dataset with this name." features, file = ds['features'], ds['file'] current_statistic, current_template, current_delimiter = find_template( statistics, input_question) if current_template == {}: serv.save_log( get_log(question, dataset, "error", "No suitable template")) log.info("answer", extra=get_log(question, dataset, "error", "No suitable template")) return "Have no suitable template (can't understand your question)" input_question = input_question.replace( current_template["question"].lower(), "") if (current_delimiter == ""): args = [input_question, ""] else: args = input_question.split(" " + current_delimiter + " ") args1, connectors1 = find_connectors(args[0]) args2, connectors2 = find_connectors(args[1]) args1 = find_features(args1, features) args2 = find_features(args2, features) if args1 == "More than one" or args2 == "More than one": serv.save_log(get_log(question, dataset, "error", "Ambiguity")) log.info("answer", extra=get_log(question, dataset, "error", "Ambiguity")) return "Please, specify values in question with feature names - during the recognition of the feature " \ "ambiguity appeared" stat = importlib.import_module("statistics." + current_statistic["file"][:-3]) calc = getattr(stat, "calc") res = calc(current_template, file, args1, connectors1, args2, connectors2) serv.save_log( get_log(question, dataset, "correct", res, current_statistic["name"], current_delimiter, current_template, args1, args2, connectors1, connectors2)) log.info("answer", extra=get_log(question, dataset, "correct", res, current_statistic["name"], current_delimiter, current_template, args1, args2, connectors1, connectors2)) return res except Exception as e: serv.save_log( get_log(question, dataset, "exception", traceback.format_exc())) log.info("answer", extra=get_log(question, dataset, "error", "Void question")) return "Something wrong (exception) was happened"
async def ready(bot: commands.bot.Bot) -> None: channel = check(bot) bot.channel = channel # necessary from cron tasks, context.channel is used in others functions log.info('CTFdBot is ready!')
async def diff(context: commands.context.Context): """ <username1> <username2> """ log.info("Command executed", name=str(context.command), author=str(context.message.author)) await display.diff(context)
async def recent(context: commands.context.Context): """ (<number_of_days>) (<username>) """ log.info("Command executed", name=str(context.command), author=str(context.message.author)) await display.recent(context)
async def who_solved(context: commands.context.Context): """ <challenge> """ log.info("Command executed", name=str(context.command), author=str(context.message.author)) await display.who_solved(context)
async def category(context: commands.context.Context): """ <category> """ log.info("Command executed", name=str(context.command), author=str(context.message.author)) await display.category(context)
async def scoreboard_complete(context: commands.context.Context): """ """ log.info("Command executed", name=str(context.command), author=str(context.message.author)) await display.scoreboard(context, all_players=True)
async def help(context: commands.context.Context): log.info("Command executed", name=str(context.command), author=str(context.message.author)) await display.help(self.bot, context)
return try: update_group_info(uid, bot, vk_chat_id, chat_id) except error.BadRequest: pass def utc_to_local(utc_dt): local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz) return local_tz.normalize(local_dt) def stop(signum, frame): exit(0) if __name__ == '__main__': signal(SIGINT, stop) log.info("Start update chats worker") while True: time = {"from": int(environ.get("FROM")), "to": int(environ.get("TO"))} sleep(interval * 60) hour = int(utc_to_local(datetime.utcnow()).strftime('%H')) if time['from'] >= hour <= time['to'] or (time['from'] == 0 and time['to'] == 0): continue run(b)