1
- """doc"""
2
- # pylint: disable=R0801
1
+ """
2
+ Python Wechaty - https://github.com/wechaty/python-wechaty
3
+ Authors: Huan LI (李卓桓) <https://github.com/huan>
4
+ Jingjing WU (吴京京) <https://github.com/wj-Mcat>
5
+ 2020 @ Copyright Wechaty Contributors <https://github.com/wechaty>
6
+ Licensed under the Apache License, Version 2.0 (the 'License');
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an 'AS IS' BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+ import os
3
17
import asyncio
4
- import logging
5
18
from typing import Optional , Union
6
19
7
- from wechaty_puppet import ScanStatus # type: ignore
8
-
9
20
from wechaty import Wechaty , Contact , Room
10
21
from wechaty .user import Message
11
22
12
23
from apscheduler .schedulers .asyncio import AsyncIOScheduler
13
24
14
- logging .basicConfig (level = logging .INFO )
15
- log = logging .getLogger (__name__ )
16
-
17
25
18
26
class MyBot (Wechaty ):
19
27
"""
@@ -25,7 +33,7 @@ def __init__(self):
25
33
self .busy = False
26
34
self .auto_reply_comment = "Automatic Reply: I cannot read your message because I'm busy now, will talk to you when I get back."
27
35
28
- async def message (msg : Message ):
36
+ async def message (self , msg : Message ):
29
37
"""back on message"""
30
38
from_contact = msg .talker ()
31
39
text = msg .text ()
@@ -39,27 +47,30 @@ async def message(msg: Message):
39
47
async def on_login (self , contact : Contact ):
40
48
print (f'user: { contact } has login' )
41
49
42
- async def on_scan (self , status : ScanStatus , qr_code : Optional [str ] = None ,
43
- data : Optional [str ] = None ):
44
- contact = self .Contact .load (self .contact_id )
45
- print (f'user <{ contact } > scan status: { status .name } , '
46
- f'qr_code: { qr_code } ' )
47
-
48
50
49
51
bot : Optional [MyBot ] = None
50
52
51
53
52
54
async def tick (bot : Wechaty ):
55
+ """
56
+ find a specific room, and say something to it.
57
+ """
53
58
room = bot .Room .load ('room-id' )
54
59
await room .ready ()
55
60
from datetime import datetime
56
- await room .say (f'say ding automatically, { datetime .now ()} ' )
57
- await room .say ('ding ' )
61
+ await room .say (f'it"s a new day, let"s welcome, now it"s { datetime .now ()} ' )
62
+ await room .say ('hello world ! ' )
58
63
59
64
60
65
async def main ():
61
- """doc"""
62
- # pylint: disable=W0603
66
+ """Async Main Entry"""
67
+ if 'WECHATY_PUPPET_HOSTIE_TOKEN' not in os .environ :
68
+ print ('''
69
+ Error: WECHATY_PUPPET_HOSTIE_TOKEN is not found in the environment variables
70
+ You need a TOKEN to run the Java Wechaty. Please goto our README for details
71
+ https://github.com/wechaty/python-wechaty-getting-started/#wechaty_puppet_hostie_token
72
+ ''' )
73
+
63
74
global bot
64
75
bot = MyBot ()
65
76
0 commit comments