2022-01-25 23:16:51 +00:00
|
|
|
/**
|
|
|
|
List of intents
|
|
|
|
https://discord.com/developers/docs/topics/gateway#privileged-intents
|
|
|
|
*/
|
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
const {
|
|
|
|
Client,
|
|
|
|
Collection,
|
|
|
|
Intents,
|
|
|
|
MessageAttachment,
|
|
|
|
} = require('discord.js');
|
|
|
|
const client = new Client({
|
|
|
|
intents: [
|
|
|
|
Intents.FLAGS.GUILDS,
|
|
|
|
Intents.FLAGS.GUILD_MESSAGES,
|
|
|
|
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
|
|
|
|
Intents.FLAGS.GUILD_MEMBERS,
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
require('dotenv').config();
|
2021-12-27 16:14:37 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
client.commands = new Collection();
|
|
|
|
const commandFiles = fs.readdirSync('./commands')
|
|
|
|
.filter(file => !file.includes('WIP'));
|
|
|
|
|
2022-02-12 17:50:34 +00:00
|
|
|
const cron = require('node-cron');
|
2022-02-12 13:04:18 +00:00
|
|
|
for (const file of commandFiles) {
|
|
|
|
const command = require(`./commands/${file}`);
|
|
|
|
// Set a new item in the Collection
|
|
|
|
// With the key as the command name and the value as the exported module
|
|
|
|
client.commands.set(command.data.name, command);
|
|
|
|
}
|
|
|
|
|
|
|
|
const help = require('./helpFunctions.js');
|
2021-12-14 17:56:41 +00:00
|
|
|
|
2020-10-30 21:52:39 +00:00
|
|
|
client.once('ready', () => {
|
2022-02-12 13:04:18 +00:00
|
|
|
if (client.user.username != 'MOOver Debug') {
|
|
|
|
client.channels.cache.get('780439236867653635').send('Just turned on!');
|
|
|
|
}
|
2022-02-12 17:50:34 +00:00
|
|
|
cron.schedule('0 13 * * *', pingEvent());
|
2022-02-12 13:04:18 +00:00
|
|
|
console.log('Running!');
|
2020-10-30 21:52:39 +00:00
|
|
|
});
|
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
client.on('messageCreate', gotMessage);
|
2021-12-24 11:58:33 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
client.on('interactionCreate', async interaction => {
|
|
|
|
if (!interaction.isCommand()) return;
|
|
|
|
|
|
|
|
const command = client.commands.get(interaction.commandName);
|
|
|
|
|
|
|
|
if (!command) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await command.execute(interaction);
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
await interaction.reply({
|
|
|
|
content: 'There was an error while executing this command!',
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-10-30 21:52:39 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
function gotMessage(message) {
|
|
|
|
if (message.content.includes('https://media.discordapp.net') &&
|
|
|
|
(message.content.includes('webm') ||
|
|
|
|
message.content.includes('mov') ||
|
|
|
|
message.content.includes('mp4'))) {
|
2022-01-28 18:36:24 +00:00
|
|
|
const linkArr = message.content.split('https://media.discordapp.net');
|
2022-02-12 13:04:18 +00:00
|
|
|
message.channel.send('https://cdn.discordapp.com' + linkArr[1]);
|
2020-10-30 21:52:39 +00:00
|
|
|
}
|
2020-11-03 11:22:42 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
const chance = help.RNG(3000);
|
|
|
|
if (chance == 1337) {
|
|
|
|
whoAsked(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
const msg = message.content.toLowerCase();
|
2021-12-31 23:21:15 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
const content = message.content.trim();
|
2020-10-30 21:52:39 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
const msgContentSplit = content.split(/[ ]+/);
|
2022-01-26 11:42:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* reference can't be null => must be a reply to message
|
|
|
|
* must contain only one argument
|
|
|
|
* that argument mentions channel
|
|
|
|
*/
|
2022-01-26 12:23:08 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
if (message.reference != null && msgContentSplit.length == 1 &&
|
|
|
|
message.mentions.channels.first() != undefined) {
|
|
|
|
move(message, msgContentSplit[0]);
|
2021-12-24 11:58:33 +00:00
|
|
|
}
|
2020-10-30 21:52:39 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
const isBot = message.author.bot;
|
2021-12-31 23:44:57 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
if (!isBot) {
|
|
|
|
if (msg.includes('henlo')) {
|
2022-01-26 12:23:08 +00:00
|
|
|
henlo(message);
|
2021-12-31 23:44:57 +00:00
|
|
|
}
|
2022-02-12 13:04:18 +00:00
|
|
|
else if (msg.includes('how ye')) {
|
|
|
|
mood(message);
|
2021-12-31 23:44:57 +00:00
|
|
|
}
|
2022-02-12 13:04:18 +00:00
|
|
|
else if (msg.includes('tylko jedno')) {
|
|
|
|
message.channel.send('Koksu pięć gram odlecieć sam');
|
2022-01-02 13:40:57 +00:00
|
|
|
}
|
2021-12-24 11:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-10 15:17:07 +00:00
|
|
|
|
2021-12-24 11:58:33 +00:00
|
|
|
// Responses
|
2022-02-12 13:04:18 +00:00
|
|
|
function henlo(message) {
|
|
|
|
const emojis = ['🥰', '🐄', '🐮', '❤️', '👋', '🤠', '😊'];
|
|
|
|
const randomNum = help.RNG(emojis.length);
|
|
|
|
message.reply('Henlooo ' + message.author.username + ' ' + emojis[randomNum]);
|
2021-12-24 11:58:33 +00:00
|
|
|
}
|
2020-10-30 21:52:39 +00:00
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
function mood(message) {
|
|
|
|
const responses = ['Not bad, how yee?', 'MOOdy', 'A bit sad 😢', 'Good, how yee?', 'I\'m fine, how yee?'];
|
|
|
|
const randomNum = help.RNG(responses.length);
|
2022-01-24 18:13:34 +00:00
|
|
|
message.reply(responses[randomNum]);
|
2021-12-24 11:58:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
function move(message, channelId) {
|
|
|
|
message.react('🐮');
|
|
|
|
|
|
|
|
const replyChannel = message.channel;
|
2022-01-26 11:42:28 +00:00
|
|
|
|
|
|
|
const msgToMooveId = message.reference.messageId;
|
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
const mentionedChannelId = channelId.substring(2, channelId.length - 1);
|
|
|
|
|
2022-01-26 11:42:28 +00:00
|
|
|
replyChannel.messages.fetch(msgToMooveId).then(msg => {
|
2022-02-12 13:04:18 +00:00
|
|
|
if (msg.attachments.size > 0) {
|
|
|
|
const newMsgAttachments = [];
|
|
|
|
const allAttachments = msg.attachments.values();
|
|
|
|
|
|
|
|
for (let i = 0; i < msg.attachments.size; i++) {
|
|
|
|
const currAttachment = allAttachments.next().value;
|
|
|
|
newMsgAttachments.push(new MessageAttachment(currAttachment.url));
|
2021-12-14 17:56:41 +00:00
|
|
|
}
|
2021-12-27 17:17:57 +00:00
|
|
|
|
2022-02-12 13:19:44 +00:00
|
|
|
if (msg.embeds.length > 0) {
|
|
|
|
client.channels.cache.get(mentionedChannelId)
|
2022-02-12 13:35:16 +00:00
|
|
|
.send({ content: `Sent by ${msg.author}\nmooved ${message.author}`, embeds: msg.embeds, files: newMsgAttachments });
|
2022-02-12 13:19:44 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
client.channels.cache.get(mentionedChannelId)
|
|
|
|
.send({ content: `Sent by ${msg.author}\nmooved ${message.author}`, files: newMsgAttachments });
|
|
|
|
}
|
2022-01-26 11:42:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-02-12 13:04:18 +00:00
|
|
|
const embed = new Discord.MessageEmbed()
|
|
|
|
.setColor(help.randomColor())
|
2022-02-12 13:35:16 +00:00
|
|
|
.addField('MOO', `Sent by ${msg.author}\nmooved ${message.author}`);
|
|
|
|
if (msg.content.includes('http')) {
|
|
|
|
const file = new MessageAttachment(msg.content);
|
|
|
|
client.channels.cache.get(mentionedChannelId).send({
|
|
|
|
embeds: [embed], files: [file] });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
embed.addField('Message:', msg.content);
|
|
|
|
client.channels.cache.get(mentionedChannelId).send({
|
|
|
|
embeds: [embed] });
|
|
|
|
}
|
|
|
|
}
|
2022-02-12 13:04:18 +00:00
|
|
|
setTimeout(() => msg.delete(), 3000);
|
2022-01-26 11:42:28 +00:00
|
|
|
});
|
|
|
|
setTimeout(() => message.delete(), 3000);
|
2021-12-24 11:58:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
async function whoAsked(message) {
|
|
|
|
const searchKey = 'who-asked';
|
|
|
|
const gifAmount = 20;
|
|
|
|
const gifs = `https://g.tenor.com/v1/search?q=${searchKey}&key=${process.env.TENOR}&limit=${gifAmount}`;
|
|
|
|
|
|
|
|
message.reply({ embeds: [help.getGifEmbed(gifs, gifAmount)] });
|
|
|
|
}
|
|
|
|
|
|
|
|
async function pingEvent() {
|
|
|
|
const currentDay = new Date().getDate();
|
|
|
|
const currentMonth = new Date().getMonth();
|
|
|
|
|
|
|
|
const guildIds = [];
|
|
|
|
const sysChannelIds = [];
|
|
|
|
client.guilds.cache.forEach(element => {
|
|
|
|
sysChannelIds.push(element.channels.guild.systemChannelId);
|
|
|
|
guildIds.push(element.id);
|
|
|
|
});
|
|
|
|
// TODO deduplicate
|
|
|
|
const birthdays = require('./database/birthdays.json');
|
|
|
|
const todayBirthdays = [];
|
|
|
|
for (let i = 0; i < birthdays.length; i++) {
|
|
|
|
if (birthdays[i].day == currentDay && birthdays[i].month == currentMonth) {
|
|
|
|
todayBirthdays.push((birthdays[i].id, birthdays[i].nickname));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (todayBirthdays != []) {
|
|
|
|
for (let i = 0; i < guildIds.length; i++) {
|
|
|
|
const guildId = guildIds[i];
|
|
|
|
const sysChannelId = sysChannelIds[i];
|
|
|
|
const guild = client.guilds.cache.find((g) => g.id == guildId);
|
|
|
|
for (let j = 0; j < todayBirthdays.length; j++) {
|
|
|
|
const userId = todayBirthdays[i][0];
|
|
|
|
if ((await guild.members.fetch()).find(user => user.id == userId) != undefined) {
|
|
|
|
client.channels.cache.get(sysChannelId).send(`Happy birthday <@${userId}>!`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const eventsJSON = require('./database/events.json');
|
|
|
|
const globalEvents = eventsJSON.global;
|
|
|
|
const todayGlobalEvents = [];
|
|
|
|
for (let i = 0; i < globalEvents.length; i++) {
|
|
|
|
if (globalEvents[i].day == currentDay && globalEvents[i].month == currentMonth) {
|
|
|
|
todayGlobalEvents.push((globalEvents[i].id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < guildIds.length; i++) {
|
|
|
|
const guildId = guildIds[i];
|
|
|
|
const guildEvents = eventsJSON[guild];
|
|
|
|
const sysChannelId = sysChannelIds[i];
|
|
|
|
const guild = client.guilds.cache.find((g) => g.id == guildId);
|
|
|
|
if (todayGlobalEvents != []) {
|
|
|
|
for (let j = 0; j < todayGlobalEvents.length; j++) {
|
|
|
|
let specialMessage;
|
|
|
|
if (todayGlobalEvents[i].name == 'Valentine\'s Day') {
|
|
|
|
specialMessage = '\n Don\'t forget I love you all with all my hart 🥺';
|
|
|
|
}
|
|
|
|
client.channels.cache.get(sysChannelId)
|
|
|
|
.send(`It's ${todayGlobalEvents} today!` + specialMessage);
|
|
|
|
}
|
|
|
|
for (let j = 0; j < guildEvents.length; j++) {
|
|
|
|
if (guildEvents[i].day == currentDay && guildEvents[i].month == currentMonth) {
|
|
|
|
client.channels.cache.get(sysChannelId)
|
|
|
|
.send(`It's ${todayGlobalEvents} today!`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-26 12:23:08 +00:00
|
|
|
}
|
2022-01-02 13:40:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-12 13:04:18 +00:00
|
|
|
client.login(process.env.TOKEN);
|