Skip to content

Commit

Permalink
修复消息例子
Browse files Browse the repository at this point in the history
  • Loading branch information
smallevilbeast committed Aug 25, 2022
1 parent 7e1bf18 commit c261a9b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion examples/auto_accept_friend_request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat
import xml.dom.minidom

Expand All @@ -24,9 +25,11 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
wechat_instance.accept_friend_request(encryptusername, ticket, int(scene))


# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()

4 changes: 3 additions & 1 deletion examples/echo_bot_msg_register.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat

wechat = ntchat.WeChat()
Expand All @@ -22,9 +23,10 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
wechat_instance.send_text(to_wxid=from_wxid, content=f"你发送的消息是: {data['msg']}")


# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()
4 changes: 3 additions & 1 deletion examples/echo_bot_on.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat

wechat = ntchat.WeChat()
Expand All @@ -22,9 +23,10 @@ def on_recv_text_msg(wechat_instance: ntchat.WeChat, message):
# 监听接收文本消息
wechat.on(ntchat.MT_RECV_TEXT_MSG, on_recv_text_msg)

# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()
5 changes: 4 additions & 1 deletion examples/get_contacts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat

wechat = ntchat.WeChat()
Expand All @@ -17,9 +18,11 @@
print(contacts)


# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()

5 changes: 4 additions & 1 deletion examples/get_rooms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat

wechat = ntchat.WeChat()
Expand All @@ -17,9 +18,11 @@
print(rooms)


# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()

5 changes: 4 additions & 1 deletion examples/send_text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import time
import ntchat

wechat = ntchat.WeChat()
Expand All @@ -13,12 +14,14 @@
# 向文件助手发送一条消息
wechat.send_text(to_wxid="filehelper", content="hello, filehelper")

# 以下是为了让程序不结束,如果有用于PyQt等有主循环消息的框架,可以去除下面代码
try:
while True:
pass
time.sleep(0.5)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()




0 comments on commit c261a9b

Please sign in to comment.