def __init__(self, game_controller):
super().__init__(game_controller)
self.username_to_user = {} # Map Wechat user name to WechatUser object
self.send_msg_queue = queue.Queue() # Avoid sending messages too fast by buffering
# Start listening Wechat messages
itchat.auto_login()
threading.Thread(target = itchat.run).start()
# Send messages in another thread
threading.Thread(target = self.send_messages_in_queue).start()
# Accept new messages from players
@itchat.msg_register(itchat.content.TEXT)
def listen_wechat_message(message_info):
username = message_info['User']['UserName'] # User name of the Wechat user
text = message_info['Text'] # Content of the message
self.got_message(username, text)
评论列表
文章目录