def match_plugin(plugin, name, msg): if not hasattr(msg, 'text') or not msg.text or msg.text == '': return receiver = utils.get_receiver(msg) text = msg.text patterns = utils.get_infov(plugin, 'patterns', ()) for pattern in patterns: # print("Trying to match", pattern, "with", text) matches = utils.match_pattern(pattern, text) if not matches: continue print("Message matches: {}".format(pattern)) if utils.is_plugin_disabled_on_chat(name, receiver): return None if not utils.plugin_have_obj(plugin, 'run'): print("The plugin {} don't have run function".format(name)) continue if utils.warns_user_not_allowed(plugin, msg): continue result = utils.execute_plugin_function_obj(plugin, 'run', msg, matches) if result and type(result) == str: utils.send_large_msg(receiver, result) return # Only one pattern per plugin!
def enable_plugin_chat(name, receiver): if not utils.plugin_exists(name): return "Plugin {} does not exists".format(name) if not utils.is_plugin_disabled_on_chat(name, receiver): return "Plugin {} is not disabled in this chat".format(name) cfg, data = getOrElse("disabled_plugins_on_chat", dict) plgs = data.get(receiver) plgs.remove(name) data[receiver] = plgs generic_cfg(data, "update", dict, field="disabled_plugins_on_chat") print("Enabled plugin {} in chat {} and saved".format(name, receiver)) cfg["disabled_plugins_on_chat"] = data utils.save_cfg_settings(cfg) return "Plugin {} enabled in the chat again! {}".format(name, utils.emojis["smile"])
def list_plugins(only_enabled=False, receiver="", in_chat=False): text = "" allp = settings.ALL_PLUGINS if hasattr(settings, "ALL_PLUGINS") else utils.clean_plugins(utils.get_all_plugins()) for plug in allp: status = utils.emojis.get("nope") if plug in settings.ENABLED_PLUGINS: status = utils.emojis.get("ok") if utils.is_plugin_disabled_on_chat(plug, receiver): status = "{} (in chat)".format(utils.emojis.get("nope")) if not only_enabled or status == utils.emojis.get("ok"): text += "{} {}\n".format(plug, status) elif in_chat: text += "{} {}\n".format(plug, status) return text
def enable_plugin_chat(name, receiver): if not utils.plugin_exists(name): return 'Plugin {} does not exists'.format(name) if not utils.is_plugin_disabled_on_chat(name, receiver): return 'Plugin {} is not disabled in this chat'.format(name) cfg, data = getOrElse('disabled_plugins_on_chat', dict) plgs = data.get(receiver) plgs.remove(name) data[receiver] = plgs generic_cfg(data, 'update', dict, field='disabled_plugins_on_chat') print("Enabled plugin {} in chat {} and saved".format(name, receiver)) cfg['disabled_plugins_on_chat'] = data utils.save_cfg_settings(cfg) return "Plugin {} enabled in the chat again! {}".format( name, utils.emojis['smile'])
def match_plugin(plugin, name, msg): if not hasattr(msg, 'text') or not msg.text or msg.text == '': return receiver = utils.get_receiver(msg) text = msg.text patterns = utils.get_infov(plugin, 'patterns', ()) for pattern in patterns: # print("Trying to match", pattern, "with", text) matches = utils.match_pattern(pattern, text) if not matches: continue print("Message matches: {}".format(pattern)) if utils.is_plugin_disabled_on_chat(name, receiver): return None
def list_plugins(only_enabled=False, receiver='', in_chat=False): text = "" allp = settings.ALL_PLUGINS if hasattr( settings, 'ALL_PLUGINS') else utils.clean_plugins( utils.get_all_plugins()) for plug in allp: status = utils.emojis.get('nope') if plug in settings.ENABLED_PLUGINS: status = utils.emojis.get('ok') if utils.is_plugin_disabled_on_chat(plug, receiver): status = '{} (in chat)'.format(utils.emojis.get('nope')) if not only_enabled or status == utils.emojis.get('ok'): text += "{} {}\n".format(plug, status) elif in_chat: text += "{} {}\n".format(plug, status) return text