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
def decorator(func): self.logger = ModLogger.log(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,") 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.__") self.logger.exception(error)""".format(func.__name__,"."+func.__name__) exec(s, None, locals()) client.add_event_handler(locals()[func.__name__], events)
def __init__(self, funct): try: self.name except NameError: self.name = "untitled" if type(funct) is not list: funct = [funct] for i in funct: if 1==1: func = i funcmd = re.compile("^."+func.__name__) try: func_name[self.name].append(func) except KeyError: func_name.update({self.name: [func]}) self.xconfig = xconfig self.client = client self.config = Var client.add_event_handler(func, events.NewMessage(pattern=funcmd, outgoing=True))
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))
def decorator(func): client.add_event_handler(func, events.NewMessage(**args))