async def handle_msg_group(context): global last_cmd global last_arg_str global last_arg_int message = context['message'] if config.need_at_me: if not is_at_me(message): return if is_at_me(message): message = rm_at_me(message) message = message.strip() cmd_args = message.split(' ') cmd = cmd_args[0] args = cmd_args[1:] if len(cmd_args) > 1 else [] def is_all_number(_str: str): if _str is None or _str == '': return False for a in _str: if not '0' <= a <= '9': return False return True arg_int = int(args[0]) if len(args) > 0 and is_all_number(args[0]) else 0 arg_int_2 = int(args[1]) if len(args) > 1 and is_all_number(args[1]) else 0 arg_str = args[0] if len(args) > 0 else '' qq_num = str(context['sender']['user_id']) qq_name = context['sender']['nickname'] if 'card' in context['sender'] and context['sender']['card'] != '': qq_name = context['sender']['card'] qq_group = '-1' if 'group_id' in context: qq_group = str(context['group_id']) if cmd == '-help' or cmd == '-?': msg = '● 个人信息 -personal' msg += '\n● 排行榜 -rank [index]' msg += '\n● 查询文件 -find [keyword]' msg += '\n● 文件信息 -info [id]' msg += '\n● 更多信息 -more' msg += sep_s() msg += '\n* 输入CSDN下载页链接下载' msg += source_code_tail() msg += donate_tail() msg += export_tail() last_cmd = cmd await bot.send(context, msg) if cmd == '-user': await bot.send(context, '查询用户信息中...') helper.init() info = helper.get_user_info() helper.dispose() if info is None: msg = '获取用户信息失败!' else: msg = '{}'.format(info['name']) if info['vip']: msg += '【VIP】' msg += '\n剩余次数:{}次'.format(info['remain']) msg += '\n有效期至:{}'.format(info['date'][:10]) else: msg += '\n剩余积分:{}积分'.format(info['remain']) await bot.send(context, msg) if cmd == '-rank': result = db_helper.rank_qq(arg_int) msg = build_rank_msg(result, arg_int) last_cmd = cmd last_arg_int = arg_int await bot.send(context, msg) if cmd == '-find': result = db_helper.find_all(arg_str, arg_int_2) count = db_helper.count_all(arg_str) msg = build_find_msg(result, count, arg_int_2) last_cmd = cmd last_arg_str = arg_str last_arg_int = arg_int_2 await bot.send(context, msg) if cmd == '-info': result = db_helper.get_download(arg_int) if result is not None: msg = build_download_info(result) last_cmd = cmd last_arg_str = arg_str last_arg_int = arg_int await bot.send(context, msg) else: await bot.send(context, '文件不存在。') if cmd == '-donors': msg = build_donors(arg_int) last_cmd = cmd last_arg_int = arg_int await bot.send(context, msg) if cmd == '-personal': msg = build_personal(qq_num, qq_group, qq_name) await bot.send(context, msg) if cmd == '-more': if last_cmd == '-find': last_arg_int += 10 result = db_helper.find_all(last_arg_str, last_arg_int) count = db_helper.count_all(last_arg_str) msg = build_find_msg(result, count, last_arg_int) await bot.send(context, msg) if last_cmd == '-rank': last_arg_int += 10 result = db_helper.rank_qq(last_arg_int) msg = build_rank_msg(result, last_arg_int) await bot.send(context, msg) if last_cmd == '-info': result = db_helper.get_download(last_arg_int) if result is not None: msg = build_download_detail_info(result) await bot.send(context, msg) if last_cmd == '-donors': last_arg_int += 10 msg = build_donors(last_arg_int) await bot.send(context, msg) if last_cmd == '-help' or last_cmd == '-?': msg = '● 用户信息 -user' msg += '\n● 捐赠名单 -donors' msg += sep_s() msg += '\n* 输入CSDN下载页链接下载' msg += source_code_tail() msg += donate_tail() msg += export_tail() await bot.send(context, msg) download_id = find_csdn_download_id(context['message']) if download_id is not None: if helper.__already_download(download_id) and db_helper.exist_download( download_id): msg = build_download_info(db_helper.get_download(download_id)) await bot.send(context, msg) return download_url = find_csdn_download_url(context['message']) if download_url is not None: can_download, msg = helper.check_download_limit(qq_num, qq_group) if not can_download: await bot.send(context, msg) return if helper.is_busy(): await bot.send(context, '资源正在下载中,请稍后...') return await bot.send(context, '开始下载...') try: helper.init() download_info = helper.auto_download(download_url, qq_num, qq_name, qq_group) msg = download_info['message'] if download_info['success']: result = db_helper.get_download(download_info['info']['id']) msg = build_download_info(result) last_cmd = '-info' last_arg_int = int(result.id) elif donate_tail() != '': msg += sep_s() msg += donate_tail() await bot.send(context, msg) finally: helper.dispose()
async def handle_msg(context): # 下面这句等价于 bot.send_private_msg(user_id=context['user_id'], message='你好呀,下面一条是你刚刚发的:') """ try: await bot.send(context, '你好呀,下面一条是你刚刚发的:') except ApiError: pass """ global last_cmd global last_arg_str global last_arg_int message = context['message'] if message.startswith('@{}'.format(config.default_qq_name)): message = message[4:] message = message.strip() cmd_args = message.split(' ') cmd = cmd_args[0] args = cmd_args[1:] if len(cmd_args) > 1 else [] def is_all_number(_str: str): if _str is None or _str == '': return False for a in _str: if not '0' <= a <= '9': return False return True arg_int = int(args[0]) if len(args) > 0 and is_all_number(args[0]) else 0 arg_int_2 = int(args[1]) if len(args) > 1 and is_all_number(args[1]) else 0 arg_str = args[0] if len(args) > 0 else '' if cmd == '-help' or cmd == '-?': msg = '● 用户信息 -user' msg += '\n● 排行榜 -rank [index]' msg += '\n● 查询文件 -find [keyword]' msg += '\n● 文件信息 -info [id]' msg += '\n● 更多信息 -more' msg += '\n' + '-' * 38 msg += '\n* 直接输入CSDN下载页链接即可下载' msg += '\n* 大黄鸭源码 http://t.cn/EK5Q58Y' await bot.send(context, msg) if cmd == '-user': await bot.send(context, '查询用户信息中...') helper.init() info = helper.get_user_info() helper.dispose() if info is None: msg = '获取用户信息失败!' else: msg = '{}'.format(info['name']) if info['vip']: msg += '【VIP】' msg += '\n剩余次数:{}次'.format(info['remain']) msg += '\n有效期至:{}'.format(info['date'][:10]) else: msg += '\n剩余积分:{}积分'.format(info['remain']) await bot.send(context, msg) if cmd == '-rank': result = db_helper.rank_qq(arg_int) msg = build_rank_msg(result, arg_int) last_cmd = cmd last_arg_int = arg_int await bot.send(context, msg) if cmd == '-find': result = db_helper.find_all(arg_str, arg_int_2) count = db_helper.count_all(arg_str) msg = build_find_msg(result, count, arg_int_2) last_cmd = cmd last_arg_str = arg_str last_arg_int = arg_int_2 await bot.send(context, msg) if cmd == '-info': result = db_helper.get_download(arg_int) if result is not None: msg = build_download_info(result) last_cmd = cmd last_arg_str = arg_str last_arg_int = arg_int await bot.send(context, msg) else: await bot.send(context, '文件不存在。') if cmd == '-more': if last_cmd == '-find': last_arg_int += 10 result = db_helper.find_all(last_arg_str, last_arg_int) count = db_helper.count_all(arg_str) msg = build_find_msg(result, count, last_arg_int) await bot.send(context, msg) if last_cmd == '-rank': last_arg_int += 10 result = db_helper.rank_qq(last_arg_int) msg = build_rank_msg(result, last_arg_int) await bot.send(context, msg) if last_cmd == '-info': result = db_helper.get_download(last_arg_int) if result is not None: msg = build_download_detail_info(result) await bot.send(context, msg) download_url = find_csdn_download_url(context['message']) if download_url is not None: if helper.is_busy(): await bot.send(context, '资源正在下载中,请稍后...') return await bot.send(context, '开始下载...') try: helper.init() qq_num = context['sender']['user_id'] qq_name = context['sender']['nickname'] if 'card' in context['sender'] and context['sender']['card'] != '': qq_name = context['sender']['card'] download_info = helper.auto_download(download_url, qq_num, qq_name) msg = download_info['message'] if download_info['success']: result = db_helper.get_download(download_info['info']['id']) msg = build_download_info(result) last_cmd = '-info' last_arg_int = int(result.id) await bot.send(context, msg) finally: helper.dispose()