Skip to content

Commit

Permalink
chore(schema): update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
fisenkodv committed Jan 1, 2025
1 parent 97ab2f3 commit 065a8cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/db/schema.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
DROP TABLE IF EXISTS jokes;
CREATE TABLE jokes
(
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
joke TEXT NOT NULL UNIQUE,
answer TEXT NULL UNIQUE,
added_at TIMESTAMP
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
setup TEXT NOT NULL UNIQUE,
punchline TEXT NULL UNIQUE,
added_at TIMESTAMP
);
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ bot.on(message('text'), async ctx => {
const joke = await jokesService.getJoke();

if (joke) {
const keyboard = joke.answer ? Markup.inlineKeyboard([Markup.button.callback('Get the answer!', `${joke.id}`)]) : undefined;
ctx.replyWithHTML(joke.joke, keyboard);
const keyboard = joke.punchline ? Markup.inlineKeyboard([Markup.button.callback('Show a punchline!', `${joke.id}`)]) : undefined;
ctx.replyWithHTML(joke.setup, keyboard);
}
} catch (error) {
logger.error("An error '%s' occurred providing a joke", error);
Expand All @@ -46,17 +46,17 @@ bot.on(callbackQuery('data'), async ctx => {
try {
const msg = ctx.callbackQuery.data;
const { first_name, last_name } = ctx.callbackQuery.from;
logger.info('The user (%s,%s) requested an answer to joke with ID %d', first_name, last_name, msg);
logger.info('The user (%s,%s) requested a punchline to joke with ID %d', first_name, last_name, msg);

const jokeId = Number.parseInt(ctx.callbackQuery.data);
const joke = await jokesService.getJokeById(jokeId);

if (joke) {
const formattedJoke = `${joke.joke}\n\u2014<i>${joke.answer}</i>`;
const formattedJoke = `${joke.setup}\n\u2014<i>${joke.punchline}</i>`;
ctx.editMessageText(formattedJoke, { parse_mode: 'HTML' });
}
} catch (error) {
logger.error("An error '%s' occurred providing an answer", error);
logger.error("An error '%s' occurred providing a punchline", error);
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/types/joke.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface Joke {
id: number;
joke: string;
answer?: string;
setup: string;
punchline?: string;
}

0 comments on commit 065a8cc

Please sign in to comment.