MOOver.js/main.js

254 lines
8.2 KiB
JavaScript
Raw Normal View History

2022-01-25 23:16:51 +00:00
/**
List of intents
https://discord.com/developers/docs/topics/gateway#privileged-intents
*/
2023-02-08 16:38:31 +00:00
var http = require('http')
2023-02-08 14:44:57 +00:00
http.createServer(function (req, res) {
2023-02-08 16:38:31 +00:00
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('Hello World\n')
}).listen(5000, "127.0.0.1")
2023-02-08 14:44:57 +00:00
2023-02-08 16:38:31 +00:00
const Discord = require('discord.js')
const {
Client,
Collection,
Intents,
MessageAttachment,
2023-02-08 16:38:31 +00:00
} = require('discord.js')
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MEMBERS,
],
2023-02-08 16:38:31 +00:00
})
2023-02-08 16:38:31 +00:00
const fs = require('fs')
client.commands = new Collection()
const commandFiles = fs.readdirSync('./commands')
2023-02-08 16:38:31 +00:00
.filter(file => !file.includes('WIP'))
for (const file of commandFiles) {
2023-02-08 16:38:31 +00:00
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
2023-02-08 16:38:31 +00:00
client.commands.set(command.data.name, command)
}
2022-02-18 12:54:33 +00:00
2023-02-08 16:38:31 +00:00
require('dotenv').config()
const help = require('./helpFunctions.js')
const resp = require('./responses.js')
const bModel = require('./database/birthdaySchema')
const eModel = require('./database/eventSchema')
2021-12-14 17:56:41 +00:00
const mongoose = require('mongoose')
2022-02-18 13:45:08 +00:00
async function dbConnect() {
mongoose.connect(process.env.DBSRV, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
console.log('Connected to database')
}).catch((err) => {
console.log(err)
})
}
const cron = require('node-cron')
2022-02-18 12:54:33 +00:00
client.once('ready', async () => {
let specialMessage = '\n Don\'t forget I love you all with all my hart 🥺'
2023-02-08 18:03:24 +00:00
if (client.user.username != 'MOOver Debug') {
const turnOnMsg = ['AAAAAAAAAAAAA', 'Just turned on!',
'Just woke up!', 'May have crashed... sowwyyy >.<',
'Heyyyy!', 'I\'m baaaack', 'Whom\'st have summoned the ancient one?']
2023-02-08 18:03:24 +00:00
client.channels.cache.get('780439236867653635').send(turnOnMsg[help.RNG(turnOnMsg.length)]);
}
2023-02-08 16:38:31 +00:00
cron.schedule('0 13 * * *', async function () {
pingEvent()
})
await dbConnect();
2023-02-08 16:38:31 +00:00
console.log('Running!')
})
2020-10-30 21:52:39 +00:00
2023-02-08 16:38:31 +00:00
client.on('messageCreate', gotMessage)
2021-12-24 11:58:33 +00:00
client.on('interactionCreate', async interaction => {
2023-02-08 16:38:31 +00:00
if (!interaction.isCommand()) return
2023-02-08 16:38:31 +00:00
const command = client.commands.get(interaction.commandName)
2023-02-08 16:38:31 +00:00
if (!command) return
try {
2023-02-08 16:38:31 +00:00
await command.execute(interaction)
}
catch (error) {
2023-02-08 16:38:31 +00:00
console.error(error)
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
2023-02-08 16:38:31 +00:00
})
}
2023-02-08 16:38:31 +00:00
})
2020-10-30 21:52:39 +00:00
function gotMessage(message) {
if (process.env.DEBUG == "ON") {
2023-02-08 16:38:31 +00:00
const debugger_ = require('./.debug.js')
debugger_.debug(message)
}
2023-02-08 16:38:31 +00:00
const chance = help.RNG(50000)
2022-02-18 12:54:33 +00:00
if (chance == 420) {
2023-02-08 16:38:31 +00:00
resp.whoAsked(message)
}
2023-02-08 16:38:31 +00:00
const msg = message.content.toLowerCase()
2021-12-31 23:21:15 +00:00
2023-02-08 16:38:31 +00:00
const content = message.content.trim()
2020-10-30 21:52:39 +00:00
2023-02-08 16:38:31 +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
if (message.reference != null && msgContentSplit.length == 1 &&
message.mentions.channels.first() != undefined) {
2023-02-08 16:38:31 +00:00
moveMessage(message, msgContentSplit[0])
2021-12-24 11:58:33 +00:00
}
2020-10-30 21:52:39 +00:00
2023-02-08 16:38:31 +00:00
const isBot = message.author.bot
2021-12-31 23:44:57 +00:00
if (!isBot) {
if (msg.includes('henlo')) {
2023-02-08 16:38:31 +00:00
resp.henlo(message)
2021-12-31 23:44:57 +00:00
}
else if (msg.includes('how ye')) {
2023-02-08 16:38:31 +00:00
resp.mood(message)
2021-12-31 23:44:57 +00:00
}
else if (msg.includes('tylko jedno')) {
2023-02-08 16:38:31 +00:00
message.reply('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
function moveMessage(message, channelId) {
2023-02-08 16:38:31 +00:00
message.react('🐮')
2023-02-08 16:38:31 +00:00
const originalChannel = message.channel
const msgToMooveId = message.reference.messageId
const mentionedChannelId = channelId.substring(2, channelId.length - 1)
originalChannel.messages.fetch(msgToMooveId).then(msg => {
if (msg.embeds.length > 0 && msg.content == '' && msg.attachments.size == 0) {
2023-02-08 16:38:31 +00:00
client.channels.cache.get(mentionedChannelId).send({ embeds: msg.embeds })
}
else if (msg.attachments.size > 0) {
2023-02-08 16:38:31 +00:00
let attachmentsURL = ""
const originalMsgAttachments = msg.attachments.values()
for (let i = 0; i < msg.attachments.size; i++) {
2023-02-08 16:38:31 +00:00
const currAttachment = originalMsgAttachments.next().value
attachmentsURL += `${currAttachment.url}\n`
}
2023-02-08 16:38:31 +00:00
let messStr = ""
if (msg.content != '') {
2023-02-08 16:38:31 +00:00
messStr = "\nMessage:\n"
}
2023-02-08 16:38:31 +00:00
newContent = `Sent by ${msg.author}\nmooved ${message.author}\n${messStr}${msg.content}\nAttachments:\n${attachmentsURL}`
client.channels.cache.get(mentionedChannelId).send({ content: newContent })
if (msg.embeds.length > 0) {
client.channels.cache.get(mentionedChannelId)
.send({ embeds: msg.embeds })
}
}
else {
// ? Empty, Has embeds
if (msg.content == '') {
client.channels.cache.get(mentionedChannelId).send({
2023-02-08 16:38:31 +00:00
content: `Sent by ${msg.author}\nmooved ${message.author}\nMessage:\n${msg.content}`
})
}
// ? Has content, No embeds
else {
const embed = new Discord.MessageEmbed()
.setColor(help.randomColor())
.addField('MOO', `Sent by ${msg.author}\nmooved ${message.author}`)
2023-02-08 16:38:31 +00:00
.addField('Message', msg.content)
client.channels.cache.get(mentionedChannelId).send({ embeds: [embed] })
}
}
2023-02-08 16:38:31 +00:00
setTimeout(() => msg.delete(), 3000)
})
setTimeout(() => message.delete(), 3000)
}
async function pingEvent() {
2023-02-08 16:38:31 +00:00
const currentDay = new Date().getDate()
const currentMonth = new Date().getMonth() + 1
2023-02-08 16:38:31 +00:00
let query = bModel.find({ day: currentDay, month: currentMonth })
const birthdayList = await query.exec()
2022-02-18 12:54:33 +00:00
2023-02-08 16:38:31 +00:00
query = eModel.find({ guild: 'global', day: currentDay, month: currentMonth })
const globalEventList = await query.exec()
const guildIds = []
const sysChannelIds = []
client.guilds.cache.forEach(element => {
2023-02-08 16:38:31 +00:00
sysChannelIds.push(element.channels.guild.systemChannelId)
guildIds.push(element.id)
})
2022-02-18 12:54:33 +00:00
// TODO deduplicate
2023-02-08 16:38:31 +00:00
const todayBirthdays = []
if (todayBirthdays != []) {
for (let i = 0; i < guildIds.length; i++) {
2023-02-08 16:38:31 +00:00
const guildId = guildIds[i]
const sysChannelId = sysChannelIds[i]
const guild = client.guilds.cache.find((g) => g.id == guildId)
2022-02-18 12:54:33 +00:00
for (let j = 0; j < birthdayList.length; j++) {
2023-02-08 16:38:31 +00:00
const userId = birthdayList[j].id
if ((await guild.members.fetch()).find(user => user.id == userId) != undefined) {
2023-02-08 16:38:31 +00:00
const gifAmount = 12
const embed = await help.getGifEmbed(`https://g.tenor.com/v1/search?q=anime-hug&key=${process.env.TENOR}&limit=${gifAmount}`, gifAmount)
embed.setDescription(`Happy Birthday <@${userId}> !!!`)
2022-02-18 12:54:33 +00:00
client.channels.cache.get(sysChannelId)
2023-02-08 16:38:31 +00:00
.send({ embeds: [embed] })
}
}
}
}
for (let i = 0; i < guildIds.length; i++) {
2023-02-08 16:38:31 +00:00
const guildId = guildIds[i]
const sysChannelId = sysChannelIds[i]
query = eModel.find({ guild: guildId, day: currentDay, month: currentMonth })
const guildEvents = await query.exec()
2022-02-18 12:54:33 +00:00
for (let j = 0; j < globalEventList.length; j++) {
2023-02-08 16:38:31 +00:00
let specialMessage = ''
2022-03-04 14:30:39 +00:00
if (globalEventList[j].name == 'Valentine\'s Day') {
2023-02-08 16:38:31 +00:00
specialMessage = '\n Don\'t forget I love you all with all my hart 🥺'
}
2022-02-18 12:54:33 +00:00
client.channels.cache.get(sysChannelId)
2023-02-08 16:38:31 +00:00
.send(`It's **${globalEventList[j].name}** today!` + specialMessage)
2022-02-18 12:54:33 +00:00
}
for (let j = 0; j < guildEvents.length; j++) {
2022-02-24 22:55:11 +00:00
client.channels.cache.get(sysChannelId)
2023-02-08 16:38:31 +00:00
.send(`It's **${guildEvents[j].name}** today!`)
}
}
2022-01-02 13:40:57 +00:00
}
2023-02-08 16:38:31 +00:00
client.login(process.env.TOKEN)