This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amiyaTest.py
110 lines (86 loc) · 3.25 KB
/
amiyaTest.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
import time
import asyncio
import functions
from abc import ABC
from core.network import WSOperation
from core.builtin.message.mirai import mirai_message_formatter
from core.builtin.messageHandler import message_handler
from core.builtin.htmlConverter import ChromiumBrowser
from core.config import config
from core.util import read_yaml, create_dir, argv
from core.bot import BotHandlers, Chain
from core import log, initialization
BotHandlers.add_prefix(
read_yaml('config/private/talking.yaml').call.positive
)
class SimulationClient(WSOperation, ABC):
async def send_message(self, reply: Chain):
for item in reply.chain + reply.voice_list:
if item['type'] == 'Plain':
text = item['text'].strip('\n')
if text:
print('text: ', text)
if item['type'] == 'Voice':
print('voice: ', item['path'])
if item['type'] == 'Image':
if type(item['path']) is bytes:
png = f'fileStorage/test/{int(time.time())}.png'
create_dir(png, is_file=True)
with open(png, mode='wb') as file:
file.write(item['path'])
print('image: ', png)
else:
print('image: ', item['path'])
if item['type'] == 'Html':
async with log.catch('html convert error:'):
browser = ChromiumBrowser()
page = await browser.open_page(item['template'], is_file=item['is_file'])
if item['data']:
await page.init_data(item['data'])
await asyncio.sleep(item['render_time'] / 1000)
png = f'fileStorage/test/{int(time.time())}.png'
create_dir(png, is_file=True)
with open(png, mode='wb') as file:
file.write(await page.make_image())
print('image: ', png)
if not argv('debug'):
await page.close()
async def test():
log.info(
[
f'starting Amiya-Bot Testing...',
f'%d function module(s) loaded.' % len([f for f in dir(functions) if f[:2] != '__'])
] + BotHandlers.detail()
)
await initialization()
log.info('testing ready.')
try:
while True:
await asyncio.sleep(0)
data = message(input())
await message_handler(data, SimulationClient())
except KeyboardInterrupt:
pass
def message(text, _type='group'):
mirai_text = {
'type': 'GroupMessage' if _type == 'group' else 'FriendMessage',
'messageChain': [
{
'type': 'Plain',
'text': text
}
],
'sender': {
'id': config.admin.accounts[0],
'permission': 'OWNER',
'nickname': 'OWNER',
'memberName': 'OWNER',
'remark': 'none',
'group': {
'id': config.test.group[0]
}
}
}
return mirai_message_formatter(account=config.miraiApiHttp.account, data=mirai_text, operation=SimulationClient())
if __name__ == '__main__':
asyncio.run(test())