-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
56 lines (47 loc) · 1.43 KB
/
bot.js
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
require("dotenv").config();
const { Bot } = require("grammy");
const whois = require("whois");
// Bot
const bot = new Bot(process.env.BOT_TOKEN);
// Commands
bot.command("start", async (ctx) => {
await ctx
.reply("*Welcome!* ✨ Send a website to get WHOIS details.", {
parse_mode: "Markdown",
})
.then(console.log("New user added:", ctx.from))
.catch((error) => console.error(error));
});
bot.command("help", async (ctx) => {
await ctx
.reply(
"*@anzubo Project.*\n\nThis bot uses the whois lib to get WHOIS domain information data.\n_Note that names or details of registrant may be privacy protected and hence not available._",
{ parse_mode: "Markdown" }
)
.then(console.log("Help command sent to", ctx.from.id))
.catch((e) => console.error(e));
});
// Messages
bot.on("msg", async (ctx) => {
console.log("Query:", ctx.msg.text, "from", ctx.from.id);
try {
await whois.lookup(ctx.msg.text, async function (err, data) {
if (err) {
await ctx.reply("*Error fetching details. Send a valid website URL.*", {
parse_mode: "Markdown",
reply_to_message_id: ctx.msg.message_id,
});
console.log(err);
return;
}
await ctx.reply("*Domain Information*" + "\n\n" + data, {
parse_mode: "Markdown",
});
});
} catch (error) {
console.error(error);
await ctx.reply("An error occured");
}
});
// Run
bot.start();