-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
131 lines (115 loc) · 3.36 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const fs = require('fs');
const Discord = require('discord.js');
const request = require('request');
const { prefix } = require('./config.json');
const { DISCORD_APP_TOKEN, AUTHOR, CLOUD_HUB } = process.env;
const { Utils } = require('./app/utils');
// importing express framework
const express = require('express');
const app = express();
let user = undefined;
const client = new Discord.Client();
const commandFiles = fs
.readdirSync('./commands')
.filter((file) => file.endsWith('.js'));
client.commands = new Discord.Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
const guven = client.users.cache.find(
(element) => element.username === 'boss',
);
console.log({ guven });
user = guven;
console.log('Ready!');
});
client.login(DISCORD_APP_TOKEN);
client.on('guildMemberAdd', (member) => {
member.roles.add(member.guild.roles.cache.find((i) => i.name === 'Shopar'));
const welcomeEmbed = new Discord.MessageEmbed();
welcomeEmbed.setColor('#5cf000');
welcomeEmbed.setTitle(
'**' +
member.user.username +
'** is Shopar other **' +
member.guild.memberCount +
'** people',
);
welcomeEmbed.setImage(
'https://cdn.mos.cms.futurecdn.net/93GAa4wm3z4HbenzLbxWeQ-650-80.jpg.webp',
);
member.guild.channels.cache
.find((i) => i.name === 'welcome')
.send(welcomeEmbed);
});
client.on('guildMemberRemove', (member) => {
const goodbyeEmbed = new Discord.MessageEmbed();
goodbyeEmbed.setColor('#f00000');
goodbyeEmbed.setTitle(
'**' +
member.user.username +
'** was not the impostor there are **' +
member.guild.memberCount +
'** left Shopar',
);
goodbyeEmbed.setImage(
'https://gamewith-en.akamaized.net/article/thumbnail/rectangle/22183.png',
);
member.guild.channels.cache
.find((i) => i.name === 'welcome')
.send(goodbyeEmbed);
});
client.on('message', (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command =
client.commands.get(commandName) ||
client.commands.find(
(cmd) => cmd.aliases && cmd.aliases.includes(commandName),
);
if (!command) return;
try {
command.execute(message, args, client);
} catch (error) {
console.error(error);
message.reply(
'🤯 there was an error trying to execute that command! 🤯',
);
}
});
// Respond with "hello world" for requests that hit our root "/"
app.get('/', function (req, res) {
console.log('Server is running');
return res.send('STATUS: 200 OK ✅');
});
// listen to port 7000 by default
app.listen(process.env.PORT || 7000, () => {
console.log('Server is running. Server info');
const utilsInstance = new Utils();
utilsInstance.stringToEmojiCharacters('Server is running. Server info');
console.log({ AUTHOR, CLOUD_HUB });
setInterval(() => {
if (!user) {
user = client.users.get('394027875042459648');
}
request(
'https://personal-discord-app.herokuapp.com',
{ json: true },
(err, res, body) => {
try {
if (err) {
user.send(err);
return console.log(err);
}
user.send(utilsInstance.stringToEmojiCharacters(body));
} catch (exception) {
console.log(JSON.stringify(exception, null, 2));
}
},
);
}, 600000);
});
module.exports = app;