def decorator(self, msg, *args, **kwargs): _action, _reply, _obj = func.__name__.split('_') if self._meta['action'][_action]: _to_user = self._meta['obj'][_obj] for _group in _to_user: instance.send_msg(msg, _group['UserName']) time.sleep(random.randrange(0, 20)) self._meta['action'][_action] = False self._current_cmd = None instance.send_msg('群发消息发送完毕', self._meta['extra']['UserName'])
def file_helper(res): msg = res['Text'] from_user = res['FromUserName'] to_user = res['ToUserName'] if msg == '技术群': instance.send_msg('晚些我会统一拉你们入群~', to_user=from_user) return if msg == '知识星球': instance.send_image(os.path.join(WX_IMG_DIR, 'zsxq.jpeg'), toUserName=from_user['UserName']) return if to_user == fh.meta['extra']['NickName']: if msg == 'm': return fh.usage if not fh.current_cmd: cmd = '_'.join(msg.split()) fh.update_cmd(cmd) return if fh.current_cmd: eval(f'fh.{fh.current_cmd}')(msg) return
def friends(res): try: # 添加好友 msg = res['RecommendInfo']['Content'] username = res['RecommendInfo']['UserName'] nickname = res['RecommendInfo']['NickName'] add_ret = instance.add_friend(username, 3) if add_ret['BaseResponse']['ErrMsg'] == '请求成功': print(f'已添加好友: {nickname}') instance.send_msg(friend.meta['extra']['welcome'], username) # 修改备注 # 若有商务、合作等关键字,备注: 商务- # 其他备注:Python专栏- if friend.is_biz(msg): instance.set_alias(username, f'商务-{nickname}') else: instance.set_alias(username, f'python专栏-{nickname}') instance.send_msg(f'添加好友: {nickname} 成功。', 'filehelper') else: print(f'添加好友失败: {nickname}') except Exception: pass
def _wrapper(*args, **kwargs): res = args[0] global is_open msg = res['Text'] to_user = res['ToUserName'] if msg == 'ro': is_open = True instance.send_msg('Miracle 微信机器人已开启', to_user) return if msg == 'rc': is_open = False instance.send_msg('Miracle 微信机器人已开启', to_user) return if is_open: return fn(*args, **kwargs) else: instance.send_msg(f'请发送指令:ro,打开机器人', to_user) return
def update_cmd(self, cmd): _action, _reply, _obj = cmd.split('_') self._meta['action'][_action] = True self.current_cmd = cmd instance.send_msg(self._meta['reply'][_reply], self._meta['extra']['UserName'])