forked from ArjuLaka/Arju-Japanese-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (64 loc) · 1.83 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
const { scrapeKanji } = require('./events/scraper');
const { fetchDetail } = require('./events/fetcher');
const { Client, GatewayIntentBits } = require('discord.js');
const schedule = require('node-schedule');
require('dotenv').config();
const token = process.env.TOKEN;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.once('ready', () => {
const channelId = process.env.CHANNEL_ID;
//Setiap jam 9 Pagi
schedule.scheduleJob('0 9 * * *', () => {
let sendKanji = getKanji(0);
sendKanji.then(kanjiMessage => {
const channel = client.channels.cache.get(channelId);
if (channel) {
channel.send(kanjiMessage).then(() => {
console.log("pesan berhasil dikirim")
}).catch(console.error)
} else {
console.error("channel not found")
}
})
})
//Setiap jam 3 Sore
schedule.scheduleJob('0 15 * * *', () => {
let sendKanji = getKanji(1);
sendKanji.then(kanjiMessage => {
const channel = client.channels.cache.get(channelId);
if (channel) {
channel.send(kanjiMessage).then(() => {
console.log("pesan berhasil dikirim")
}).catch(console.error)
} else {
console.error("channel not found")
}
})
})
})
async function getKanji(kanjiClass) {
try {
let kanji = await scrapeKanji(kanjiClass);
let detailData = await fetchDetail(kanji);
let finalData = `
# ${detailData.kanji}
## JLPT N${detailData.jlpt}
### Meanings:
${detailData.meanings}
### Kunyomi Reading:
${detailData.kun_readings}
### Onyomi Reading:
${detailData.on_readings}
`;
return finalData;
} catch(err) {
console.log(err)
}
}
client.login(token);