-
Notifications
You must be signed in to change notification settings - Fork 33
/
silly_girl.py
143 lines (136 loc) · 4.8 KB
/
silly_girl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from asyncio import sleep
from pagermaid.listener import listener
from pagermaid import persistent_vars, bot
from pagermaid.utils import client, alias_command
import os
import json
"""
Pagermaid sillyGirl plugin.
Silly Gril Repo: https://github.com/cdle/sillyGirl
"""
persistent_vars.update(
{'sillyGirl':
{
'times': 0,
'started': False,
'self_user_id': 0,
'token': '',
'url': '',
'init': False,
'restart': False,
}
}
)
@listener(is_plugin=True, outgoing=True, command=alias_command("sillyGirl"), ignore_edited=True, parameters="<message>")
async def sillyGirl(context):
fd = os.open("sillyGirl.egg", os.O_RDWR | os.O_CREAT)
await context.edit("正在连接到傻妞服务器...")
persistent_vars["sillyGirl"]['context'] = context
persistent_vars["sillyGirl"]['init'] = False
if context.arguments:
text = context.arguments
try:
os.write(fd, bytes(text, 'utf-8'))
except Exception as e:
print(e)
else:
try:
text = str(os.read(fd, 1200), encoding="utf-8")
except Exception as e:
print(e)
if '@' in text:
s1 = text.split("//", 1)
s2 = s1[1].split("@", 1)
persistent_vars["sillyGirl"]['token'] = s2[0]
text = s1[0]+"//"+s2[1]
os.close(fd)
persistent_vars["sillyGirl"]['url'] = text
myself = await context.client.get_me()
persistent_vars["sillyGirl"]['self_user_id'] = myself.id
if persistent_vars["sillyGirl"]['started'] == False:
persistent_vars["sillyGirl"]['started'] = True
while(context.client.is_connected()):
await poll([])
@listener(is_plugin=True, outgoing=True, incoming=True)
async def handle_receive(context):
if persistent_vars["sillyGirl"]['started'] == False:
await sillyGirl(context)
reply_to = 0
reply_to = context.id
reply = await context.get_reply_message()
reply_to_sender_id = 0
if reply:
reply_to = reply.id
reply_to_sender_id = reply.sender_id
elif persistent_vars["sillyGirl"]['self_user_id'] == context.sender_id or context.is_private:
reply_to = 0
await poll(
[{
'id': context.id,
'chat_id': context.chat_id,
'text': context.text,
'sender_id': context.sender_id,
'reply_to': reply_to,
'reply_to_sender_id': reply_to_sender_id,
'bot_id': persistent_vars["sillyGirl"]['self_user_id'],
'is_group': context.is_private == False,
}])
async def poll(data):
try:
init = ""
if persistent_vars["sillyGirl"]['init'] == False:
init = "&init=true"
req_data = await client.post(persistent_vars["sillyGirl"]['url']+"/pgm?token="+persistent_vars["sillyGirl"]['token']+init, json=data)
except Exception as e:
await sleep(0.1)
return
if not req_data.status_code == 200:
# await sleep(0.1)
return
try:
replies = json.loads(req_data.text)
results = []
for reply in replies:
if reply["delete"]:
try:
await bot.edit_message(reply["chat_id"], reply["id"], "打错字了,呱呱~")
except Exception as e:
""""""
try:
await bot.delete_messages(reply["chat_id"], [reply["id"]])
except Exception as e:
""""""
if reply["id"] != 0:
try:
await bot.edit_message(reply["chat_id"], reply["id"], reply["text"])
continue
except Exception as e:
continue
text = reply["text"]
images = reply["images"]
chat_id = reply["chat_id"]
reply_to = reply["reply_to"]
context = False
if images and len(images) != 0:
context = await bot.send_file(
chat_id,
images[0],
caption=text,
reply_to=reply_to,
)
elif text != '':
context = await bot.send_message(chat_id, text, reply_to=reply_to)
if context:
results.append({
'id': context.id,
'uuid': reply["uuid"],
})
if len(results):
await poll(results)
if persistent_vars["sillyGirl"]['init'] == False:
persistent_vars["sillyGirl"]['init'] = True
await persistent_vars["sillyGirl"]['context'].edit("傻妞连接成功,愉快玩耍吧。")
await persistent_vars["sillyGirl"]['context'].delete()
except Exception as e:
# await sleep(0.1)
return