-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.ts
More file actions
123 lines (97 loc) · 3.16 KB
/
bot.ts
File metadata and controls
123 lines (97 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { Bot, Context } from "grammy";
import dotenv from "dotenv";
import { dailyQuote, loadInitialQuote } from "./getQuoteFunc";
import http from "http";
dotenv.config();
const bot = new Bot(process.env.BOT_TOKEN as string);
bot.command("start", async (ctx) => {
const userName = ctx.from?.first_name || "friend";
const welcomeMessage = `
<b>Hello, ${userName}!</b> 👋
I'm <b>Random Quote</b> 🤖
Your personal quote assistant, here to sprinkle a little inspiration, wisdom, or fun into your day.
<b>What can I do for you?</b>
🔹 Send you one carefully selected quote every day
🔹 Let you choose the delivery time that works best for you
🔹 Allow you to pick the quote type — movies, anime, music, books, or all mixed together
🔹 Occasionally try to be funny... no guarantees 😅
<b>Ready to get inspired?</b>
Hit /quote to give your first daily quote.
Wanna know all about bot and author? Check /about.
`.trim();
await ctx.reply(welcomeMessage, { parse_mode: "HTML" });
});
bot.command("about", async (ctx: Context) => {
const aboutMessage = `
<b>About this bot 🤖</b>
I'm <b>Random Quote</b>, your daily companion for inspirational, motivational, funny, or simply beautiful quotes from:
🎬 Movies
📚 Books
🎵 Songs
📺 Anime
...and more.
<b>Available Commands:</b>
/start — Welcome message
/quote — Get daily quotes
/about — You're here! 😄
—
<b>Created with 💻 & ❤️ by</b>
<a href="https://t.me/kenmaqqe">Dmytro Tymoshenko</a> — developer, content creator, and fan of cool side projects.
🌐 Socials:
🔗 <a href="https://t.me/kenmaqqe">Telegram</a>
🐙 <a href="https://github.com/kenmaqqe">GitHub</a>
📸 <a href="https://www.linkedin.com/in/kenmaqqe/">Linkedin</a>
☕ Wanna support Me?
Donate via <a href="coff.ee/kenmaqqe">Buy Me A Coffee</a> 🙏
Even small tips mean a lot 💜
Stay awesome!
`.trim();
if (!ctx.chat) return;
await ctx.api.sendMessage(ctx.chat.id, aboutMessage, {
parse_mode: "HTML",
// @ts-expect-error: Known Telegram API param, but maybe missing in types
disable_web_page_preview: true,
});
});
bot.command("quote", async (ctx) => {
try {
if (!dailyQuote) {
await ctx.reply(
"Sorry, the quote is not ready yet. Please try again in a moment.",
);
return;
}
await ctx.reply(`<b>${dailyQuote.q}</b>\n<i>© ${dailyQuote.a}</i>`, {
parse_mode: "HTML",
});
} catch (error) {
console.error(error);
await ctx.reply("Oops! Something went wrong.");
}
});
bot.on("message", async (ctx) => {
await ctx.reply("I don`t understand you. Please use commands.");
});
async function main() {
await loadInitialQuote();
await bot.api.setMyCommands([
{ command: "start", description: "Start the bot" },
{ command: "about", description: "About bot" },
{ command: "quote", description: "Get random quote" },
]);
await bot.start();
}
main().catch(console.error);
http
.createServer((req, res) => {
if (req.url === "/ping") {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("pong");
} else {
res.writeHead(404);
res.end();
}
})
.listen(process.env.PORT || 8080, () => {
console.log("Ping server is running");
});