Skip to content

Commit c56e685

Browse files
committed
fix
1 parent 9088ed8 commit c56e685

File tree

4 files changed

+94
-6
lines changed

4 files changed

+94
-6
lines changed

src/Embeds/GoodnightEmbed.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const Discord = require("discord.js");
2+
3+
class GoodnightEmbed {
4+
5+
send(model) {
6+
const examples = `
7+
\`\`\`
8+
r/help
9+
r/leaderboard
10+
r/rank @mention
11+
\`\`\`
12+
`
13+
const embed = new Discord.MessageEmbed()
14+
.setColor('#DAA520')
15+
.setTitle("❓ Help ")
16+
.addFields(
17+
{ name: 'help', value: 'Show this message.', inline: true },
18+
{ name: 'leaderboard', value: 'Show the top message writers on the server during the current period.', inline: true },
19+
{ name: 'leastactive', value: 'Show who has been active in the server, starting from the least active.', inline: true },
20+
{ name: 'rank', value: 'Show the rank of the mentioned user.', inline: true },
21+
{ name: 'usage examples:', value: examples}
22+
)
23+
.setThumbnail('https://i.imgur.com/v5RR3ro.png')
24+
.setFooter({ text: 'Author: \\ (Barretta)', iconURL: 'https://i.imgur.com/lyv8H8C.png' });
25+
26+
const embedContainer = {
27+
embeds: [embed],
28+
}
29+
30+
model.channel.send(embedContainer).catch(
31+
error => console.error(error)
32+
);
33+
}
34+
35+
}
36+
37+
module.exports = new GoodnightEmbed();

src/Instance.js

+52-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
1+
const CronJob = require('cron').CronJob;
2+
const GoodnightEmbed = require('./Embeds/GoodnightEmbed');
3+
14
class Instance {
25

6+
constructor(guild) {
7+
this.guild = guild;
8+
this.config = {
9+
channels: [
10+
"chat",
11+
"nose-boop"
12+
]
13+
}
14+
}
15+
316
init() {
17+
this._setup();
418
this._setEvents();
519
}
620

21+
_setGoodnightMessage() {
22+
new CronJob(
23+
'5 * * * * *',
24+
() => this._sendGoodnightEmbed(),
25+
null,
26+
true,
27+
'Europe/Rome'
28+
);
29+
}
30+
31+
_sendGoodnightEmbed() {
32+
const model = {
33+
channel: this.channel
34+
}
35+
36+
GoodnightEmbed.send(model);
37+
}
38+
39+
_isAllowedChannel(channelname) {
40+
const isAllowedChannel = this.config.channels.find(
41+
channel => channel.includes(channelname)
42+
) != undefined;
43+
44+
return isAllowedChannel;
45+
}
46+
47+
_setup() {
48+
this.channel = this.guild.channels.cache.find(
49+
channel => {
50+
const isAllowedChannel = this._isAllowedChannel(channel.name);
51+
const isCorrectChannel = isAllowedChannel && channel.type === "GUILD_TEXT"
52+
53+
return isCorrectChannel;
54+
}
55+
);
56+
}
57+
758
_setEvents() {
8-
59+
this._setGoodnightMessage();
960
}
1061

1162
onMessageCreate(msg) {

src/InstanceManager.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class InstanceManager {
1818
const guildId = msg.guild.id;
1919
const instance = this.sessions.get(guildId);
2020

21-
msg.content = this.wordFilter.filter(msg.content);
22-
2321
if (instance) {
2422
instance.onMessageCreate(msg)
2523
}
@@ -28,15 +26,15 @@ class InstanceManager {
2826
_initSessions() {
2927
if (!this.sessions.size) {
3028
for (const [guildId, guild] of this.client.guilds.cache.entries()) {
31-
const instance = new Instance(guild, DAL);
29+
const instance = new Instance(guild);
3230
instance.init();
3331
this.sessions.set(guildId, instance);
3432
}
3533
}
3634
}
3735

3836
_initSession(guild) {
39-
const instance = new Instance(guild, DAL);
37+
const instance = new Instance(guild);
4038
instance.init();
4139
this.sessions.set(guild.id, instance);
4240
}
@@ -64,7 +62,6 @@ class InstanceManager {
6462
this.client.login(config.TOKEN_PROD);
6563
}
6664

67-
this._setup();
6865
this._setEvents();
6966
}
7067

wednesday.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const InstanceManager = require("./src/InstanceManager");
2+
3+
new InstanceManager().init();

0 commit comments

Comments
 (0)