Advertisement
lolsalat

[AD] Inception

Dec 18th, 2020 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. import inspect
  2.  
  3. class InceptionExtension(Extension):
  4.  
  5. def __init__(self):
  6. super().__init__("inception")
  7. self.ext = dict()
  8.  
  9. def emake_command(self, args=""):
  10. """makes a new command group"""
  11. if not args:
  12. self.debugger.log("emake <name>")
  13. return
  14. if args in self.ext:
  15. self.debugger.log(f"command group '{args}' does already exist!")
  16. return
  17. if not args.isidentifier():
  18. self.debugger.log(f"command group '{args}' is not a valid python identifier")
  19. return
  20. code = """
  21. class {}(Extension):
  22. def __init__(self):
  23. super().__init__("cg {}")
  24.  
  25. """.format(args, args)
  26. self.ext[args] = code
  27. print("ok")
  28.  
  29. def eedit_command(self, args=""):
  30. """edit command group command"""
  31. if not args or not " " in args:
  32. self.debugger.log("eedit <group> <command>")
  33. return
  34. name = args.split(" ")[0]
  35. command = args.split(" ")[1]
  36. if not command.isidentifier():
  37. self.debugger.log(f"command name {command} is not a python identifier!")
  38. return
  39. if not name in self.ext:
  40. self.debugger.log(f"command group '{name}' does not exist. use 'emake {name}' to create it")
  41. return
  42. self.debugger.log("type code (quit to exit abort to abort)")
  43. code = self.ext[name] + "\n\n" + " def {}_command(self, arg=''):\n".format(command)
  44. while True:
  45. i = input("(code)")
  46. if i == "exit":
  47. break
  48. if i == "abort":
  49. self.debugger.log("aborted!")
  50. return
  51. code += " " + i + "\n"
  52. self.debugger.log(code)
  53. try:
  54. exec(code)
  55. self.debugger.extensions["cg " + name] = eval(f"{name}()")
  56. self.ext[name] = code
  57. self.debugger.log("ok")
  58. except Exception as e:
  59. self.debugger.log(f"Error: {e}")
  60.  
  61.  
  62. ext = InceptionExtension()
  63. debugger.extensions[ext.name] = ext
  64. ext.enable(debugger)
  65. debugger.log(f"[{ext.name}]: Extension loaded successfully!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement