forked from Tju-LMc/Paddle_Story_Generation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (60 loc) · 1.78 KB
/
main.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
import os
import asyncio
os.environ['WECHATY_PUPPET'] = 'wechaty-puppet-service'
os.environ['WECHATY_PUPPET_SERVICE_TOKEN'] = 'puppet_padlocal_xxxx'
from wechaty import (
Contact,
Message,
Wechaty,
ScanStatus,
)
from world import World
world = World()
async def on_message(msg: Message):
"""
Message Handler for the Bot
"""
if msg.talker().name == '古德猫宁':
if msg.text() == '开始':
# 向用户输出故事开头
await msg.say(world.start())
return
response = world.receive(msg.text())
await msg.say(response)
async def on_scan(
qrcode: str,
status: ScanStatus,
_data,
):
"""
Scan Handler for the Bot
"""
print('Status: ' + str(status))
print('View QR Code Online: https://wechaty.js.org/qrcode/' + qrcode)
async def on_login(user: Contact):
"""
Login Handler for the Bot
"""
print(user)
# TODO: To be written
async def main():
"""
Async Main Entry
"""
#
# Make sure we have set WECHATY_PUPPET_SERVICE_TOKEN in the environment variables.
# Learn more about services (and TOKEN) from https://wechaty.js.org/docs/puppet-services/
#
if 'WECHATY_PUPPET_SERVICE_TOKEN' not in os.environ:
print('''
Error: WECHATY_PUPPET_SERVICE_TOKEN is not found in the environment variables
You need a TOKEN to run the Python Wechaty. Please goto our README for details
https://github.com/wechaty/python-wechaty-getting-started/#wechaty_puppet_service_token
''')
bot = Wechaty()
bot.on('scan', on_scan)
bot.on('login', on_login)
bot.on('message', on_message)
await bot.start()
print('[Python Wechaty] Ding Dong Bot started.')
asyncio.run(main())