Skip to content

Commit

Permalink
Merge pull request #32 from gabeklavans/feature/update-start
Browse files Browse the repository at this point in the history
Update start command to display explanatory welcome message
  • Loading branch information
gabeklavans authored Jun 24, 2024
2 parents ba1d538 + f021d25 commit 1a92945
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 19 deletions.
46 changes: 32 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@fastify/cors": "^8.4.0",
"@fastify/swagger": "^8.12.0",
"@fastify/swagger-ui": "^1.10.1",
"@grammyjs/parse-mode": "^1.10.0",
"correct-frequency-random-letters": "^1.0.1",
"date-fns": "^3.6.0",
"dictionary-en": "^3.2.0",
Expand Down
14 changes: 10 additions & 4 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { Bot, GrammyError, InlineKeyboard } from "grammy";
import { GAME_LIST, GAME_START_BUTTON_TEXT } from "./constants";
import { Bot, Context, GrammyError, InlineKeyboard } from "grammy";
import { GAME_LIST, GAME_START_BUTTON_TEXT, WELCOME_MESSAGE } from "./constants";
import { getSessionId, throwIfSessionExpired } from "./server/utils";
import { SessionExpiredError } from "./server/errors";
import { ParseModeFlavor, hydrateReply } from "@grammyjs/parse-mode";

if (!process.env.BOT_API_KEY) {
console.error("environment misconfigured");
}

if (process.env.BOT_API_KEY == null) throw Error("Telegram bot API token is missing.");
export const bot = new Bot(process.env.BOT_API_KEY!);
export const bot = new Bot<ParseModeFlavor<Context>>(process.env.BOT_API_KEY!);

bot.use(hydrateReply);

const startingInlineKeyboard = new InlineKeyboard().game(GAME_START_BUTTON_TEXT);

bot.command("start", (ctx) => ctx.reply("Welcome! Up and running."));
bot.command(
"start",
async (ctx) => await ctx.replyFmt(WELCOME_MESSAGE, { link_preview_options: { is_disabled: true } }),
);

bot.command("game", async (ctx) => {
await ctx.replyWithGame(process.env.WORD_HUNT_SHORTNAME as string, {
Expand Down
15 changes: 14 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { code, fmt, link } from "@grammyjs/parse-mode";

export enum Game {
WORD_HUNT,
}
Expand All @@ -21,7 +23,18 @@ export const TURN_MAX: { [key in Game]: number } = {
[Game.WORD_HUNT]: Number.MAX_VALUE,
};

export const GAME_START_BUTTON_TEXT = "Play now!"
export const GAME_START_BUTTON_TEXT = "Play now!";

export const MAX_SESSIONS = 10000;
export const NUM_DAYS_SESSION_EXPIRED = 3;

export const WELCOME_MESSAGE = fmt`Welcome!
This bot is best used in ${link(
"Inline Mode",
"https://telegram.org/blog/inline-bots",
)}. Just go to your chat then type the name of the bot with a space at the end: ${code(
"@gamejaybot ",
)} and a list of games should show up! You can search through the games by continuing to type your search query. Then, tap on the one you want to start and it will send a new game to the chat you're in.
Currently, Word Hunt Online is the only game available for GameJay, but more are planned to be added!`;

0 comments on commit 1a92945

Please sign in to comment.