Skip to content

Commit

Permalink
[Release] v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ptkdev committed Oct 17, 2021
1 parent 47e431f commit e61738d
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 63 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v0.3.0 (TBD)
# v0.3.0 (October 18, 2021)

- Multilanguage support
- Scores board
Expand Down
7 changes: 5 additions & 2 deletions app/functions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import bot from "@app/core/telegraf";
import telegram from "@routes/api/telegram";
import { sendMessageToAllGroups } from "@app/functions/utils/admin";
import translate from "@translations/translate";

import db from "@routes/api/database";
import logger from "@app/functions/utils/logger";

const actions = async (): Promise<void> => {
bot.action(["message_all_groups", "set_user_score"], async (ctx) => {
logger.info(`action: ${telegram.api.message.getActionType(ctx)}`, "actions.ts:actions()");
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

switch (telegram.api.message.getActionType(ctx)) {
case "message_all_groups":
Expand All @@ -28,7 +31,7 @@ const actions = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("admin_set_user_score_info_request"),
translate(lang.language, "admin_set_user_score_info_request"),
);
break;
default:
Expand Down
36 changes: 22 additions & 14 deletions app/functions/commands/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,33 @@ import logger from "@app/functions/utils/logger";
const admin = async (): Promise<void> => {
bot.command("admin", async (ctx) => {
logger.info("command: /admin", "admin.ts:admin()");
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

if (telegram.api.message.getChatID(ctx) > 0) {
// is bot chat
await telegram.api.message.send(ctx, telegram.api.message.getChatID(ctx), translate("admin_welcome"), {
reply_markup: {
inline_keyboard: [
[
{
text: translate("action_send_messagge_all_groups"),
callback_data: "message_all_groups",
},
{
text: translate("action_set_user_score"),
callback_data: "set_user_score",
},
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate(lang.language, "admin_welcome"),
{
reply_markup: {
inline_keyboard: [
[
{
text: translate(lang.language, "action_send_messagge_all_groups"),
callback_data: "message_all_groups",
},
{
text: translate(lang.language, "action_set_user_score"),
callback_data: "set_user_score",
},
],
],
],
},
},
});
);
}
});
};
Expand Down
Empty file removed app/functions/commands/credits.ts
Empty file.
15 changes: 9 additions & 6 deletions app/functions/commands/hears.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { similarity } from "../utils/utils";
const hears = async (): Promise<void> => {
bot.on("text", async (ctx) => {
logger.info("hears: text", "hears.ts:on(text)");
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

if (telegram.api.message.getChatID(ctx) > 0) {
// is chat with bot
Expand All @@ -46,13 +49,13 @@ const hears = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("hears_missing_question"),
translate(lang.language, "hears_missing_question"),
);
} else if (json.description === undefined || json.description === "") {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("hears_missing_tip"),
translate(lang.language, "hears_missing_tip"),
);
} else {
await db.master.update({}, json);
Expand All @@ -66,7 +69,7 @@ const hears = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("haers_not_you_master"),
translate(lang.language, "haers_not_you_master"),
);
}
}
Expand Down Expand Up @@ -94,7 +97,7 @@ const hears = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
master?.group_id,
translate("hears_win", {
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),
Expand Down Expand Up @@ -132,7 +135,7 @@ const hears = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
master?.group_id || 0,
translate("hears_win_but_not_master", {
translate(lang.language, "hears_win_but_not_master", {
first_name: telegram.api.message.getUserFirstName(ctx),
master_first_name: master.first_name,
master_username: master.username,
Expand All @@ -151,7 +154,7 @@ const hears = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
master.group_id,
translate("hot_answer", {
translate(lang.language, "hot_answer", {
first_name: telegram.api.message.getUserFirstName(ctx),
username: telegram.api.message.getUsername(ctx),
}),
Expand Down
12 changes: 8 additions & 4 deletions app/functions/commands/hearsphoto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import logger from "@app/functions/utils/logger";
const hearsPhoto = async (): Promise<void> => {
bot.on("photo", async (ctx) => {
logger.info("hears: photo", "hears.ts:on(photo)");
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

if (telegram.api.message.getChatID(ctx) > 0) {
// is chat with bot
const master: TelegramUserInterface = await db.master.get({
Expand All @@ -45,13 +49,13 @@ const hearsPhoto = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("hears_missing_question"),
translate(lang.language, "hears_missing_question"),
);
} else if (json.description === undefined || json.description === "") {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("hears_missing_tip"),
translate(lang.language, "hears_missing_tip"),
);
} else {
await db.master.update({}, json);
Expand All @@ -67,14 +71,14 @@ const hearsPhoto = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("hears_missing_photo_caption"),
translate(lang.language, "hears_missing_photo_caption"),
);
}
} else {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("hears_not_you_master"),
translate(lang.language, "hears_not_you_master"),
);
}
}
Expand Down
13 changes: 10 additions & 3 deletions app/functions/commands/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import logger from "@app/functions/utils/logger";
const master = async (): Promise<void> => {
bot.command("master", async (ctx) => {
logger.info("command: /master", "master.ts:master()");
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

if (telegram.api.message.getChatID(ctx) < 0) {
// is group chat
Expand All @@ -37,7 +40,7 @@ const master = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("master_command_empty"),
translate(lang.language, "master_command_empty"),
);
} else {
const username = telegram.api.message.getText(ctx).replace("/master ", "").replace("@", "").trim();
Expand Down Expand Up @@ -66,14 +69,18 @@ const master = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("master_command_success", {
translate(lang.language, "master_command_success", {
username: username,
bot_username: telegram.api.bot.getUsername(ctx),
}),
);
}
} else {
await telegram.api.message.send(ctx, telegram.api.message.getChatID(ctx), translate("command_only_group"));
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate(lang.language, "command_only_group"),
);
}
});
};
Expand Down
13 changes: 10 additions & 3 deletions app/functions/commands/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import logger from "@app/functions/utils/logger";
const score = async (): Promise<void> => {
bot.command("score", async (ctx) => {
logger.info("command: /score", "score.ts:score()");
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

if (telegram.api.message.getChatID(ctx) < 0) {
// is group chat
Expand All @@ -49,7 +52,7 @@ const score = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("score_command_show", {
translate(lang.language, "score_command_show", {
first_name: telegram.api.message.getUserFirstName(ctx) || "",
username: telegram.api.message.getUsername(ctx) || "",
score: score?.score || 0,
Expand Down Expand Up @@ -79,14 +82,18 @@ const score = async (): Promise<void> => {
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("score_command_show_with_username", {
translate(lang.language, "score_command_show_with_username", {
username: username,
score: score?.score || 0,
}),
);
}
} else {
await telegram.api.message.send(ctx, telegram.api.message.getChatID(ctx), translate("command_only_group"));
await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate(lang.language, "command_only_group"),
);
}
});
};
Expand Down
75 changes: 58 additions & 17 deletions app/functions/commands/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,71 @@ import logger from "@app/functions/utils/logger";
const settings = async (): Promise<void> => {
bot.command("settings", async (ctx) => {
logger.info("command: /settings", "settings.ts:settings()");
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

await ctx.reply(
translate("settings_command_options"),
translate(lang.language, "settings_command_options"),
Markup.inlineKeyboard([
[Markup.button.callback(translate("settings_command_setlanguage"), "settings_languages")],
[
Markup.button.callback(
translate(lang.language, "settings_command_setlanguage"),
"settings_languages",
),
],
[
Markup.button.url(
translate("settings_command_opensource"),
translate(lang.language, "settings_command_opensource"),
"https://github.com/ptkdev/quizquickanswer-telegram-game-bot",
),
],
[Markup.button.callback(translate("settings_command_credits"), "settings_credits")],
[Markup.button.url(translate("settings_command_email"), "https://t.me/QuizQuickAnswerGroup")],
[Markup.button.callback(translate(lang.language, "settings_command_credits"), "settings_credits")],
[
Markup.button.url(
translate(lang.language, "settings_command_email"),
"https://t.me/QuizQuickAnswerGroup",
),
],
]),
);
});

bot.action("settings_languages", async (ctx) => {
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

await ctx.reply(
translate("settings_command_switchlanguage"),
translate(lang.language, "settings_command_switchlanguage"),
Markup.inlineKeyboard([
Markup.button.callback(translate("settings_command_language_english"), "settings_set_english"),
Markup.button.callback(translate("settings_command_language_italian"), "settings_set_italian"),
Markup.button.callback(
translate(lang.language, "settings_command_language_english"),
"settings_set_english",
),
Markup.button.callback(
translate(lang.language, "settings_command_language_italian"),
"settings_set_italian",
),
]),
);
});

bot.action("settings_credits", async (ctx) => {
const lang = await db.settings.get({
group_id: telegram.api.message.getChatID(ctx),
});

await ctx.reply(
translate("settings_command_credits"),
translate(lang.language, "settings_command_credits"),
Markup.inlineKeyboard([
[Markup.button.url(translate("settings_command_ptkdev"), "https://ptk.dev")],
[Markup.button.url(translate("settings_command_ali"), "https://github.com/alishadman95/")],
[Markup.button.url(translate(lang.language, "settings_command_ptkdev"), "https://ptk.dev")],
[
Markup.button.url(
translate(lang.language, "settings_command_ali"),
"https://github.com/alishadman95/",
),
],
]),
);
});
Expand All @@ -68,16 +101,20 @@ const settings = async (): Promise<void> => {
if (lang.group_id !== 0) {
await db.settings.update(
{ group_id: telegram.api.message.getChatID(ctx) },
{ group_id: telegram.api.message.getChatID(ctx), language: "en" },
{ group_id: telegram.api.message.getChatID(ctx), language: "en", pin_message: lang.pin_message },
);
} else {
await db.settings.add({ group_id: telegram.api.message.getChatID(ctx), language: "en" });
await db.settings.add({
group_id: telegram.api.message.getChatID(ctx),
language: "en",
pin_message: lang.pin_message,
});
}

await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("settings_command_current_english"),
translate(lang.language, "settings_command_current_english"),
);
});

Expand All @@ -89,16 +126,20 @@ const settings = async (): Promise<void> => {
if (lang.group_id !== 0) {
await db.settings.update(
{ group_id: telegram.api.message.getChatID(ctx) },
{ group_id: telegram.api.message.getChatID(ctx), language: "it" },
{ group_id: telegram.api.message.getChatID(ctx), language: "it", pin_message: lang.pin_message },
);
} else {
await db.settings.add({ group_id: telegram.api.message.getChatID(ctx), language: "it" });
await db.settings.add({
group_id: telegram.api.message.getChatID(ctx),
language: "it",
pin_message: lang.pin_message,
});
}

await telegram.api.message.send(
ctx,
telegram.api.message.getChatID(ctx),
translate("settings_command_current_italian"),
translate(lang.language, "settings_command_current_italian"),
);
});
};
Expand Down
Loading

0 comments on commit e61738d

Please sign in to comment.