def send_alert(group_id, user_class, type='private'): group_menbers = globalDB.get_class_members(user_class) current_date = time.strftime("%Y-%m-%d", time.localtime()) alert_users = {} #user_id:last_date for user_id in group_menbers: #print(user_id) try: last_date = dbconn.check_status(user_id) except TypeError: #还没发过照片 alert_users[user_id] = '无记录' else: if (str(last_date) != str(current_date)): alert_users[user_id] = str(last_date)[5:] #print(alert_users) msg = f"今天还有{len(alert_users)}位小可爱未完成哦\n" if (type == 'private'): for user_id in alert_users.keys(): last_date = alert_users[user_id] msg += f"{globalDB.get_user(user_id)['user_name']}({alert_users[user_id]})" msg += f"{globalDB.get_user(user_id)['user_count']}\n" msg += f"{user_class} {current_date}\n完成情况:{len(group_menbers)-len(alert_users)}/{len(group_menbers)}" goapi.sendMsg(group_id, msg) elif (type == 'group'): for user_id in alert_users.keys(): globalDB.add_user_count(str(user_id)) last_date = alert_users[user_id] msg += f"[CQ:at,qq={user_id}]({alert_users[user_id]})-" msg += f"{globalDB.get_user(user_id)['user_count']}\n" msg += f"{user_class} {current_date}\n完成情况:{len(group_menbers)-len(alert_users)}/{len(group_menbers)}" goapi.sendGroupMsg(group_id, msg)
def handler(message, qid, type, message_id): """获取舔狗""" url = 'http://api.tianapi.com/txapi/tiangou/index' params = {'key':'ce9683fb3b39fb211a0834c09165c599'} res = requests.get(url,params=params) res_dict = json.loads(res.text) text = "" if(res_dict['code'] == 200): text = res_dict['newslist'][0]['content'] #return text if(type == 'private'): goapi.sendMsg(qid, text) else: goapi.sendGroupMsg(qid, text)
def timer_task(): """定时执行任务""" #命令行执行参数 if (len(sys.argv) > 1): opt = sys.argv[1] else: logger.plog("timer", "命令行参数获取出错") return if (opt == 'zaoan'): #早安 for groupId in group_list1: goapi.sendGroupMsg( groupId, "☀️早安\n" + apis.get_history_today() + "\n" + apis.english_img()) elif (opt == 'wanan'): for groupId in group_list1: goapi.sendGroupMsg(groupId, "时间不早啦,赶快休息吧。\n" + apis.getBingImg())
def handler(message, qid, type, message_id): """获取网易云热评""" url = 'https://v1.hitokoto.cn' params = {'c': 'j'} res = requests.get(url, params=params) res_dict = json.loads(res.text) text = "" if (res_dict['from']): text = res_dict['hitokoto'] + '——' + res_dict['from'] else: text = res_dict['hitokoto'] if (type == 'private'): goapi.sendMsg(qid, text) else: goapi.sendGroupMsg(qid, text)
def amuseRouter(message, qid, type, message_id): """娱乐插件路由""" if ('#help' in message): if (type == 'private'): goapi.sendMsg(qid, f"当前支持娱乐功能:{ENABLED_PLUGINS}") else: goapi.sendGroupMsg(qid, f"当前支持娱乐功能:{ENABLED_PLUGINS}") return if (qid in DISABLE_GROUP) or (qid in DISABLE_FRIEND): if (type == 'private'): goapi.sendMsg(qid, "抱歉,您暂无此权限") else: goapi.sendGroupMsg(qid, "抱歉,您所在的群组暂无此权限") else: try: message = message[1:] if not ('[CQ' in message): #无CQ码,空格分割函数名和参数列表 func_name = message.split(' ')[0] else: #有CQ码,按CQ码分割函数名和参数列表 func_name = message.split('[')[0] #检查插件名称合法性,防止eval注入 if (func_name not in ENABLED_PLUGINS): logger.plog("AmuseCtrl", f"找不到娱乐模块'{func_name}'", "warning") if (type == 'private'): goapi.sendMsg(qid, f"还没有'{func_name}'功能呢~") else: goapi.sendGroupMsg(qid, f"还没有'{func_name}'功能呢~") cmd = f"__import__('{func_name}').handler('{message}','{qid}','{type}','{message_id}')" eval(cmd) except: logger.plog("AmuseCtrl", f"用户调用娱乐模块'{func_name}'失败\n命令:{cmd}", "error") else: logger.plog("AmuseCtrl", f"成功调用娱乐模块'{func_name}'")