Last active
July 20, 2017 23:46
-
-
Save diggzhang/37748f50be53cfdabc204dd87130b759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# coding: utf-8 | |
# https://gist.github.com/diggzhang/37748f50be53cfdabc204dd87130b759 | |
# 回复语,在发送群邀请后会回复这个 | |
reply_text = """你好,如果您是我们歪友,欢迎加入我们歪歪群 | |
""" | |
# 45min | |
# intervalTime = 2700 | |
intervalTime = 10 | |
# 金数据问卷地址 | |
askPage = "https://jinshuju.net/f/YNEnRx" | |
# 群名 | |
group_name = '名字特别长的测试群' | |
""" | |
代码区,下方的内容不要修改 | |
""" | |
from wxpy import * | |
import re | |
import platform | |
import threading | |
import datetime | |
from time import sleep | |
console_qr=(False if platform.system() == 'Windows' else True) | |
bot = Bot('bot.pkl', console_qr=console_qr) | |
target_group = bot.groups().search(group_name)[0] | |
# 欢迎语,{} 会变成新入群用户的昵称 | |
welcome_text = '''🎉 欢迎 @{} 的加入! | |
😃 有问题请私聊 @王主任 @刘医生 | |
{} | |
新诊病人请填写报道表方便档案管理:https://jinshuju.net/f/YNEnRx | |
我会每隔45分钟询问当前排队情况,方便您的时间安排。 | |
''' | |
''' | |
邀请消息处理 | |
''' | |
def get_new_member_name(msg): | |
# itchat 1.2.32 版本未格式化群中的 Note 消息 | |
from itchat.utils import msg_formatter | |
msg_formatter(msg.raw, 'Text') | |
for rp in rp_new_member_name: | |
match = rp.search(msg.text) | |
if match: | |
return match.group(1) | |
''' | |
邀请信息处理 | |
''' | |
rp_new_member_name = ( | |
re.compile(r'^"(.+)"通过'), | |
re.compile(r'邀请"(.+)"加入'), | |
) | |
''' | |
处理加好友请求信息 | |
如果验证信息文本是字典的键值之一,则尝试拉群。 | |
''' | |
@bot.register(msg_types=FRIENDS) | |
def new_friends(msg): | |
user = msg.card.accept() | |
target_group.add_members(user,use_invitation=True) | |
user.send(reply_text) | |
def countMembers(target_group): | |
return "在改邪归正路上,共计" + str(len(target_group)) + "位歪友" | |
@bot.register(target_group, NOTE) | |
def welcome(msg): | |
name = get_new_member_name(msg) | |
if name: | |
return welcome_text.format(name, countMembers(target_group)) | |
@bot.register(target_group, TEXT) | |
def replyAtMessage(msg): | |
# .*\d*号* | |
reply_msg = msg.text | |
gotNumberInMsg = re.sub("\D", "", reply_msg) | |
numis = int(gotNumberInMsg) | |
one_range = range(1, 200) | |
if numis in one_range: | |
nowAnsterNumber = numis | |
next_range = nowAnsterNumber + 6 | |
reply_msg = """ | |
@所有人 当前已经扎到了{}号,请{}~{}号的歪友做好准备,防止过号。 | |
已经完成治疗的歪友请填写问卷方便歪情跟踪: {} | |
""".format(nowAnsterNumber ,nowAnsterNumber + 1, next_range, askPage) | |
try: | |
msg.reply(reply_msg) | |
except Exception as e: | |
print(e) | |
# 建议谁来排队吧 | |
def queueListPrint(argument): | |
switcher = { | |
0: ['帝福', '陈星丛', '齐林可', '水子', '吕振国', '李杰', '徐利', '王健丽', '酥扩', '原而', '丁斌', '笑捷', '负富', '刁学芝', '孙秀萍', '郭雄礼', '宋眷霞', '张心兰', '董超', '孙恩惠', '万国莉'], | |
1: ['陈霞', '王轶彤', '李翠云', '樊文琪', '段晓瑜', '俞琪英', '吕美昌', '彭嵋逸', '王永芳', '胡艳双', '王晨字', '孙星霞', '张顺季', '王吴艳云'], | |
2: ['获蕊', '翻飞', '克亮', '马艳', '杜明利月', '刘宜妍', '王雯'], | |
3: ['李姑琳', '张硕', '张俊然', '张兴泽', '王远健', '李东', '李帅', '马圆圆'], | |
4: ['张新富', '徐永峰', '邵健栩', '周子洋', '李文海', '徐研', '郭莹尹', '宪志', '张莹', '吴艳云', '杨淑慧'], | |
5: ['毛媛媛', '竺', '众几示矛', '荔丽', '浩', '屈璐'], | |
} | |
return switcher.get(argument, "不要有人") | |
def queuingUp(now): | |
hourIs = now.hour | |
if hourIs >= 7 and hourIs <=9: | |
argument = 0 | |
elif hourIs > 9 and hourIs <= 10: | |
argument = 1 | |
elif hourIs > 10 and hourIs <= 13: | |
argument = 2 | |
elif hourIs > 13 and hourIs <= 14: | |
argument = 3 | |
elif hourIs > 14 and hourIs <= 15: | |
argument = 4 | |
elif hourIs > 15: | |
argument = 5 | |
qList = " ".join(queueListPrint(argument)) | |
advList = """ | |
建议 {} 这个点来扎针。在期望时间点来可享受优先排号权。 | |
""".format(qList) | |
# target_group.send(advList) | |
sleep(15) | |
def isWorkTime(): | |
# 0yi 1er 2san 3si 4wu 5liu 6ri | |
now = datetime.datetime.now() | |
weekdayIs = now.weekday() | |
if weekdayIs is not 5 and weekdayIs is not 6: | |
if int(now.hour) >= 7 and int(now.hour) <= 19: | |
queuingUp(now) | |
return True | |
else: | |
return False | |
def askAll(): | |
workTime = isWorkTime() | |
if workTime is not False: | |
threading.Timer(intervalTime, askAll).start() | |
target_group.send("@所有人 谁知道现在扎到多少号了?") | |
askAll() | |
embed() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment