Skip to content

Commit 31f73f7

Browse files
committed
feat: make quiz correct and next question in same message and bot now append the qouted message to the command query if its not long enough
1 parent 2323264 commit 31f73f7

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/commands/quiz.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Message } from "../types/message";
2-
import { quiz } from "../components/utils/data";
2+
import { done, quiz } from "../components/utils/data";
33
import log from "../components/utils/log";
44
import redis from "../components/redis";
55

@@ -12,11 +12,16 @@ export const info = {
1212
cooldown: 5000,
1313
};
1414

15-
export default async function (msg: Message): Promise<void> {
15+
export default async function (
16+
msg: Message,
17+
continueQuiz: boolean = false,
18+
): Promise<void> {
1619
const id = Math.floor(Math.random() * quiz.length);
1720
const response = quiz[id];
1821

1922
let text = `
23+
${continueQuiz && done[Math.floor(Math.random() * done.length)]}
24+
2025
\`${response.question}\`
2126
`;
2227

src/commands/riddle.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Message } from "../types/message";
2-
import { riddles } from "../components/utils/data";
2+
import { done, riddles } from "../components/utils/data";
33
import redis from "../components/redis";
44

55
export const info = {
@@ -11,11 +11,16 @@ export const info = {
1111
cooldown: 5000,
1212
};
1313

14-
export default async function (msg: Message): Promise<void> {
14+
export default async function (
15+
msg: Message,
16+
continueQuiz: boolean = false,
17+
): Promise<void> {
1518
const id = Math.floor(Math.random() * riddles.length);
1619
const response = riddles[id];
1720

1821
let text = `
22+
${continueQuiz && done[Math.floor(Math.random() * done.length)]}
23+
1924
\`${response.question}\`
2025
`;
2126

src/components/events/message.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ export default async function (msg: Message, type: string): Promise<void> {
189189
}
190190

191191
log.info("Message", lid, key);
192-
msg.body = newMessageBody;
192+
193+
if (newMessageBody.split(" ").length === 1 && msg.hasQuotedMsg) {
194+
const qoutedMessage = await msg.getQuotedMessage();
195+
msg.body = (newMessageBody + " " + qoutedMessage.body).trim();
196+
} else {
197+
msg.body = newMessageBody;
198+
}
193199

194200
/*
195201
*

src/components/utils/quiz.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ export default async function (msg: Message): Promise<void> {
3434
log.info("QuizAnswered", quizAttempt.quiz_id, "correct");
3535
await Promise.allSettled([
3636
redis.del(key),
37-
msg.reply(done[Math.floor(Math.random() * done.length)]),
3837
addUserQuizPoints(msg, true),
3938
quoted.delete(true, true),
40-
startNewQuiz(msg),
39+
startNewQuiz(msg, true),
4140
]);
4241
} else {
4342
log.info("QuizAnswered", quizAttempt.quiz_id, "wrong");

src/components/utils/riddle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ export default async function (msg: Message): Promise<void> {
3434
log.info("RiddleAnswered", riddleAttempt.quiz_id, "correct");
3535
await Promise.allSettled([
3636
redis.del(key),
37-
msg.reply(done[Math.floor(Math.random() * done.length)]),
3837
addUserQuizPoints(msg, true, 20),
3938
quoted.delete(true, true),
40-
startNewRiddle(msg),
39+
startNewRiddle(msg, true),
4140
]);
4241
} else {
4342
log.info("RiddleAnsweredWrong", riddleAttempt.quiz_id, "wrong");

0 commit comments

Comments
 (0)