def remote_admin_command(msg): log.logger.info('接收远程管理员命令') log.logger.info(msg) if ('休眠' in msg.text): if (msg.sender == robot_master): thread = threading.Thread(target=remote_down) thread.start() thread.join() return '机器人已休眠' else: msg.chat.send('机器人休眠一分钟') thread = threading.Thread(target=remote_down_minute) thread.start() thread.join() return '机器人休眠一分钟结束' elif ('管理员手册' in msg.text): return FixedReply.handbook_admin elif ('管理员列表' in msg.text): return group_admin elif ('用户手册 娱乐' in msg.text): return FixedReply.handbook_user_entertainment elif ('用户手册 实用' in msg.text): return FixedReply.handbook_user_practical elif (msg.sender == robot_master and '添加管理员' in msg.text): try: name_temp = re.search(r'添加管理员\s*@(.+?)(?:\u2005?\s*$)', msg.text).group(1) except AttributeError as e: log.logger.error("异常" + e) robot_master.send('无法解析命令') return '无法解析命令' try: new_admin = ensure_one(robot.friends().search(name_temp)) except BaseException as e: log.logger.error("异常" + e) return '管理员名称输入错误' return FixedReply.admin_add(robot_master, group_admin, new_admin, name_temp) elif (msg.sender == robot_master and '取消管理员' in msg.text): try: name_temp = re.search(r'取消管理员\s*@(.+?)(?:\u2005?\s*$)', msg.text).group(1) except AttributeError as e: robot_master.send('无法解析命令') log.logger.error("异常" + e) return '无法解析命令' try: old_admin = ensure_one(robot.friends().search(name_temp)) except BaseException as e: log.logger.error("异常" + e) return "管理员名称输入错误" return FixedReply.admin_sub(robot_master, group_admin, old_admin, name_temp) elif ("登出" in msg.text): # print('已成功退出') robot.logout() else: TuLingReply.auto_reply(msg)
def reply_my_friend(msg): if ('用户手册 娱乐' in msg.text): return FixedReply.handbook_user_entertainment elif ('用户手册 实用' in msg.text): return FixedReply.handbook_user_practical elif FixedReply.valid(msg): invite(msg.sender) else: TuLingReply.auto_reply(msg)
def reply_my_friend(msg): log.logger.info("回复来自其他好友(不包括管理员)的消息接收消息:") log.logger.info(msg) try: if ('用户手册 娱乐' in msg.text): return FixedReply.handbook_user_entertainment elif ('用户手册 实用' in msg.text): return FixedReply.handbook_user_practical elif FixedReply.valid(msg): invite(msg.sender) else: TuLingReply.auto_reply(msg) except BaseException as e: log.logger.error("回复来自其他好友(不包括管理员)的消息异常" + e)
def auto_reply(msg): log.logger.info("群聊接收消息:") log.logger.info(msg) try: if (msg.is_at): if ('休眠' in msg.text and msg.member in group_admin): if (msg.member == robot_master): thread = threading.Thread(target=remote_down) thread.start() thread.join() return '机器人已休眠' else: msg.chat.send('机器人休眠一分钟') thread = threading.Thread(target=remote_down_minute) thread.start() thread.join() return '机器人休眠一分钟结束' elif ('取消免打扰' in msg.text and msg.member in group_admin): group_free.append(msg.chat) return '此群已取消免打扰' elif (msg.chat.is_owner and '移出' in msg.text and msg.member == robot_master): try: name_to_kick = re.search(r'移出\s*@(.+?)(?:\u2005?\s*$)', msg.text).group(1) except AttributeError: robot_master.send('无法解析命令') return member_to_kick = ensure_one(msg.chat.search(name_to_kick)) if member_to_kick == robot_master: robot_master.send('在尝试移出自己吗?') return else: member_to_kick.remove() return '已移出 [{}]'.format(name_to_kick) elif ('用户手册 娱乐' in msg.text): return FixedReply.handbook_user_entertainment elif ('用户手册 实用' in msg.text): return FixedReply.handbook_user_practical elif ('管理员列表' in msg.text and msg.member in group_admin): return group_admin elif ('管理员手册' in msg.text and msg.member in group_admin): return FixedReply.handbook_admin else: TuLingReply.auto_reply(msg) except BaseException as e: log.logger.error("群聊接收消息异常" + e)
def repot_time(group_free): isWorkdate = workDate.checkWorkDate() hour = int(time.strftime('%H', time.localtime(time.time()))) if isWorkdate: if hour < 12: nowTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) group_free[0].send( '早上好!\n要上班啦,大家记得打卡,昨天的日报记得写哟:\n{}\n------------今日天气------------\n{}' .format(nowTime, TuLingReply.text_reply('北京西二期天气'))) time.sleep(3) elif hour > 12: nowTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) group_free[0].send( '该下班啦!\n大家 记得打卡,写今天的日报:\n{}\n------------轻松一下------------\n{}'. format(nowTime, TuLingReply.text_reply('讲个笑话'))) time.sleep(3) else: return
def recieve_some(msg): if (msg.is_at and '休眠' in msg.text and msg.member in group_admin): if (msg.member == robot_master): thread = threading.Thread(target=remote_down) thread.start() thread.join() return '机器人已休眠' else: msg.chat.send('机器人休眠一分钟') thread = threading.Thread(target=remote_down_minute) thread.start() thread.join() return '机器人休眠一分钟结束' elif (msg.is_at and '免打扰' in msg.text and msg.member in group_admin): for j in range(len(group_free)): if (group_free[j] == msg.chat): group_free.pop(j) return '此群已免打扰' return elif (msg.is_at and msg.chat.is_owner and '移出' in msg.text and msg.member == robot_master): try: name_to_kick = re.search(r'移出\s*@(.+?)(?:\u2005?\s*$)', msg.text).group(1) print(name_to_kick) except AttributeError: robot_master.send('无法解析命令') return member_to_kick = ensure_one(msg.chat.search(name_to_kick)) if member_to_kick == robot_master: robot_master.send('在{}群组尝试移出自己!'.format(msg.chat)) return '在{}群组尝试移出自己!'.format(msg.chat) else: member_to_kick.remove() return '已移出 [{}]'.format(name_to_kick) elif (msg.is_at and msg.member in group_admin and '添加管理员' in msg.text): try: name_temp = re.search(r'添加管理员\s*@(.+?)(?:\u2005?\s*$)', msg.text).group(1) except AttributeError: robot_master.send('无法解析命令') return try: new_admin = ensure_one(msg.chat.search(name_temp)) except: return '管理员名称输入错误' return FixedReply.admin_add(robot_master, group_admin, new_admin, name_temp) elif (msg.is_at and msg.member == robot_master and '取消管理员' in msg.text): try: name_temp = re.search(r'取消管理员\s*@(.+?)(?:\u2005?\s*$)', msg.text).group(1) except AttributeError: robot_master.send('无法解析命令') return try: old_admin = ensure_one(msg.chat.search(name_temp)) except: return '管理员名称输入错误' return FixedReply.admin_sub(robot_master, group_admin, old_admin, name_temp) elif (msg.is_at and '管理员列表' in msg.text and msg.member in group_admin): return group_admin elif (msg.is_at and '管理员手册' in msg.text and msg.member in group_admin): return FixedReply.handbook_admin elif ('用户手册 娱乐' in msg.text): return FixedReply.handbook_user_entertainment elif ('用户手册 实用' in msg.text): return FixedReply.handbook_user_practical else: TuLingReply.auto_reply(msg)