Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
ptkdev committed Nov 17, 2022
2 parents bc8ab22 + f498e4b commit d8df0e0
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 59 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# v0.7.4 (November 17, 2022)
# v0.7.5 (November 18, 2022)

- Fix: misprint in the translation
- Fix: unpin if exist question and use `/master`
- Fix: unpin if exist question and master send again a new question
- New: `/master off` to stop bot
- New: vote buttons in win message
- Fix: `/score @nickname`

<!-- all-shields/sponsors-badges:START -->

[![Donate Paypal](https://img.shields.io/badge/donate-paypal-005EA6.svg?style=for-the-badge&logo=paypal)](https://www.paypal.me/ptkdev) [![Donate Ko-Fi](https://img.shields.io/badge/donate-ko--fi-29abe0.svg?style=for-the-badge&logo=ko-fi)](https://ko-fi.com/ptkdev) [![Donate Github Sponsors](https://img.shields.io/badge/donate-sponsors-ea4aaa.svg?style=for-the-badge&logo=github)](https://github.com/sponsors/ptkdev) [![Donate Patreon](https://img.shields.io/badge/donate-patreon-F87668.svg?style=for-the-badge&logo=patreon)](https://www.patreon.com/join/ptkdev) [![Donate Bitcoin](https://img.shields.io/badge/BTC-35jQmZCy4nsxoMM3QPFrnZePDVhdKaHMRH-E38B29.svg?style=flat-square&logo=bitcoin)](https://ptk.dev/img/icons/menu/bitcoin_wallet.png) [![Donate Ethereum](https://img.shields.io/badge/ETH-0x8b8171661bEb032828e82baBb0B5B98Ba8fBEBFc-4E8EE9.svg?style=flat-square&logo=ethereum)](https://ptk.dev/img/icons/menu/ethereum_wallet.png)

<!-- all-shields/sponsors-badges:END -->

# v0.7.4 (November 17, 2022)

- Fix: misprint in the translation
- Fix: unpin if exist question and use `/master`
- Fix: unpin if exist question and master send again a new question
- New: `/master off` to stop bot

# v0.7.3 (November 07, 2022)

- Fix: Telegram Topics
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- all-shields/header-badges:START -->

[![v0.7.4](https://img.shields.io/badge/version-v0.7.4-lightgray.svg?style=flat&logo=)](https://github.com/ptkdev/quizquickanswer-telegram-game-bot/blob/main/CHANGELOG.md) [![](https://img.shields.io/npm/v/@ptkdev/quizquickanswer-telegram-game-bot?color=CC3534&logo=npm)](https://www.npmjs.com/package/@ptkdev/quizquickanswer-telegram-game-bot) [![License: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat&logo=license)](https://github.com/ptkdev/quizquickanswer-telegram-game-bot/blob/main/LICENSE.md) [![Language: TypeScript](https://img.shields.io/badge/language-typescript-blue.svg?style=flat&logo=typescript)](https://www.typescriptlang.org/) [![Framework: Grammy](https://img.shields.io/badge/powered%20by-grammy-009dca.svg?style=flat&logo=telegram)](https://grammy.dev/) [![ECMAScript: 2019](https://img.shields.io/badge/ES-9-F7DF1E.svg?style=flat&logo=javascript)](https://github.com/tc39/ecma262) [![Discord Server](https://discordapp.com/api/guilds/383373985666301975/embed.png)](https://discord.ptkdev.io)
[![v0.7.5-beta.1](https://img.shields.io/badge/version-v0.7.5--beta.1-lightgray.svg?style=flat&logo=)](https://github.com/ptkdev/quizquickanswer-telegram-game-bot/blob/main/CHANGELOG.md) [![](https://img.shields.io/npm/v/@ptkdev/quizquickanswer-telegram-game-bot?color=CC3534&logo=npm)](https://www.npmjs.com/package/@ptkdev/quizquickanswer-telegram-game-bot) [![License: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat&logo=license)](https://github.com/ptkdev/quizquickanswer-telegram-game-bot/blob/main/LICENSE.md) [![Language: TypeScript](https://img.shields.io/badge/language-typescript-blue.svg?style=flat&logo=typescript)](https://www.typescriptlang.org/) [![Framework: Grammy](https://img.shields.io/badge/powered%20by-grammy-009dca.svg?style=flat&logo=telegram)](https://grammy.dev/) [![ECMAScript: 2019](https://img.shields.io/badge/ES-9-F7DF1E.svg?style=flat&logo=javascript)](https://github.com/tc39/ecma262) [![Discord Server](https://discordapp.com/api/guilds/383373985666301975/embed.png)](https://discord.ptkdev.io)

<!-- all-shields/header-badges:END -->

Expand Down Expand Up @@ -50,14 +50,14 @@ Funny quiz game, play with friends on your telegram group!
1. Add [@QuizQuickAnswerBot](https://t.me/QuizQuickAnswerBot) to your Telegram group
2. Make **@QuizQuickAnswerBot** admin of your group
3. Run `/start` or `/start@QuizQuickAnswerBot`
4. Make yourself master of game, run `/master @YOUR_NICKNAME`
4. Make yourself master of game, run `/master @nickname`
5. Follow instructions and Play with friends!

## 🎮 How to play

1. Set a master with `/master @YOUR_NICKNAME`
1. Set a master with `/master @nickname`
2. Master send private message to [@QuizQuickAnswerBot](https://t.me/QuizQuickAnswerBot)
3. Master write question with syntax: `QUESTION - TIP`, example: `gameboy - '90s' portable console`
3. Master write question with syntax: `QUESTION ## TIP`, example: `gameboy ## '90s' portable console`
4. Friends try to answer quickly in the telegram group. Who reply with right answer is the new master!

## ⏱ Official Group
Expand Down
1 change: 1 addition & 0 deletions app/functions/api/database/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const schema = new Schema<MasterInterface>({
question: { type: String, default: "" },
description: { type: String, default: "" },
pin_id: { type: Number, default: 0 },
win_message_id: { type: Number, default: 0 },
message_thread_id: { type: Number, default: 0 },
});

Expand Down
6 changes: 6 additions & 0 deletions app/functions/api/database/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const schema = new Schema<QuestionsInterface>({
downvotes_2021: { type: Number, default: 0 },
upvotes_2022: { type: Number, default: 0 },
downvotes_2022: { type: Number, default: 0 },
upvotes_2023: { type: Number, default: 0 },
downvotes_2023: { type: Number, default: 0 },
upvotes_2024: { type: Number, default: 0 },
downvotes_2024: { type: Number, default: 0 },
upvotes_2025: { type: Number, default: 0 },
downvotes_2025: { type: Number, default: 0 },
voters: { type: Object, default: { message_id: 0, users: { upvotes: [], downvotes: [] } } },
});

Expand Down
41 changes: 28 additions & 13 deletions app/functions/commands/hears.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const hears = async (): Promise<void> => {
translate(lang.language, "hears_missing_tip"),
);
} else {
if (master?.win_message_id > 0) {
await telegram.api.message.removeMessageMarkup(master?.group_id, master?.win_message_id);
}

if (master?.pin_id > 0) {
await telegram.api.message.unpin(ctx, master?.group_id, master?.pin_id);
}
Expand All @@ -71,16 +75,11 @@ const hears = async (): Promise<void> => {
});

master_in_multi_groups.forEach(async (master_in_group) => {
const buttons = new InlineKeyboard();
buttons.text(`👍 0`, "upvote");
buttons.text(`👎 0`, "downvote");

const quiz = await telegram.api.message.send(
ctx,
master_in_group?.group_id,
`⏱ ${json.description || ""}`,
{
reply_markup: buttons,
message_thread_id: master_in_group.message_thread_id,
},
);
Expand Down Expand Up @@ -132,31 +131,42 @@ const hears = async (): Promise<void> => {
user_id: telegram.api.message.getUserID(ctx),
});

await telegram.api.message.send(
const buttons = new InlineKeyboard();
buttons.text(`👍 0`, `upvote ${master.id}`);
buttons.text(`👎 0`, `downvote ${master.id}`);

const win_message = await telegram.api.message.send(
ctx,
master?.group_id,
translate(lang.language, "hears_win", {
first_name: telegram.api.message.getUserFirstName(ctx),
username: telegram.api.message.getUsername(ctx),
bot_username: telegram.api.bot.getUsername(ctx),
answer: telegram.api.message.getText(ctx),
answer: master.question,
tip: master.description,
score: user_questions
? (user_score?.[`score_${new Date().getFullYear()}`] || 0) +
10 +
user_questions[`upvotes_${new Date().getFullYear()}`] -
user_questions[`downvotes_${new Date().getFullYear()}`]
: (user_score?.[`score_${new Date().getFullYear()}`] || 0) + 10,
}),
{ reply_markup: buttons, parse_mode: "HTML" },
);

await telegram.api.message.unpin(ctx, master?.group_id, master?.pin_id);
if (master?.win_message_id > 0) {
await telegram.api.message.removeMessageMarkup(master?.group_id, master?.win_message_id);
}

await telegram.api.message.removeMessageMarkup(master?.group_id, master?.pin_id);
if (master?.pin_id > 0) {
await telegram.api.message.unpin(ctx, master?.group_id, master?.pin_id);
}

const json: MasterInterface = telegram.api.message.getFullUser(ctx);
json.question = "";
json.description = "";
json.group_id = telegram.api.message.getChatID(ctx);
json.win_message_id = win_message?.message_id || 0;
json.message_thread_id = telegram.api.message.getThreadID(ctx);

await db.master.update({ group_id: telegram.api.message.getChatID(ctx) }, json);
Expand Down Expand Up @@ -210,11 +220,16 @@ const hears = async (): Promise<void> => {
}
});

bot.callbackQuery("upvote", async (ctx) => {
await vote(ctx, "upvote");
bot.callbackQuery(/upvote (.*)/, async (ctx) => {
const match: any = ctx.match;

await vote(ctx, "upvote", match.input.replace("upvote ", ""));
});
bot.callbackQuery("downvote", async (ctx) => {
await vote(ctx, "downvote");

bot.callbackQuery(/downvote (.*)/, async (ctx) => {
const match: any = ctx.match;

await vote(ctx, "downvote", match.input.replace("downvote ", ""));
});
};

Expand Down
27 changes: 12 additions & 15 deletions app/functions/commands/hearsphoto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const hearsPhoto = async (): Promise<void> => {
translate(lang.language, "hears_missing_tip"),
);
} else {
if (master?.win_message_id > 0) {
await telegram.api.message.removeMessageMarkup(master?.group_id, master?.win_message_id);
}

if (master?.pin_id > 0) {
await telegram.api.message.unpin(ctx, master?.group_id, master?.pin_id);
}
Expand All @@ -75,14 +79,7 @@ const hearsPhoto = async (): Promise<void> => {
photo_id,
{
caption: `⏱ ${json.description || ""}`,
reply_markup: {
inline_keyboard: [
[
{ text: `👍 0`, callback_data: "upvote" },
{ text: `👎 0`, callback_data: "downvote" },
],
],
},

message_thread_id: master_in_group.message_thread_id,
},
);
Expand All @@ -103,6 +100,13 @@ const hearsPhoto = async (): Promise<void> => {
group_id: master_in_group?.group_id,
});

if (master?.win_message_id > 0) {
await telegram.api.message.removeMessageMarkup(
master?.group_id,
master?.win_message_id,
);
}

await telegram.api.message.unpin(
ctx,
master_in_group?.group_id,
Expand Down Expand Up @@ -132,13 +136,6 @@ const hearsPhoto = async (): Promise<void> => {
}
}
});

bot.callbackQuery("upvote", async (ctx) => {
await vote(ctx, "upvote");
});
bot.callbackQuery("downvote", async (ctx) => {
await vote(ctx, "downvote");
});
};

export { hearsPhoto };
Expand Down
5 changes: 5 additions & 0 deletions app/functions/commands/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const master = async (): Promise<void> => {
score_2024: 0,
score_2025: 0,
pin_id: 0,
win_message_id: 0,
group_id: telegram.api.message.getChatID(ctx),
message_thread_id: telegram.api.message.getThreadID(ctx),
};
Expand All @@ -69,6 +70,10 @@ const master = async (): Promise<void> => {
group_id: telegram.api.message.getChatID(ctx),
});

if (master?.win_message_id > 0) {
await telegram.api.message.removeMessageMarkup(master?.group_id, master?.win_message_id);
}

if (master?.pin_id > 0) {
await telegram.api.message.unpin(ctx, master?.group_id, master?.pin_id);
}
Expand Down
16 changes: 9 additions & 7 deletions app/functions/commands/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ const score = async (): Promise<void> => {
});

if (user_questions) {
score[`score_${new Date().getFullYear()}`] +=
(user_questions[`upvotes_${new Date().getFullYear()}`] || 0) -
(user_questions[`downvotes_${new Date().getFullYear()}`] || 0);
score[`score_${new Date().getFullYear()}`] =
score[`score_${new Date().getFullYear()}`] +
user_questions[`upvotes_${new Date().getFullYear()}`] -
user_questions[`downvotes_${new Date().getFullYear()}`];
}

await telegram.api.message.send(
Expand All @@ -73,13 +74,14 @@ const score = async (): Promise<void> => {
});
const user_questions: QuestionsInterface = await db.questions.get({
group_id: telegram.api.message.getChatID(ctx),
user_id: telegram.api.message.getUserID(ctx),
user_id: score.id,
});

if (user_questions) {
score[`score_${new Date().getFullYear()}`] +=
(user_questions[`upvotes_${new Date().getFullYear()}`] || 0) -
(user_questions[`downvotes_${new Date().getFullYear()}`] || 0);
score[`score_${new Date().getFullYear()}`] =
score[`score_${new Date().getFullYear()}`] +
user_questions[`upvotes_${new Date().getFullYear()}`] -
user_questions[`downvotes_${new Date().getFullYear()}`];
}

await telegram.api.message.send(
Expand Down
8 changes: 5 additions & 3 deletions app/functions/commands/top_yearly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { QuestionsInterface } from "@app/types/question.interfaces";
import logger from "@app/functions/utils/logger";

const topYearly = async (): Promise<void> => {
bot.command(["top2021", "top2022"], async (ctx) => {
bot.command(["top2021", "top2022", "top2023", "top2024", "top2025"], async (ctx) => {
logger.info("command: /topyearly", "topYearly.ts:topyearly()");
const lang = await telegram.api.message.getLanguage(ctx);

Expand All @@ -39,8 +39,10 @@ const topYearly = async (): Promise<void> => {
});

if (user_questions) {
s[`score_${year}`] +=
(user_questions[`upvotes_${year}`] || 0) - (user_questions[`downvotes_${year}`] || 0) || 0;
s[`score_${year}`] =
s[`score_${year}`] +
user_questions[`upvotes_${year}`] -
user_questions[`downvotes_${year}`];
}
return s;
}),
Expand Down
14 changes: 5 additions & 9 deletions app/functions/utils/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ import translate from "@translations/translate";
import type { MasterInterface } from "@app/types/master.interfaces";
import type { QuestionsInterface } from "@app/types/question.interfaces";

const vote = async (ctx, type): Promise<void> => {
const vote = async (ctx, type, user_id): Promise<void> => {
const lang = await telegram.api.message.getLanguage(ctx);

if (telegram.api.message.getChatID(ctx) < 0) {
// is group chat

const { id: user_id }: MasterInterface = await db.master.get({
group_id: telegram.api.message.getChatID(ctx),
});

const voter_user_id = telegram.api.message.getUserIDFromAction(ctx);
const message_id = telegram.api.message.getMessageIDFromAction(ctx);

Expand Down Expand Up @@ -88,8 +84,8 @@ const vote = async (ctx, type): Promise<void> => {
await db.questions.update({ group_id, user_id }, user_questions);

const buttons = new InlineKeyboard();
buttons.text(`👍 ${user_questions?.voters?.users?.upvotes?.length || 0} `, "upvote");
buttons.text(`👎 ${user_questions?.voters?.users?.downvotes?.length || 0} `, "downvote");
buttons.text(`👍 ${user_questions?.voters?.users?.upvotes?.length || 0} `, `upvote ${user_id}`);
buttons.text(`👎 ${user_questions?.voters?.users?.downvotes?.length || 0} `, `downvote ${user_id}`);

await telegram.api.message.editMessageReplyMarkup(ctx, {
reply_markup: buttons,
Expand All @@ -113,8 +109,8 @@ const vote = async (ctx, type): Promise<void> => {
await db.questions.add(json);

const buttons = new InlineKeyboard();
buttons.text(`👍 ${is_upvote ? 1 : 0} `, "upvote");
buttons.text(`👎 ${is_upvote ? 0 : 1}`, "downvote");
buttons.text(`👍 ${is_upvote ? 1 : 0} `, `upvote ${user_id}`);
buttons.text(`👎 ${is_upvote ? 0 : 1}`, `downvote ${user_id}`);

await telegram.api.message.editMessageReplyMarkup(ctx, {
reply_markup: buttons,
Expand Down
2 changes: 1 addition & 1 deletion app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"hears_missing_tip": "🤬 Hey buddy! You forgot the two HASHTAGS. First of all, the WORD(S) to guess, then two HASHTAGS, finally the HINT. If you want to send also a picture, please insert it the caption. All in a single message. Exemple:\n\n<code>gameboy ## old console '90s</code>\n\ngameboy is the word to guess, then there is the two HASHTAGS and finally the HINT (old console '90s). Don't be ashamed, try again!",
"hears_missing_caption": "🤬 Hey buddy! You forgot the caption. First of all, the WORD(S) to guess, then two HASHTAGS, finally the HINT. If you want to send also a picture, please insert it the caption. All in a single message. Exemple:\n\n<code>gameboy ## old console '90s</code>\n\ngameboy is the word to guess, then there is the two HASHTAGS and finally the HINT (old console '90s). Don't be ashamed, try again!",
"hears_missing_photo_caption": "🤬 Hey buddy! You forgot the caption when you inserted the picture. Write down the WORD(S) to guess as caption, then two HASHTAGS and finally the HINT. All in a single message. Exemple:\n\n<code>gameboy ## old console '90s</code>\n\ngameboy is the word to guess, then there is the two HASHTAGS and finally the HINT (old console '90s). Don't be ashamed, try again!!",
"hears_win": "🏆 <b>GREAT JOB </b> {{first_name}} (@{{username}}) YOU WIN!!!\n\n✍️ The correct answer was: <b>{{answer}}</b>\n👑 Now you are the new <b>master</b>! ⚽️ Your score is <b>{{score}}</b> 🔥\n\nTo take a quiz, write a private message to @{{bot_username}} (click on the nickname) and follow the instruction.",
"hears_win": "🏆 <b>GREAT JOB </b> {{first_name}} (@{{username}}) YOU WIN!!!\n\n❓ The question was: <b>{{tip}}</b>\n✍️ The correct answer was: <b>{{answer}}</b>\n👑 Now you are the new <b>master</b>! ⚽️ Your score is <b>{{score}}</b> 🔥\n\nTo take a quiz, write a private message to @{{bot_username}} (click on the nickname) and follow the instruction.\n\nDid you like the question? Rate it:",
"hears_win_but_not_master": "🏆 YOU WIN {{first_name}}!! But you can't be master because you don't have a Telegram username. Please set a username: go to Telegram settings, click on edit and write your @nickname! {{master_first_name}} (@{{master_username}}) is still the master.",
"master_command_empty": "Insert a nickname, for exemple:\n\n<code>/master @ptkdev</code>",
"master_command_success": "Now you are the master @{{username}}!\n\nTo take a quiz, write a private message to @{{bot_username}} (click on the nickname) and write there the word or the sentence to guess, followed by two HASHTAGS and the hint, for exemple: \n\n<code>gameboy ## old console '90s</code>",
Expand Down
Loading

0 comments on commit d8df0e0

Please sign in to comment.