def read_trigger(infos: Infos) -> Callable: if infos.is_callback_query: if infos.callback_query.data == "done": return to_menu(infos) new_trigger = infos.message.text t_type = infos.bot.waiting_data["type"] section = infos.bot.waiting_data["section"] t = Trigger(t_type, new_trigger, section, infos.bot.bot_id, infos.db.language) mongo_interface.add_trigger(t) triggers = mongo_interface.get_triggers_of_type_and_section( infos.bot.bot_id, t_type, section, infos.db.language) msg = "Now send the triggers as replies." if triggers: triggs = make_trigger_list(triggers) msg = f"[md]Triggers of type `{t_type}` in section `{section}`:\n{triggs}\n" + msg infos.edit(msg, msg_id=infos.bot.waiting_data["msg"].message_id, reply_markup=keyboards.done(), parse=False) return read_trigger
def get_triggers(bot_id: int, language=_default_language): return [ Trigger.from_json(trigger) for trigger in _get_db().triggers.find({ "bot_id": bot_id, "language": language }) ]
def get_triggers_of_type_and_section(bot_id: int, t_type: str, section: str, language=_default_language) \ -> List[Trigger]: return [ Trigger.from_json(trigger) for trigger in _get_db().triggers.find({ "bot_id": bot_id, "type": t_type, "section": section, "language": language }) ]
def elaborate_triggers(triggers: dict, infos: Infos): log.d("Elaborating triggers....") mongo_interface.drop_triggers() final_trigger_list = [] for t_type in triggers: if isinstance(triggers[t_type], str): triggers[t_type] = [ trigger.replace("_", " ") for trigger in triggers[t_type].split() ] actual_triggers = triggers[t_type] section = None # TODO add support for importing commands if t_type == "equals": t_type = "equal" elif t_type == "contents": t_type = "content" elif t_type == "eteractions": t_type = "eteraction" elif t_type == "interactions": t_type = "interaction" else: if t_type in [ "bot_commands", "antispam time", "bot_comm_symbol", "day_parts", "notte", "giorno", "admin_actions" ]: continue section = t_type t_type = "interaction" for trigger in actual_triggers: trigger = update_dummies(trigger) n_t = Trigger(t_type, trigger, trigger if not section else section, infos.bot.bot_id, infos.db.user.language, 0) print(dict(n_t)) final_trigger_list.append(n_t) mongo_interface.add_triggers(final_trigger_list) log.d("Elaborated!")
def converter(self, comandoStr): compileDados = re.compile(RegexUtil.REGEX_PROP_STRING) matches = re.finditer(RegexUtil.REGEX_TABLE, comandoStr, re.MULTILINE | re.IGNORECASE) table = Table() for matchNum, match in enumerate(matches): if match.lastgroup == 'DUMPNAME': table.dump_name = compileDados.findall( match.groupdict()['DUMPNAME'])[0] elif match.lastgroup == 'AREA': table.area = compileDados.findall(match.groupdict()['AREA'])[0] elif match.lastgroup == 'DESCRIPTION': table.description = compileDados.findall( match.groupdict()['DESCRIPTION'])[0] elif match.lastgroup == 'LABEL': table.label = compileDados.findall( match.groupdict()['LABEL'])[0] elif match.lastgroup == 'ADDTABLE': table.name = compileDados.findall( match.groupdict()['ADDTABLE'])[0] elif match.lastgroup == 'TABLETRIGGER': t = match.groupdict()['TABLETRIGGER'] res_trigger_regex = re.finditer(RegexUtil.REGEX_TRIGGER, t, re.MULTILINE | re.IGNORECASE) parse_triggers = Prp(res_trigger_regex) trigger = Trigger() trigger.table_name = table.dump_name trigger.event = parse_triggers.first_value_string('EVENT') trigger.override = parse_triggers.group_value( 'OVERRIDE', default='OVERRIDE') trigger.procedure = parse_triggers.first_value_string( 'PROCEDURE') trigger.crc = parse_triggers.first_value_string('CRC') table.addTrigger(trigger) return table