-
Notifications
You must be signed in to change notification settings - Fork 1
/
XMLSender.py
86 lines (73 loc) · 2.76 KB
/
XMLSender.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
from urllib.request import urlopen
from nonebot import get_bot
from hoshino import Service
from hoshino.typing import HoshinoBot, CQEvent
from quart import request
import os
try:
import ujson as json
except ImportError:
import json
sv = Service(name='XMLSender')
app = get_bot().server_app
host = json.load(urlopen('http://jsonip.com'))['ip']
port = get_bot().config.PORT
curr_bot = get_bot()
try:
password = json.load(open(os.path.dirname(__file__) + '/config.json', 'r'))['password']
except IOError:
password = '123456'
json.dump({'password': password}, open(os.path.dirname(__file__) + '/config.json', 'w'))
@sv.on_prefix('发送XML')
async def sendXML(bot: HoshinoBot, ev: CQEvent):
msg = ev.message.extract_plain_message()
await bot.send(ev, f'[CQ:xml,data={msg}]')
@sv.on_fullmatch('在线发送XML')
async def sendXMLWeb(bot: HoshinoBot, ev: CQEvent):
await bot.send(ev, f'http://{host}:{port}/XMLSender')
@sv.on_prefix('设置XML密码')
async def setPassword(bot: HoshinoBot, ev: CQEvent):
global password
password = ev.message.extract_plain_text()
json.dump({'password': password}, open(os.path.dirname(__file__) + '/config.json', 'w'))
await bot.send(ev, f'已将密码设置为{password}')
@app.route('/XMLSender', methods=['GET'])
def sendg():
return '''
<form action="XMLSender" method="post"><br />
密码:<input type="password" name="psw"><br />
群号:<input type="text" name="group"><br />
XML:<br />
<textarea rows="10" cols="30" name="XML"></textarea><br />
<button type="submit">发送</button>
</form>
'''
@app.route('/XMLSender', methods=['POST'])
async def sendp():
XML_data = await request.form
group_id = int(XML_data.get('group'))
xml = XML_data.get('XML')
psw = XML_data.get('psw')
if psw == password:
await curr_bot.send_group_msg(group_id=group_id, message=f'[CQ:xml,data={xml}]')
return '''
<form action="XMLSender" method="post"><br />
密码:<input type="password" name="psw"><br />
群号:<input type="text" name="group"><br />
XML:<br />
<textarea rows="10" cols="30" name="XML"></textarea><br />
<button type="submit">发送</button>
</form>
发送成功!
'''
else:
return '''
<form action="XMLSender" method="post"><br />
密码:<input type="password" name="psw"><br />
群号:<input type="text" name="group"><br />
XML:<br />
<textarea rows="10" cols="30" name="XML"></textarea><br />
<button type="submit">发送</button>
</form>
密码错误!
'''