def register(self, **args): tmp = {} tmp["pattern"] = args.get("pattern", None) tmp["outgoing"] = args.get("outgoing", None) tmp["incoming"] = args.get("incoming", None) del args args = tmp del tmp try: MOD_LIST[list(MOD_LIST.keys())[-1]].append(args["pattern"]) except: pass def decorator(func): logger = ModLogger.log(func.__name__) s ="""async def {}(event, func=func, logger=logger): from xtrabot import client, trustUser if event.from_id in trustUser and event.from_id != (await client.get_me()).id: event2 = await event.respond("Processing,") event2.text = event.text elif event.from_id == (await client.get_me()).id: event2 = event else: return try: await func(event2) except Exception as error: await event.reply("__Error occured on the current__ `{}`, __do__ `.log` __to show the latest log.__") logger.exception(error)""".format(func.__name__,"."+func.__name__) exec(s, None, locals()) client.add_event_handler(locals()[func.__name__], events.NewMessage(**args)) return func return decorator
def command(**args): try: MOD_LIST[list(MOD_LIST.keys())[-1]].append(args["pattern"]) except: pass def decorator(func): client.add_event_handler(func, events.NewMessage(**args)) return decorator
def uniadmin(self, pattern=None, **args): args["pattern"] = re.compile(uni.COMMAND_HAND_LER + pattern) MOD_LIST[list(MOD_LIST.keys())[-1]].append("." + pattern) if not "outgoing" in args: if not "incoming" in args: args["outgoing"] = True if "allow sudo" in args: del args["allow_sudo"] if "allow_edited_updates" in args: del args["allow_edited_updates"] return events.NewMessage(**args)
def register(self, **args): try: MOD_LIST[list(MOD_LIST.keys())[-1]].append(args["pattern"]) except: pass def decorator(func): kwargs = {} kwargs[ "pattern"] = args["pattern"] if "pattern" in args else None kwargs["outgoing"] = args[ "outgoing"] if "outgoing" in args else False kwargs["incoming"] = args[ "incoming"] if "incoming" in args else False logger = ModLogger.log(func.__name__) s = """async def {}(event, func=func, logger=logger, kwargs=kwargs): from xtrabot import client, trustUser from telethon.events import StopPropagation if event.from_id in trustUser and event.from_id != (await client.get_me()).id: event2 = await event.respond("Processing,") event.edit = event2.edit elif event.from_id == (await client.get_me()).id: pass elif "incoming" in kwargs: if kwargs["incoming"] == True: pass else: return try: await func(event) except StopPropagation: pass except Exception as error: await event.reply("__Error occured on the current__ `{}`, __do__ `.log` __to show the latest log.__") logger.exception(error)""".format(func.__name__, "." + func.__name__) exec(s, None, locals()) del kwargs["incoming"] client.add_event_handler( locals()[func.__name__], events.NewMessage(incoming=True, **kwargs)) return func return decorator
def __init__(self, funct): try: self.name except NameError: self.name = "untitled" if type(funct) is not list: funct = [funct] for func in funct: if 1 == 1: funcmd = re.compile("^." + func.__name__) try: func_name[self.name].append(func) except KeyError: func_name.update({self.name: [func]}) self.xconfig = xconfig self.logger = ModLogger.log(self.name) self.client = client self.config = Var MOD_LIST[list(MOD_LIST.keys())[-1]].append("^." + func.__name__) s = """async def {}(event, func=func, self=self): from xtrabot import client, trustUser if event.from_id in trustUser and event.from_id != (await client.get_me()).id: event2 = await event.respond("Processing,") event.edit = event2.edit elif event.from_id == (await client.get_me()).id: pass else: return try: await func(event) except Exception as error: await event.reply("__Error occured on the current__ `{}`, __do__ `.log` __to show the latest log.__") self.logger.exception(error)""".format(func.__name__, "." + func.__name__) exec(s, None, locals()) client.add_event_handler(locals()[func.__name__], events.NewMessage(pattern=funcmd))