-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotten.js
65 lines (64 loc) · 2.52 KB
/
rotten.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
const rm = require('rotten-movies');
const Discord = require('discord.js');
module.exports = (message, content) => {
if ((content.startsWith('🍅 ') || content.startsWith('!rt ')) && content.length > 3) {
var com = content.startsWith('🍅 ') ? 3 : 4;
if (!content.includes('coming soon') && !content.includes('box office') && !content.includes('opening')) {
var movieurl = 'https://www.rottentomatoes.com/m/' + encodeURI(content.substring(com).toLowerCase().replace(/ /gm, '_').replace(/[^a-z0-9_]/gm, ''));
rm.info(movieurl, function (err, info) {
rm.scores(movieurl, function (err2, scores) {
message.channel.send({
embed: {
title: info.name,
description: info.description,
url: movieurl,
footer: {
text: 'From RottenTomatoes'
},
color: 0xa81717,
fields: [{
name: "🍅 Critic Score",
value: scores.critic + '%',
inline: true
}, {
name: "🍿 Audience Score",
value: scores.audience + '%',
inline: true
}
]
}
});
});
});
} else {
var rtscraper = require('rt-scraper');
rtscraper.getRottenTomatoesScraperData(function (error, data) {
if (!error) {
if (content.includes('coming soon')) {
const RTembed = new Discord.RichEmbed().setTitle(':film_frames: Coming Soon').setColor(0xa81717).setFooter("From RottenTomatoes");
for (var i = 0; i < data.comingSoon.length; i++) {
RTembed.addField(data.comingSoon[i].title, data.comingSoon[i].date + '; ' + data.comingSoon[i].meter);
}
message.channel.send({ embed: RTembed });
}
if (content.includes('opening')) {
const RTembed = new Discord.RichEmbed().setTitle(':film_frames: Opening This Week').setColor(0xa81717).setFooter("From RottenTomatoes");
for (var i = 0; i < data.openingThisWeek.length; i++) {
RTembed.addField(data.openingThisWeek[i].title, data.openingThisWeek[i].date + '; ' + data.openingThisWeek[i].meter);
}
message.channel.send({ embed: RTembed });
}
if (content.includes('box office')) {
const RTembed = new Discord.RichEmbed().setTitle(':film_frames: Box Office').setColor(0xa81717).setFooter("From RottenTomatoes");
for (var i = 0; i < data.boxOffice.length; i++) {
RTembed.addField(data.boxOffice[i].title, data.boxOffice[i].gross + '; ' + data.boxOffice[i].meter);
}
message.channel.send({ embed: RTembed });
}
} else {
message.channel.send('Some error occured.');
}
});
}
}
}