This repository was archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
307 lines (258 loc) · 11.9 KB
/
index.js
File metadata and controls
307 lines (258 loc) · 11.9 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
const fs = require('node:fs');
const { Client, Collection, Intents, MessageEmbed } = require('discord.js');
const { Token, TwitterConsumerKey, TwitterConsumerSecret, Color, TwitterAccessTokenKey,
TwitterAccessTokenSecret, guildID, TwitterFollowing, ChannelsToPost, YouTubeChannelID,
PlatformRoles, SnowflakesRole, ColorRoles } = require('./config.json');
const { loadJSON } = require('./birthday-data');
const { CheckBirthday } = require('./birthday-data/birthdaysystem');
const client = new Client({ intents: [Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MEMBERS] });
const Twitter = require('node-tweet-stream');
const YouTubeNotification = require('./youtube-notification');
const generateImage = require('./generate-image');
const TicTacToe = require('discord-tictactoe');
const game = new TicTacToe({ language: 'en', commandOptionName: 'user' });
/************** Set All Slashcommands Files **************/
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
console.log('Files loaded..');
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
console.log(`✔ [${file}] have been loaded!`);
}
/******************** Set Twitter API ********************/
const SocialTwitter = new Twitter({
consumer_key: TwitterConsumerKey,
consumer_secret: TwitterConsumerSecret,
token: TwitterAccessTokenKey,
token_secret: TwitterAccessTokenSecret,
});
/************** Set Twitter Accounts To Follow **************/
let followedAccounts = TwitterFollowing;
console.log(' \nTwitter users loading..');
for(let i = 0; i < followedAccounts.length; i++){
SocialTwitter.follow(followedAccounts[i]);
console.log(`✔ Following Twitter UserID [${followedAccounts[i]}]`);
}
/**************** Set YouTube Notification *****************/
const SocialYouTube = new YouTubeNotification({
channels: [YouTubeChannelID[0], YouTubeChannelID[1], YouTubeChannelID[2]],
/* Nintendo, VALORANT, IGN */
checkInterval: 60 /* Interval to check the latest video. */
});
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%% Milkshake Bot Code %%%%%%%%%%%%%%%%%%%%%%%%%%%*/
client.on('ready', async () => {
const status = [
"a tornado of flavors..\naahaaah!",
"my body temperature.",
`${client.guilds.cache.size} servers & ${client.users.cache.size} users!`
];
let randomNumber = 0;
setInterval(() => {
randomNumber = Math.floor(Math.random() * (status.length));
client.user.setActivity(`${status[randomNumber]}`, { type: 'WATCHING' });
}, 1000*60); /* 1000ms = 1s */
/* client.user.setActivity('a tornado of flavors!', { type: 'WATCHING' }); */
/************************ Birthday System ************************/
setInterval(async () => {
const BirthdayData = loadJSON('./birthday-data/birthdata.json');
CheckBirthday(client, BirthdayData);
}, 1000*45); /* 1000ms = 1s */
console.log(`\n\n${client.user.username} is ready to taste!\n`);
sendLog(`${client.user.username} is ready to taste!`);
});
/****************** Reconnecting client ******************/
client.on('reconnecting', () => {
client.user.setActivity(`Reconnecting..`, { status: 'idle' });
sendLog(`Reconnecting..`);
});
/************ Interaction With Slashcommands ************/
client.on('interactionCreate', async interaction => {
if(interaction.isCommand()){
if(interaction.commandName === 'tictactoe'){
return game.handleInteraction(interaction);
}
const command = client.commands.get(interaction.commandName);
if(!command) return;
try{
await command.execute(client, interaction);
}catch(error){
console.error(error);
sendLog(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
if(interaction.isButton()){
const user = interaction.guild.members.cache.get(interaction.user.id);
if(interaction.customId === 'pc'){
/* Add or Remove user role */
const role = interaction.guild.roles.cache.get(PlatformRoles[0]);
addRemoveRoles(user, interaction, role);
/* Delete message reply */
const message = await interaction.fetchReply();
deleteReplyButton(interaction, message);
}else if(interaction.customId === 'nintendo'){
/* Add or Remove user role */
const role = interaction.guild.roles.cache.get(PlatformRoles[1]);
addRemoveRoles(user, interaction, role);
/* Delete message reply */
const message = await interaction.fetchReply();
deleteReplyButton(interaction, message);
}else if(interaction.customId === 'xbox'){
/* Add or Remove user role */
const role = interaction.guild.roles.cache.get(PlatformRoles[2]);
addRemoveRoles(user, interaction, role);
/* Delete message reply */
const message = await interaction.fetchReply();
deleteReplyButton(interaction, message);
}else if(interaction.customId === 'playstation'){
/* Add or Remove user role */
const role = interaction.guild.roles.cache.get(PlatformRoles[3]);
addRemoveRoles(user, interaction, role);
/* Delete message reply */
const message = await interaction.fetchReply();
deleteReplyButton(interaction, message);
}else if(interaction.customId === 'snowflakes'){
/* Add or Remove user role */
const role = interaction.guild.roles.cache.get(SnowflakesRole);
addRemoveRoles(user, interaction, role);
/* Delete message reply */
const message = await interaction.fetchReply();
deleteReplyButton(interaction, message);
}else{
for(let i = 0; i < ColorRoles.length; i++){
if(interaction.customId === ColorRoles[i]){
/* Add or Remove user role */
let role = interaction.guild.roles.cache.get(ColorRoles[i]);
addRemoveRoles(user, interaction, role);
/* Remove other roles from the same group */
for(let j = 0; j < ColorRoles.length; j++){
if(user.roles.cache.has(ColorRoles[j]) && j != i){
role = interaction.guild.roles.cache.get(ColorRoles[j]);
user.roles.remove(ColorRoles[j]);
const wait = require('node:timers/promises').setTimeout;
await wait(1000);
await interaction.editReply(`I removed you the ${role.name} role.`);
sendLog(`I removed the ${role.name} Role from user <@${user.id}>.`);
}
}
/* Delete message reply */
let message = await interaction.fetchReply();
deleteReplyButton(interaction, message);
}
}
}
}
function addRemoveRoles(user, interactionButton, role){
if(user.roles.cache.has(role.id)){
user.roles.remove(role.id);
interactionButton.reply(`I removed you the ${role.name} role.`);
sendLog(`I removed the ${role.name} Role from user <@${user.id}>.`);
}else{
user.roles.add(role.id);
interactionButton.reply(`I added you the ${role.name} role.`);
sendLog(`I added the ${role.name} Role from user <@${user.id}>.`);
}
}
function deleteReplyButton(interactionButton, message){
setTimeout(() => {
interactionButton.channel.messages.fetch(message.id)
.then((msg) => {
interactionButton.deleteReply(); /* console.log(msg); */
})
.catch((error) => {
if(!error.httpStatus === 404)
console.log(error);
});
}, 1000*2.5);
}
});
/************** Sends A Welcome Image When A New User Joins The Server **************/
client.on('guildMemberAdd', async member => {
const optionsDate = { year: 'numeric', month: 'long', day: 'numeric' };
const optionsTime = { hour: '2-digit', minute: '2-digit', hour12: true };
const newMember = member.guild.members.cache.get(member.user.id);
const newMemberEmbed = new MessageEmbed()
.setTitle(`🔎 ${member.user.username} joined the server!`)
.addField(`User Tag`, `<@${member.user.id}>`, true)
.addField(`User ID`, `${member.user.id}`, true)
.addField('\u200B', '\u200B', true)
.addField('Joined Discord', `${new Date(member.user.createdTimestamp).toLocaleDateString('en-us', optionsDate)}\n${new Date(member.user.createdTimestamp).toLocaleTimeString('en-us', optionsTime)}`, true)
.addField('Joined server', `${new Date(newMember.joinedTimestamp).toLocaleDateString('en-us', optionsDate)}\n${new Date(newMember.joinedTimestamp).toLocaleTimeString('en-us', optionsTime)}`, true)
.addField('\u200B', '\u200B', true)
.setThumbnail(member.user.displayAvatarURL({ size: 1024, dynamic: true}))
.setColor(Color)
.setTimestamp();
const welcomeImage = await generateImage(member, `${member.user.username} just joined the server`);
client.channels.cache.get(ChannelsToPost[7]).send({
embeds: [newMemberEmbed]
});
client.channels.cache.get(ChannelsToPost[0]).send({
content: `Hey, <@${member.id}>, welcome to SnowMi's House ❄! <:1_Hi:866983162533773312>`,
files: [welcomeImage]
});
sendLog(`${member.user.username} joined the server`);
});
/**************** Sends A Goodbye Image When A User Leaves The Server ****************/
client.on('guildMemberRemove', async member => {
const randomMessages = [
'Keep in touch!',
'Goodbye always makes my throat hurt\nWaiit.. I\'m a bot!',
'See you soon..'
];
const randomIndex = Math.floor(Math.random() * (randomMessages.length));
const welcomeImage = await generateImage(member, `${member.user.username} just left the server, Bye! 🙁`);
client.channels.cache.get(ChannelsToPost[0]).send({
content: `${randomMessages[randomIndex]}`,
files: [welcomeImage]
});
sendLog(`${member.user.username} left the server`);
});
/********* Send Tweets To The respective Channels *********/
SocialTwitter.on('tweet', function(tweet){
/* console.log('Tweet received!', tweet); */
/* console.log(`[DEBUG] Twitter - ${tweet.user.screen_name} ${tweet.user.id}`); */
const tweetToSend = `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`;
/*** All tweets are sent to the [BOT-SPAM] channel [MILKSHAKE BOT Server] ***/
let TwitterUsers = TwitterFollowing;
for(let i = 0; i < TwitterFollowing.length; i++){
if(tweet.user.id == TwitterUsers[i])
client.channels.cache.get(ChannelsToPost[5]).send(tweetToSend);
}
/*** Tweets from [@PlayVALORANT] are sent to the [OTHER-GAMES] channel ***/
if(tweet.user.id == TwitterFollowing[0]){
client.channels.cache.get(ChannelsToPost[1]).send(tweetToSend);
/*** Tweets from [@NintendoAmerica] & [@NintendoEurope] are sent to the [NINTENDO] channel ***/
}else if(tweet.user.id == TwitterFollowing[1] || tweet.user.id == TwitterFollowing[2]){
client.channels.cache.get(ChannelsToPost[2]).send(tweetToSend);
}
});
/******************* Catch Twitter error *******************/
SocialTwitter.on('error', function (error) {
console.log('⚠ SocialTwitter Down!', error);
sendLog(`⚠ SocialTwitter Down!\n${error}`);
});
/********* Send Videos To The respective Channels *********/
SocialYouTube.on('video', video => {
/* console.log(video); */
const URLVideo = `https://youtu.be/${video.id}`;
/* Videos from [VALORANT] are sent to the [OTHER-GAMES] channel */
if(video.channelID === YouTubeChannelID[0]){
client.channels.cache.get(ChannelsToPost[1]).send(URLVideo);
/* Videos from [NINTENDO] are sent to the [NINTENDO] channel */
}else if(video.channelID === YouTubeChannelID[1]){
client.channels.cache.get(ChannelsToPost[2]).send(URLVideo);
/* Videos from [IGN] are sent to the [MILKSHAKE] channel */
}else if(video.channelID === YouTubeChannelID[2]){
client.channels.cache.get(ChannelsToPost[5]).send(URLVideo);
}
});
client.login(Token);
/* Send console.log messages to a log channel */
function sendLog(string){
client.channels.cache.get(ChannelsToPost[6]).send(`\`\`\`js\n${new Date().toLocaleString()}\n${string}\n\`\`\``);
}