-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (73 loc) · 3.29 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
/* eslint-disable no-inline-comments */
const Discord = require('discord.js');
const client = new Discord.Client();
const HytaleApi = require('hytale-api-sdk');
const api = new HytaleApi.ArticlesApi();
const config = require("./config");
const prefix = config.prefix
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (!msg.content.startsWith(prefix)) return;
const args = msg.content.trim().split(/ +/g);
const cmd = args[0].slice(prefix.length).toLowerCase(); // case INsensitive, without prefix
if(cmd === 'ping') {
msg.reply('pong');
console.log('!ping');
}
if(cmd === 'madeby') {
console.log('!madeby');
msg.channel.send('this was made by RM20');
}
if(cmd === 'blog') {
var input1 = `${args[1]}`
console.log(input1)
var x=0
if (!args[1]) {
api.getArticles({}, function(error, data, response) {
const latest = data.slice(0, 1);
console.log("getting api",1)
latest.forEach(function(article) {
const publishAt = new Date(article.publishedAt);
const embed = new Discord.MessageEmbed()
.setColor(3447003)
.setThumbnail(`https://hytale.com/m/variants/blog_thumb_${article.coverImage.s3Key}`)
.setAuthor('Hytale', 'https://cdn.discordapp.com/attachments/741665332808122469/741685930401857596/G-O9yHTX.jpg')
.setTitle(article.title)
.setDescription(article.bodyExcerpt)
.setURL(`https://hytale.com/news/${publishAt.getFullYear()}/${publishAt.getMonth() + 1}/${article.slug}`)
.addField('Published At', `${publishAt.toLocaleDateString()}`)
;
console.log("passed getting api")
msg.channel.send(embed);
})
})
}
if(Number(input1) > config.max){
msg.channel.send("too high number")
}
else {
msg.channel.send(`getting ${args[1]} blog post`);
api.getArticles({}, function(error, data, response) {
const latest = data.slice(0, `${args[1]}`);
console.log("getting api",`${args[1]} `)
latest.forEach(function(article) {
const publishAt = new Date(article.publishedAt);
const embed = new Discord.MessageEmbed()
.setColor(3447003)
.setThumbnail(`https://hytale.com/m/variants/blog_thumb_${article.coverImage.s3Key}`)
.setAuthor('Hytale', 'https://cdn.discordapp.com/attachments/741665332808122469/741685930401857596/G-O9yHTX.jpg')
.setTitle(article.title)
.setDescription(article.bodyExcerpt)
.setURL(`https://hytale.com/news/${publishAt.getFullYear()}/${publishAt.getMonth() + 1}/${article.slug}`)
.addField('Published At', `${publishAt.toLocaleDateString()}`)
;
console.log("passed getting api")
msg.channel.send(embed);
})
})
}
}
});
client.login(config.BotToken);