-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.ts
49 lines (38 loc) · 1.19 KB
/
bot.ts
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
import { Bot } from "https://deno.land/x/grammy@v1.33.0/mod.ts";
import "jsr:@std/dotenv/load";
import {
FULL_HELP_MESSAGE,
INVALID_COMMAND_MESSAGE,
MENU,
SHORT_HELP_MESSAGE,
SUPPORT_MESSAGE,
} from "./constants.ts";
import { handleFaucetRequest, validateNetwork } from "./utils.ts";
const bot = new Bot(Deno.env.get("BOT_KEY") || "");
bot.command("start", (ctx) => ctx.reply(FULL_HELP_MESSAGE));
bot.command("help", (ctx) =>
ctx.reply(`${SHORT_HELP_MESSAGE}\n\n${SUPPORT_MESSAGE}`)
);
bot.command("devnet", (ctx) => {
return handleFaucetRequest(ctx, "devnet");
});
bot.command("testnet", (ctx) => {
return handleFaucetRequest(ctx, "testnet");
});
bot.on("message", (ctx) => {
if (ctx.message?.text == null) {
return ctx.reply(INVALID_COMMAND_MESSAGE);
}
const command = ctx.message?.text.trim();
const parts = command.split(" ");
if (parts.length !== 2) {
return ctx.reply(INVALID_COMMAND_MESSAGE);
}
const network = parts[0].trim().toLowerCase();
if (!validateNetwork(network)) {
return ctx.reply(INVALID_COMMAND_MESSAGE);
}
return ctx.reply(`This format is deprecated. ${SHORT_HELP_MESSAGE}`);
});
await bot.api.setMyCommands(MENU);
export default bot;