| 摘要 | 一个主题组件,将与 AI 机器人的私信转换为交互式问答体验。 | |
| 仓库 | GitHub - VaperinaDEV/discourse-quizmaster: A theme component that transforms private messages with an AI bot into an interactive quiz experience. · GitHub | |
| 觉得有用吗? | > ./support --coffee | |
| 安装指南 | 如何安装主题或主题组件 | |
| Discourse 主题新手? | 使用 Discourse 主题的入门指南 |
安装此主题组件
交互式问答主题组件
你好 ![]()
我创建了一个主题组件,它将与 AI 机器人的私信转换为交互式问答体验。该组件自动格式化问答题目,处理答案提交,跟踪进度,并通过方便的头部下拉菜单管理问答完成,以便快速开始问答。
功能
1. 头部下拉菜单问答启动器
站点头部有一个可自定义的下拉按钮,可快速访问不同的问答类型:
- 通过主题设置使用对象模式进行完全可配置
- 支持多语言,集成 i18n 用于标签、描述和消息
- 每个问答难度级别都有可自定义的图标
- 默认选项包括:简单、普通、困难和混合难度问答
- 每个选项都会向 AI 机器人发送预配置的消息以开始问答
2. 自动问答题目格式化
该组件检测并格式化 AI 机器人帖子中的多项选择题。当机器人发布以 “A)”、“B)” 等开头的列表时,这些会自动转换为带有自定义样式的可点击问答选项。
3. 一键提交答案
用户可以直接点击答案选项 (A, B, C, D) 来提交他们的回答。该组件:
- 通过加载状态防止重复提交
- 自动回复到正确的帖子
- 一致地格式化答案(例如,“我的答案:A) 选项文本”)
- 提供带有用户反馈的错误处理
4. 问题计数器
每个问答题目上都会出现一个进度指示器,显示:
- 当前问题编号与允许的最大值
- 可自定义的最大问题数(默认:50)
- 仅在 AI 机器人的帖子上可见
5. 自动问答终止
该组件包含智能的问答管理:
- 里程碑检查点:每 10 个问题显示一次“终止问答”按钮(在第 11、21、31 个问题之后等)
- 硬性限制执行:达到最大问题数时自动发送终止消息
- 防止重复:跟踪终止状态以防止多个终止帖子
- 验证检查:确保仅在适当的时候终止
6. UI 修改
在问答对话中:
- 从机器人帖子中移除 AI 重试/分享按钮(非管理员)
- 从私信中的机器人帖子中移除回复按钮
- 防止问答创建者删除他们自己的帖子(保留问答历史)
- 添加自定义 CSS 主体类
is-quiz-chat用于样式设置
配置
该组件使用以下主题设置:
# 问答行为设置
quizmaster_username: "YourBotUsername" # AI 机器人的用户名
show_for_groups: "" # 头部下拉菜单显示给哪些组
quiz_max_questions: 50 # 自动终止前的最大问题数
# 头部按钮设置
button_icon: "question-circle" # 主要问答按钮的图标
# 下拉菜单问答选项 (对象模式) 最多 4 个
dropdown_items:
type: objects
default:
- label_template: quiz_easy_label
description_template: quiz_easy_description
icon: star
message_template: quizmaster_input_easy
- label_template: quiz_normal_label
description_template: quiz_normal_description
icon: star-half-alt
message_template: quizmaster_input_normal
- label_template: quiz_hard_label
description_template: quiz_hard_description
icon: certificate
message_template: quizmaster_input_hard
- label_template: quiz_mixed_label
description_template: quiz_mixed_description
icon: random
message_template: quizmaster_input_mixed
schema:
properties:
label_template:
type: string
description_template:
type: string
icon:
type: string
message_template:
type: string
svg_icons:
default: "far-star-half"
type: list
list_type: "compact"
description: "此主题组件中使用的 FontAwesome 6 图标列表"
翻译键
将这些添加到您的主题语言文件中,以支持完整的 i18n:
英语 (en.yml)
en:
js:
# 头部按钮
quiz: "Quiz"
# 下拉菜单标签
quiz_easy_label: "Easy Quiz"
quiz_normal_label: "Normal Quiz"
quiz_hard_label: "Hard Quiz"
quiz_mixed_label: "Mixed Quiz"
# 下拉菜单描述
quiz_easy_description: "Basic questions for beginners"
quiz_normal_description: "Average difficulty questions"
quiz_hard_description: "Advanced level challenge"
quiz_mixed_description: "Random difficulty questions"
# 消息模板
quizmaster_input_easy: "Give me an easy quiz question"
quizmaster_input_normal: "Give me a normal difficulty quiz question"
quizmaster_input_hard: "Give me a hard quiz question"
quizmaster_input_mixed: "Give me a mixed difficulty quiz question"
# 问答交互
my_answer: "My answer to the question is:"
terminate_quiz: "Thanks for the game, I'd like a summary!"
max_questions_text: "questions (or until my source runs dry). Every 10, you choose: stay or venture on."
使用场景
此组件非常适合:
- 与 AI 导师的教育问答
- 培训评估
- 知识测试
- 交互式学习体验
- 游戏化内容交付
- 语言学习应用程序
- 认证准备课程
该组件自动处理跟踪状态、防止错误和管理问答生命周期的所有复杂性,为问答创建者和参与者提供流畅的体验。头部下拉菜单使用户可以极其轻松地开始问答。
自定义
管理员可以通过以下方式轻松自定义问答体验:
- 在语言文件中修改问答难度标签和描述
- 添加新的语言翻译
- 更改不同问答类型的图标
- 调整发送给 AI 机器人的消息模板
- 配置哪些用户组可以看到头部按钮
- 设置最大问题数限制
所有自定义都通过管理界面完成,无需接触任何代码。
AI 系统提示
该组件通过检测简单的列表格式与 AI 机器人无缝配合。以下是为您的神秘 AI 机器人准备的示例系统提示(根据需要自定义):
You are the strict but fair professional mystical Quizmaster. Speak with authority but helpfulness, as if you were a modern wizard. Use some magic-related phrases (e.g. 'Let's see what lies in the mist of your knowledge...'), but stick to the technical facts.
### QUIZ DIFFICULTY LEVELS (MODES)
The user will initiate the conversation by specifying a difficulty level. Use the following guidelines to calibrate the depth of your questions:
1. **Easy:**
[Your easy mode criteria here]
2. **Normal:**
[Your normal mode criteria here]
3. **Hard:**
[Your hard mode criteria here]
4. **Mixed:** Randomly select a difficulty and a category for every question.
---
### DYNAMIC RESPONSE LOGIC
**INSTRUCTION:** For every new question, pick a different Category (A-E) than the previous 5 questions.
- **VARIETY RULES:** Never repeat a question or its topic within the same session.
- **LEVEL-UP SUGGESTION:** After every 10-question milestone, if the user has a 100% success rate on Easy or Normal, suggest moving to the next level within the evaluation block.
### CORE RULES:
1. **Continuous Flow:** After evaluating an answer, immediately provide the next question in the SAME message.
2. **Terminating the game:**
* If the user writes: "Thanks for playing, I'd like a summary!", stop immediately.
* Provide a final evaluation based ONLY on answered questions.
* Provide the final score and a mystical goodbye.
3. **SINGLE OUTPUT:** **CRITICAL: Provide the evaluation, the current score, and the NEXT question exactly ONCE. Do not repeat the question or the options list within the same response.**
### RESPONSE STRUCTURE & FORMATTING (MANDATORY):
> [Correct/Incorrect emoji] **[Brief explanation of the previous answer.]**
*Current Score: [X] points*
---
### [Next Question text goes here]
* A) [OPTION_A_TEXT]
* B) [OPTION_B_TEXT]
* C) [OPTION_C_TEXT]
* D) [OPTION_D_TEXT]
---
### AUTOMATION RULES (FOR THE AI):
- **NO WRAP TAGS:** Do not use `[wrap]` tags or any special Discourse syntax for buttons.
- **STRICT LIST FORMAT:** You MUST provide the four options as a simple bulleted list exactly as shown above, starting with "A)", "B)", "C)", and "D)".
- **SYSTEM INTEGRATION:** The external system will automatically detect your A-D list and convert it into interactive buttons. Do not attempt to style the buttons yourself.
### CONSTRAINTS:
- **Language Consistency:** Always respond in the same language the user used.
- The explanation must be inside a blockquote (>).
注意: 我们最初尝试使用 [wrap] 标签来创建按钮,但 AI 有时会遗漏闭合的 ],导致功能失效。简单的项目符号列表格式(* A), * B), 等)更可靠,AI 几乎不可能出错。主题组件会自动检测此格式并将其转换为交互式按钮。
我非常想听听关于您的使用场景。请分享!

