diff --git a/game_task/game_chatgpt_qa.py b/game_task/game_chatgpt_qa.py index 2326f27..82d45ba 100644 --- a/game_task/game_chatgpt_qa.py +++ b/game_task/game_chatgpt_qa.py @@ -52,13 +52,22 @@ def message_task_json(prompt, content): def game_question_json(question): - prompt = """请根据以下要求,随机生成一个问题,确保每次提问都涉及不同的领域,并且每个问题都互不相关: - 本次的问题请充满乐趣,请确保问题足够简洁且容易理解,适合百科类知识问答。 - 每个问题都应当独立,问题之间不应具有连贯性或延续性。 - 避免重复提问或相似问题,确保每个问题都是全新的。 - ,问题需要有一定的难度,回答完毕之后用户能有所收获,并且对问题进行打分,同时根据问题难度告知答对之后给多少分(1-10)请只返回JSON格式的内容: - 格式要求如下(请不要加上markdown 的符号):{\"question\": \"哪个国家最早将玫瑰与爱情联系起来?\", \"score\":\"1\", \"answer\": \"波斯\",\"description\":\"描述问题答案的原因\"} - """ + prompt = """ + 请根据以下要求,随机生成一个问题,确保每次提问涉及不同领域,且不重复: + 1. 每个问题应该覆盖以下任意领域:近现代史、战争与政治、文化遗产与考古学、进化论、动植物学、基因与遗传学、生态学、有机化学、无机化学、生物化学、环境化学、人文地理、自然地理、地质学、气候变化、古典文学、现代文学、小说与戏剧、诗歌与散文、美术、音乐、戏剧与舞蹈、电影与媒体、西方哲学、东方哲学、道德与伦理学、逻辑与认识论、人类学、心理学、政治学、经济学、编程语言、人工智能、数据科学、网络与安全、机械工程、电气工程、化学工程、土木工程、解剖学、生理学、临床医学、药学与护理、球类运动、奥林匹克运动、运动心理学、健身与营养、世界宗教、神话与民间故事、宗教哲学、语法与词汇、语言习得、方言与语言变异、宏观经济学、微观经济学、国际贸易、金融与投资、民法与刑法、国际法、知识产权法、环境法。 + 2. 问题应简洁,具有一定难度,易于理解且充满乐趣,适合百科类知识问答。 + 3. 每个问题应独立,且问题之间无连贯性或延续性。 + 4. 避免重复提问或产生相似的问题,确保问题新颖。 + 5. 对于每个问题,提供难度评分(1-10分)。在问题答对后,用户可以根据难度给出相应的分数。 + + 输出格式要求如下(仅返回JSON格式,确保不添加多余的符号): + { + "question": "哪个国家最早将玫瑰与爱情联系起来?", + "score": "1", + "answer": "波斯", + "description": "波斯文化中,玫瑰被广泛认为是象征爱情的花卉,其象征意义逐渐传入西方。" + } + """ return message_task_json(prompt, question) @@ -69,5 +78,5 @@ def game_answer_json(answer): if __name__ == '__main__': - print(game_question_json('请从不同的学科领域(历史学:古代历史、近现代史、战争与政治、文化遗产与考古学;生物学:进化论、动植物学、基因与遗传学、生态学;化学:有机化学、无机化学、生物化学、环境化学;地理学:人文地理、自然地理、地质学、气候变化;文学:古典文学、现代文学、小说与戏剧、诗歌与散文;艺术:美术、音乐、戏剧与舞蹈、电影与媒体;哲学:西方哲学、东方哲学、道德与伦理学、逻辑与认识论;社会学:人类学、心理学、政治学、经济学;计算机科学:编程语言、人工智能、数据科学、网络与安全;工程学:机械工程、电气工程、化学工程、土木工程;医学:解剖学、生理学、临床医学、药学与护理;体育:球类运动、奥林匹克运动、运动心理学、健身与营养;宗教与神话:世界宗教、神话与民间故事、宗教哲学;语言学:语法与词汇、语言习得、方言与语言变异;经济学:宏观经济学、微观经济学、国际贸易、金融与投资;法律:民法与刑法、国际法、知识产权法、环境法)生成一个全新问题。')) + print(game_question_json('请出题!')) # print(game_answer_json('question:哪个国家的节日与裸体狂欢有关?,answer:古罗马,top_score:3')) diff --git a/game_task/game_task_encyclopedia.py b/game_task/game_task_encyclopedia.py index f39a286..7718156 100644 --- a/game_task/game_task_encyclopedia.py +++ b/game_task/game_task_encyclopedia.py @@ -14,10 +14,12 @@ db_config = { 'cursorclass': pymysql.cursors.DictCursor } + # 连接数据库 def get_db_connection(): return pymysql.connect(**db_config) + # 添加群聊 def add_group(group_id, player_id): conn = get_db_connection() @@ -35,6 +37,7 @@ def add_group(group_id, player_id): cursor.close() conn.close() + # 获取所有群聊ID def get_group_ids(): conn = get_db_connection() @@ -46,6 +49,7 @@ def get_group_ids(): cursor.close() conn.close() + # 确保游戏启动(自动初始化群聊和玩家) def ensure_game_started(group_id, player_id, player_name="未知玩家"): conn = get_db_connection() @@ -79,6 +83,7 @@ def ensure_game_started(group_id, player_id, player_name="未知玩家"): cursor.close() conn.close() + # 随机分配任务 def assign_random_task(group_id, player_id=None): conn = get_db_connection() @@ -147,6 +152,7 @@ def assign_random_task(group_id, player_id=None): cursor.close() conn.close() + # 提交答案并计分 def submit_answer(group_id, player_id, task_id, answer): conn = get_db_connection() @@ -277,6 +283,7 @@ def submit_answer(group_id, player_id, task_id, answer): cursor.close() conn.close() + # 显示排行榜 def show_rank(group_id, player_id): conn = get_db_connection() @@ -301,6 +308,7 @@ def show_rank(group_id, player_id): cursor.close() conn.close() + # 显示当前活跃任务 def show_active_tasks(group_id, player_id): conn = get_db_connection() @@ -331,6 +339,7 @@ def show_active_tasks(group_id, player_id): cursor.close() conn.close() + # 列举所有未完成任务 def list_uncompleted_tasks(group_id, player_id): conn = get_db_connection() @@ -361,6 +370,7 @@ def list_uncompleted_tasks(group_id, player_id): cursor.close() conn.close() + # 定时任务:整点触发,排除23:00-08:00 def run_random_task_assignment(group_id): current_hour = datetime.now().hour @@ -370,6 +380,7 @@ def run_random_task_assignment(group_id): result = assign_random_task(group_id) print(f"{datetime.now()} {result}") + # 处理群聊消息 def game_process_message(group_id, player_id, message, player_name="未知玩家"): # 自动初始化群聊和玩家 @@ -436,15 +447,17 @@ def game_process_message(group_id, player_id, message, player_name="未知玩家 f"🎀 /r - 查看排行榜" ) + # 设置定时任务 def setup_schedule(): group_ids = get_group_ids() for gid in group_ids: run_random_task_assignment(group_id=gid) + # 主程序 if __name__ == "__main__": # 测试用例 print(game_process_message("45317011307@chatroom", "Jyunere", "/t")) # 新用户获取任务 print(game_process_message("45317011307@chatroom", "Jyunere", "/a 18 罗马斗兽场")) # 提交答案 - print(game_process_message("45317011307@chatroom", "Jyunere", "/r")) # 查看排行榜 \ No newline at end of file + print(game_process_message("45317011307@chatroom", "Jyunere", "/r")) # 查看排行榜 diff --git a/xiuren/xiuren_dl.py b/xiuren/xiuren_dl.py new file mode 100644 index 0000000..ad03120 --- /dev/null +++ b/xiuren/xiuren_dl.py @@ -0,0 +1,49 @@ +import requests +from lxml import etree +import os + +# 设置目标URL和请求头 +url = "https://www.xiurenwang.cc/bang?f=7" +headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "Referer": "https://www.xiurenwang.cc/" +} + +# 发送请求获取网页内容 +response = requests.get(url, headers=headers) +response.encoding = "utf-8" # 确保正确解码 + +# 解析HTML +html = etree.HTML(response.text) + +# 提取图片链接和标题(假设最新图片在列表页面中) +image_items = html.xpath('//div[@class="list"]/li/a[@class="img"]/@href') +titles = html.xpath('//div[@class="tit"]/a/text()') + +# 创建保存图片的文件夹 +save_dir = "./xiuren_images" +if not os.path.exists(save_dir): + os.makedirs(save_dir) + +# 只获取最新的一个条目(假设第一个是最新的) +if image_items: + latest_url = "https://www.xiurenwang.cc" + image_items[0] # 拼接详情页URL + latest_title = titles[0] if titles else "latest_image" + + # 访问详情页获取图片 + detail_response = requests.get(latest_url, headers=headers) + detail_html = etree.HTML(detail_response.text) + image_urls = detail_html.xpath('//div[@id="image"]/a/@href') + + # 下载图片 + for idx, img_url in enumerate(image_urls): + img_response = requests.get(img_url, headers=headers) + img_name = f"{latest_title}_{idx + 1}.jpg" + img_path = os.path.join(save_dir, img_name.replace('/', '_')) # 避免文件名中的斜杠 + with open(img_path, "wb") as f: + f.write(img_response.content) + print(f"已下载: {img_path}") +else: + print("未找到图片链接,可能需要调整XPath或检查网站结构。") + +print("最新图片下载完成!")