-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
105 lines (89 loc) · 3.08 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
require("dotenv").config();
const { Client, GatewayIntentBits } = require("discord.js");
const fs = require("fs");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const token = process.env.SECRET_KEY;
let data = [];
// edit-api
fetch("https://www.ryankert.cc/rss-friend/sorted.json")
.then((res) => res.json())
.then((json) => {
data = json;
});
// When the client is ready, run this code (only once)
// main edit
client.once("ready", (c) => {
console.log(`Ready! Logged in as ${c.user.tag}`);
// logged out if no News aka. we have no new post yesterday.
const yesterday = new Date();
const firstDate = new Date(data[0].date);
if (
firstDate.getDate() != yesterday.getDate() ||
firstDate.getMonth() != yesterday.getMonth() ||
firstDate.getFullYear() != yesterday.getFullYear()
) {
console.log("No Avilable News");
process.exit();
}
// edit-channel-id
let channel = client.channels.cache.get("1015956897922297897");
let returnData = String();
returnData += "> **NewsLetter :**\n";
for (let i = 0; i < 3 && i < data.length; i++) {
const tempDate = new Date(data[i].date);
if (!samedate(tempDate, yesterday)) continue;
if (i != 0) returnData += "> \n";
returnData += "> ";
if (tempDate.getMonth() < 9) returnData += "0";
returnData += String(tempDate.getMonth() + 1) + "/";
if (tempDate.getDate() < 10) returnData += "0";
returnData += String(tempDate.getDate()) + " ";
returnData += String(data[i].title) + "\n";
returnData += "> link: " + String(data[i].link) + "\n";
}
channel.send(returnData).then(() => {
client.destroy();
});
});
function samedate(a, b) {
if (
a.getDate() != b.getDate() ||
a.getMonth() != b.getMonth() ||
a.getFullYear() != b.getFullYear()
) {
return false;
}
return true;
}
client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const { commandName } = interaction;
if (commandName === "ping") {
await interaction.reply("Pong!");
} else if (commandName === "server") {
await interaction.reply(
`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`
);
} else if (commandName === "user") {
await interaction.reply(
`Your tag: ${interaction.user.tag}\nYour id: ${interaction.user.id}`
);
} else if (commandName === "newsletter") {
let returnData = String();
returnData += "> **NewsLetter :**\n";
for (let i = 0; i < 3 && i < data.length; i++) {
const tempDate = new Date(data[i].date);
returnData += "> ";
if (tempDate.getMonth() < 9) returnData += "0";
returnData += String(tempDate.getMonth() + 1) + "/";
if (tempDate.getDate() < 10) returnData += "0";
returnData += String(tempDate.getDate()) + " ";
returnData += String(data[i].title) + "\n";
returnData += "> link: " + String(data[i].link) + "\n";
if (i + 1 < 3 && i + 1 < data.length) returnData += "> \n";
}
await interaction.reply(returnData);
}
});
// console.log(process.env.SECRET_KEY)
client.login(token);