teamx-cloner commited on
Commit
55a07ba
·
1 Parent(s): c0cdefe

Delete plugins/gcsd.py

Browse files
Files changed (1) hide show
  1. plugins/gcsd.py +0 -124
plugins/gcsd.py DELETED
@@ -1,124 +0,0 @@
1
- import ast
2
- import importlib
3
- import types
4
- from telethon import TelegramClient, events, utils
5
- import asyncio
6
- from . import ultroid_cmd
7
-
8
- async def meval(code, globs, **kwargs):
9
- # This function is released in the public domain. Feel free to kang it (although I like credit)
10
- # Note to self: please don't set globals here as they will be lost.
11
- # Don't clutter locals
12
- locs = {}
13
- # Restore globals later
14
- globs = globs.copy()
15
- # This code saves __name__ and __package__ into a kwarg passed to the function.
16
- # It is set before the users code runs to make sure relative imports work
17
- global_args = "_globs"
18
- while global_args in globs.keys():
19
- # Make sure there's no name collision, just keep prepending _s
20
- global_args = "_" + global_args
21
- kwargs[global_args] = {}
22
- for glob in ["__name__", "__package__"]:
23
- # Copy data to args we are sending
24
- kwargs[global_args][glob] = globs[glob]
25
-
26
- root = ast.parse(code, "exec")
27
- code = root.body
28
-
29
- ret_name = "_ret"
30
- ok = False
31
- while True:
32
- if ret_name in globs.keys():
33
- ret_name = "_" + ret_name
34
- continue
35
- for node in ast.walk(root):
36
- if isinstance(node, ast.Name) and node.id == ret_name:
37
- ret_name = "_" + ret_name
38
- break
39
- ok = True
40
- if ok:
41
- break
42
-
43
- if not code:
44
- return None
45
-
46
- if not any(isinstance(node, ast.Return) for node in code):
47
- for i in range(len(code)):
48
- if isinstance(code[i], ast.Expr):
49
- if i == len(code) - 1 or not isinstance(code[i].value, ast.Call):
50
- code[i] = ast.copy_location(ast.Expr(ast.Call(func=ast.Attribute(value=ast.Name(id=ret_name,
51
- ctx=ast.Load()),
52
- attr="append", ctx=ast.Load()),
53
- args=[code[i].value], keywords=[])), code[-1])
54
- else:
55
- for node in code:
56
- if isinstance(node, ast.Return):
57
- node.value = ast.List(elts=[node.value], ctx=ast.Load())
58
-
59
- code.append(ast.copy_location(ast.Return(value=ast.Name(id=ret_name, ctx=ast.Load())), code[-1]))
60
-
61
- # globals().update(**<global_args>)
62
- glob_copy = ast.Expr(ast.Call(func=ast.Attribute(value=ast.Call(func=ast.Name(id="globals", ctx=ast.Load()),
63
- args=[], keywords=[]),
64
- attr="update", ctx=ast.Load()),
65
- args=[], keywords=[ast.keyword(arg=None,
66
- value=ast.Name(id=global_args, ctx=ast.Load()))]))
67
- ast.fix_missing_locations(glob_copy)
68
- code.insert(0, glob_copy)
69
- ret_decl = ast.Assign(targets=[ast.Name(id=ret_name, ctx=ast.Store())], value=ast.List(elts=[], ctx=ast.Load()))
70
- ast.fix_missing_locations(ret_decl)
71
- code.insert(1, ret_decl)
72
- args = []
73
- for a in list(map(lambda x: ast.arg(x, None), kwargs.keys())):
74
- ast.fix_missing_locations(a)
75
- args += [a]
76
- args = ast.arguments(args=[], vararg=None, kwonlyargs=args, kwarg=None, defaults=[],
77
- kw_defaults=[None for i in range(len(args))])
78
- args.posonlyargs = []
79
- fun = ast.AsyncFunctionDef(name="tmp", args=args, body=code, decorator_list=[], returns=None)
80
- ast.fix_missing_locations(fun)
81
- mod = ast.parse("")
82
- mod.body = [fun]
83
- comp = compile(mod, "<string>", "exec")
84
-
85
- exec(comp, {}, locs)
86
-
87
- r = await locs["tmp"](**kwargs)
88
- for i in range(len(r)):
89
- if hasattr(r[i], "__await__"):
90
- r[i] = await r[i] # workaround for 3.5
91
- i = 0
92
- while i < len(r) - 1:
93
- if r[i] is None:
94
- del r[i]
95
- else:
96
- i += 1
97
- if len(r) == 1:
98
- [r] = r
99
- elif not r:
100
- r = None
101
- return r
102
-
103
- @ultroid_cmd(pattern="ev")
104
- async def eval_handler(event):
105
- code = event.text[3:] # Corrected: Remove only the "ev " prefix
106
- env = {
107
- 'client': event.client, # Corrected: Use event.client
108
- 'event': event,
109
- 'message': event.message,
110
- 'chat': event.chat,
111
- 'sender': await event.get_sender(),
112
- 'reply_to': await event.get_reply_message(),
113
- 'utils': utils,
114
- 'asyncio': asyncio,
115
- 'importlib': importlib,
116
- 'types': types,
117
- 'ast': ast,
118
- }
119
- try:
120
- result = await meval(code, env)
121
- output = f"**Output:**\n`{result}`"
122
- except Exception as e:
123
- output = f"**Error:**\n`{e}`"
124
- await event.reply(output)