forked from leeduckgo/wechat_robot_supported_blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
58 lines (50 loc) · 1.89 KB
/
run.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
# -*- coding: utf-8 -*-
from time import sleep
from wxpy import Bot
from wxpy import embed
from wxpy import Group
from common.logger import Logger
from common.message_replier import Replier
from settings import ALLOW_GROUPS
# === init ===
# user.name 用户群内备注名称
# user.nick_name 用户微信名称
bot = Bot(console_qr=True, cache_path=True) # 控制台二维码
# bot = Bot(cache_path=True) # 短时间内重启无需重新登录
bot.enable_puid()
logger = Logger() # 项目logger对象
replier = Replier(bot)
groups = bot.groups()
# === main process ===
if __name__ == '__main__':
for group in groups: # 所有群聊puid
logger.warning('群名:%s,puid:%s' % (group.name, group.puid))
@bot.register(msg_types='Note')
def deal_new(msg):
"""新入群自动初始化"""
logger.info(msg.sender)
if type(msg.sender) == Group and msg.sender.puid in ALLOW_GROUPS: # 限定群组
replier.update_user_info(msg)
@bot.register(msg_types='Text')
def reply_message(msg):
"""消息回复"""
if type(msg.sender) == Group and msg.sender.puid in ALLOW_GROUPS: # 限定群组
logger.info("=== start ===")
logger.info(msg.sender)
replier.set_group(msg.sender.puid) # 获取群信息
logger.info(msg.member.puid)
if msg.type == "Note":
replier.update_user_info(msg)
typ, content1, content2 = replier.handle_group_msg(msg)
if typ == 'text':
msg.reply_msg(content1)
elif typ == 'img':
msg.reply_image(content1)
elif typ == 'both':
msg.reply_image(content1)
sleep(1)
msg.reply_msg(content2)
# else: # todo 私聊消息
# replier.handle_solo_msg(msg)
# logger.info(msg)
embed() # 阻塞线程不退出'