-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (67 loc) · 2.73 KB
/
index.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
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
const { default: axios } = require("axios");
const Parser = require("rss-parser");
let parser = new Parser();
const { Telegraf } = require("telegraf");
const { message } = require("telegraf/filters");
const bot = new Telegraf("6092909492:AAHBFwlrfjTDsG8dezYnWZM8P3psnZlli48");
const RSS_URL = `https://www.space.com/feeds/all`;
bot.start(async (ctx) => {
ctx.reply(
"⭐Welcome " +
ctx.from.first_name +
"\n\n🪐 Hi there! I can help you with that. Here is a brief description for a Telegram bot that shows you astronomy photos and news every day:\n\nThis bot offers a daily dose of astronomy by sending you a breathtaking photo of space along with some interesting news about the field. Each day, you will receive a new photo and news article to keep you informed and inspired. The bot is perfect for anyone interested in astronomy, space exploration and the wonders of the universe. Never miss out on the latest developments in astronomy again - let this bot keep you up to date and inspired every day!\n\n " +
"commands : \n\n/pic: get the Astronomy Picture of the Day\n\n /news: get the most important news of the day "
);
})
bot.on(message("sticker"), (ctx) => ctx.reply("🪐"));
bot.hears(
[
"pic",
"Pic",
"pics",
"Pics",
"PIC",
"PICS",
"PHOTO",
"Photo",
"photo",
"foto",
"fotos",
"Foto",
"Fotos",
"FOTO",
"FOTOS",
],
async (ctx) => ctx.reply(await getIMG())
);
bot.command("pic", async (ctx) => ctx.reply(await getIMG()));
bot.command("news", async (ctx) => {
await getNews(ctx);
});
bot.hears(["news", "new", "News", "New", "NEW", "NEWS"], async (ctx) => {
await getNews(ctx);
});
bot.telegram.setMyCommands([
{ command: "start", description: "open the menu" },
{ command: "pic", description: "get the Astronomy Picture of the Day" },
{ command: "news", description: "get the most important news of the day" },
]);
bot.launch();
// Enable graceful stop
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));
const getNews = async (ctx) => {
ctx.reply("News of the day:");
const feed = await parser.parseURL(RSS_URL);
return feed.items.forEach((item) => {
ctx.reply(
"⭐" + item.title + ":\n\n🪐" + item.contentSnippet + "\n\n" + item.link
);
});
};
const getIMG = async () => {
const res = await axios(
"https://api.nasa.gov/planetary/apod?api_key=9RUHxYDMfs6EfNMRClemRebIdyG5D9Ylni6eHs2d"
);
return await `🌑🌒🌓🌔🌕🌖🌗🌘🌑 \n\ndate: ${res.data.date} ⏰\n\nname: ${res.data.title} 😁\n\nurl: 📎 ${res.data.url} 📎 \n\n🧠 ${res.data.explanation}🧠\n\n🪐⭐`;
};