webhook
This commit is contained in:
parent
9c9446fd49
commit
e69896481c
3 changed files with 127 additions and 105 deletions
20
git_webhook.js
Normal file
20
git_webhook.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
const secret = `${process.env.GITHUB_WEBHOOK}`
|
||||||
|
const repo = "/home/moover/MOOver"
|
||||||
|
|
||||||
|
const http = require('http')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
const exec = require('child_process').exec
|
||||||
|
|
||||||
|
http.createServer(function (req, res) {
|
||||||
|
req.on('data', function (chunk) {
|
||||||
|
let sig = "sha1=" + crypto.createHmac('sha1', secret).update(chunk.toString()).digest('hex')
|
||||||
|
|
||||||
|
if (req.headers['x-hub-signature'] == sig) {
|
||||||
|
exec('cd ' + repo + ' && git pull' + '&& npm install' + 'pm2 restart 0')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
res.end()
|
||||||
|
}).listen(5050)
|
||||||
|
|
||||||
|
console.log("running webhook!")
|
197
main.js
197
main.js
|
@ -3,19 +3,19 @@
|
||||||
https://discord.com/developers/docs/topics/gateway#privileged-intents
|
https://discord.com/developers/docs/topics/gateway#privileged-intents
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var http = require('http');
|
var http = require('http')
|
||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, { 'Content-Type': 'text/plain' })
|
||||||
res.end('Hello World\n');
|
res.end('Hello World\n')
|
||||||
}).listen(1000, "127.0.0.1");
|
}).listen(5000, "127.0.0.1")
|
||||||
|
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js')
|
||||||
const {
|
const {
|
||||||
Client,
|
Client,
|
||||||
Collection,
|
Collection,
|
||||||
Intents,
|
Intents,
|
||||||
MessageAttachment,
|
MessageAttachment,
|
||||||
} = require('discord.js');
|
} = require('discord.js')
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
Intents.FLAGS.GUILDS,
|
Intents.FLAGS.GUILDS,
|
||||||
|
@ -23,71 +23,71 @@ const client = new Client({
|
||||||
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
|
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
|
||||||
Intents.FLAGS.GUILD_MEMBERS,
|
Intents.FLAGS.GUILD_MEMBERS,
|
||||||
],
|
],
|
||||||
});
|
})
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs')
|
||||||
client.commands = new Collection();
|
client.commands = new Collection()
|
||||||
const commandFiles = fs.readdirSync('./commands')
|
const commandFiles = fs.readdirSync('./commands')
|
||||||
.filter(file => !file.includes('WIP'));
|
.filter(file => !file.includes('WIP'))
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const command = require(`./commands/${file}`);
|
const command = require(`./commands/${file}`)
|
||||||
// Set a new item in the Collection
|
// Set a new item in the Collection
|
||||||
// With the key as the command name and the value as the exported module
|
// With the key as the command name and the value as the exported module
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command)
|
||||||
}
|
}
|
||||||
const cron = require('node-cron');
|
const cron = require('node-cron')
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose')
|
||||||
|
|
||||||
mongoose
|
mongoose
|
||||||
.connect(process.env.DBSRV, {
|
.connect(process.env.DBSRV, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log('Connected to database');
|
console.log('Connected to database')
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log(err);
|
console.log(err)
|
||||||
});
|
})
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config()
|
||||||
const help = require('./helpFunctions.js');
|
const help = require('./helpFunctions.js')
|
||||||
const resp = require('./responses.js');
|
const resp = require('./responses.js')
|
||||||
const bModel = require('./database/birthdaySchema');
|
const bModel = require('./database/birthdaySchema')
|
||||||
const eModel = require('./database/eventSchema');
|
const eModel = require('./database/eventSchema')
|
||||||
|
|
||||||
const turnOnMsg = ['AAAAAAAAAAAAA', 'Just turned on!', 'Just woke up!', 'May have crashed... sowwyyy >.<',
|
const turnOnMsg = ['AAAAAAAAAAAAA', 'Just turned on!', 'Just woke up!', 'May have crashed... sowwyyy >.<',
|
||||||
'Heyyyy!', 'I\'m baaaack', 'Whom\'st have summoned they ancient one?'];
|
'Heyyyy!', 'I\'m baaaack', 'Whom\'st have summoned they ancient one?']
|
||||||
|
|
||||||
client.once('ready', async () => {
|
client.once('ready', async () => {
|
||||||
// if (client.user.username != 'MOOver Debug') {
|
// if (client.user.username != 'MOOver Debug') {
|
||||||
// client.channels.cache.get('780439236867653635').send(turnOnMsg[help.RNG(turnOnMsg.length)]);
|
// client.channels.cache.get('780439236867653635').send(turnOnMsg[help.RNG(turnOnMsg.length)]);
|
||||||
// }
|
// }
|
||||||
cron.schedule('0 13 * * *', async function() {
|
cron.schedule('0 13 * * *', async function () {
|
||||||
pingEvent();
|
pingEvent()
|
||||||
});
|
})
|
||||||
console.log('Running!');
|
console.log('Running!')
|
||||||
});
|
})
|
||||||
|
|
||||||
client.on('messageCreate', gotMessage);
|
client.on('messageCreate', gotMessage)
|
||||||
|
|
||||||
client.on('interactionCreate', async interaction => {
|
client.on('interactionCreate', async interaction => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isCommand()) return
|
||||||
|
|
||||||
const command = client.commands.get(interaction.commandName);
|
const command = client.commands.get(interaction.commandName)
|
||||||
|
|
||||||
if (!command) return;
|
if (!command) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await command.execute(interaction);
|
await command.execute(interaction)
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error(error);
|
console.error(error)
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: 'There was an error while executing this command!',
|
content: 'There was an error while executing this command!',
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
function gotMessage(message) {
|
function gotMessage(message) {
|
||||||
if (message.content.includes('https://media.discordapp.net') &&
|
if (message.content.includes('https://media.discordapp.net') &&
|
||||||
|
@ -95,25 +95,25 @@ function gotMessage(message) {
|
||||||
message.content.includes('mov') ||
|
message.content.includes('mov') ||
|
||||||
message.content.includes('mp4') ||
|
message.content.includes('mp4') ||
|
||||||
message.embeds[0]?.type == 'video')) {
|
message.embeds[0]?.type == 'video')) {
|
||||||
const linkArr = message.content.split('https://media.discordapp.net');
|
const linkArr = message.content.split('https://media.discordapp.net')
|
||||||
message.channel.send('https://cdn.discordapp.com' + linkArr[1]);
|
message.channel.send('https://cdn.discordapp.com' + linkArr[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.DEBUG == "ON") {
|
if (process.env.DEBUG == "ON") {
|
||||||
const debugger_ = require('./.debug.js');
|
const debugger_ = require('./.debug.js')
|
||||||
debugger_.debug(message);
|
debugger_.debug(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
const chance = help.RNG(50000);
|
const chance = help.RNG(50000)
|
||||||
if (chance == 420) {
|
if (chance == 420) {
|
||||||
resp.whoAsked(message);
|
resp.whoAsked(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
const msg = message.content.toLowerCase();
|
const msg = message.content.toLowerCase()
|
||||||
|
|
||||||
const content = message.content.trim();
|
const content = message.content.trim()
|
||||||
|
|
||||||
const msgContentSplit = content.split(/[ ]+/);
|
const msgContentSplit = content.split(/[ ]+/)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reference can't be null => must be a reply to message
|
* reference can't be null => must be a reply to message
|
||||||
|
@ -123,53 +123,53 @@ function gotMessage(message) {
|
||||||
|
|
||||||
if (message.reference != null && msgContentSplit.length == 1 &&
|
if (message.reference != null && msgContentSplit.length == 1 &&
|
||||||
message.mentions.channels.first() != undefined) {
|
message.mentions.channels.first() != undefined) {
|
||||||
moveMessage(message, msgContentSplit[0]);
|
moveMessage(message, msgContentSplit[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
const isBot = message.author.bot;
|
const isBot = message.author.bot
|
||||||
|
|
||||||
if (!isBot) {
|
if (!isBot) {
|
||||||
if (msg.includes('henlo')) {
|
if (msg.includes('henlo')) {
|
||||||
resp.henlo(message);
|
resp.henlo(message)
|
||||||
}
|
}
|
||||||
else if (msg.includes('how ye')) {
|
else if (msg.includes('how ye')) {
|
||||||
resp.mood(message);
|
resp.mood(message)
|
||||||
}
|
}
|
||||||
else if (msg.includes('tylko jedno')) {
|
else if (msg.includes('tylko jedno')) {
|
||||||
message.reply('Koksu pięć gram odlecieć sam');
|
message.reply('Koksu pięć gram odlecieć sam')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveMessage(message, channelId) {
|
function moveMessage(message, channelId) {
|
||||||
message.react('🐮');
|
message.react('🐮')
|
||||||
|
|
||||||
const originalChannel = message.channel;
|
const originalChannel = message.channel
|
||||||
const msgToMooveId = message.reference.messageId;
|
const msgToMooveId = message.reference.messageId
|
||||||
const mentionedChannelId = channelId.substring(2, channelId.length - 1);
|
const mentionedChannelId = channelId.substring(2, channelId.length - 1)
|
||||||
|
|
||||||
originalChannel.messages.fetch(msgToMooveId).then(msg => {
|
originalChannel.messages.fetch(msgToMooveId).then(msg => {
|
||||||
if (msg.embeds.length > 0 && msg.content == '' && msg.attachments.size == 0) {
|
if (msg.embeds.length > 0 && msg.content == '' && msg.attachments.size == 0) {
|
||||||
client.channels.cache.get(mentionedChannelId).send({embeds: msg.embeds });
|
client.channels.cache.get(mentionedChannelId).send({ embeds: msg.embeds })
|
||||||
}
|
}
|
||||||
else if (msg.attachments.size > 0) {
|
else if (msg.attachments.size > 0) {
|
||||||
|
|
||||||
let attachmentsURL = "";
|
let attachmentsURL = ""
|
||||||
const originalMsgAttachments = msg.attachments.values();
|
const originalMsgAttachments = msg.attachments.values()
|
||||||
|
|
||||||
for (let i = 0; i < msg.attachments.size; i++) {
|
for (let i = 0; i < msg.attachments.size; i++) {
|
||||||
const currAttachment = originalMsgAttachments.next().value;
|
const currAttachment = originalMsgAttachments.next().value
|
||||||
attachmentsURL += `${currAttachment.url}\n`;
|
attachmentsURL += `${currAttachment.url}\n`
|
||||||
}
|
}
|
||||||
|
|
||||||
let messStr = "";
|
let messStr = ""
|
||||||
if (msg.content != '') {
|
if (msg.content != '') {
|
||||||
messStr = "\nMessage:\n";
|
messStr = "\nMessage:\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
newContent = `Sent by ${msg.author}\nmooved ${message.author}\n${messStr}${msg.content}\nAttachments:\n${attachmentsURL}`;
|
newContent = `Sent by ${msg.author}\nmooved ${message.author}\n${messStr}${msg.content}\nAttachments:\n${attachmentsURL}`
|
||||||
|
|
||||||
client.channels.cache.get(mentionedChannelId).send({content: newContent});
|
client.channels.cache.get(mentionedChannelId).send({ content: newContent })
|
||||||
if (msg.embeds.length > 0) {
|
if (msg.embeds.length > 0) {
|
||||||
client.channels.cache.get(mentionedChannelId)
|
client.channels.cache.get(mentionedChannelId)
|
||||||
.send({ embeds: msg.embeds })
|
.send({ embeds: msg.embeds })
|
||||||
|
@ -179,77 +179,78 @@ function moveMessage(message, channelId) {
|
||||||
// ? Empty, Has embeds
|
// ? Empty, Has embeds
|
||||||
if (msg.content == '') {
|
if (msg.content == '') {
|
||||||
client.channels.cache.get(mentionedChannelId).send({
|
client.channels.cache.get(mentionedChannelId).send({
|
||||||
content: `Sent by ${msg.author}\nmooved ${message.author}\nMessage:\n${msg.content}`});
|
content: `Sent by ${msg.author}\nmooved ${message.author}\nMessage:\n${msg.content}`
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// ? Has content, No embeds
|
// ? Has content, No embeds
|
||||||
else {
|
else {
|
||||||
const embed = new Discord.MessageEmbed()
|
const embed = new Discord.MessageEmbed()
|
||||||
.setColor(help.randomColor())
|
.setColor(help.randomColor())
|
||||||
.addField('MOO', `Sent by ${msg.author}\nmooved ${message.author}`)
|
.addField('MOO', `Sent by ${msg.author}\nmooved ${message.author}`)
|
||||||
.addField('Message', msg.content);
|
.addField('Message', msg.content)
|
||||||
client.channels.cache.get(mentionedChannelId).send({ embeds: [embed] });
|
client.channels.cache.get(mentionedChannelId).send({ embeds: [embed] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => msg.delete(), 3000);
|
setTimeout(() => msg.delete(), 3000)
|
||||||
});
|
})
|
||||||
setTimeout(() => message.delete(), 3000);
|
setTimeout(() => message.delete(), 3000)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pingEvent() {
|
async function pingEvent() {
|
||||||
const currentDay = new Date().getDate();
|
const currentDay = new Date().getDate()
|
||||||
const currentMonth = new Date().getMonth() + 1;
|
const currentMonth = new Date().getMonth() + 1
|
||||||
|
|
||||||
let query = bModel.find({ day: currentDay, month: currentMonth });
|
let query = bModel.find({ day: currentDay, month: currentMonth })
|
||||||
const birthdayList = await query.exec();
|
const birthdayList = await query.exec()
|
||||||
|
|
||||||
query = eModel.find({ guild: 'global', day: currentDay, month: currentMonth });
|
query = eModel.find({ guild: 'global', day: currentDay, month: currentMonth })
|
||||||
const globalEventList = await query.exec();
|
const globalEventList = await query.exec()
|
||||||
const guildIds = [];
|
const guildIds = []
|
||||||
const sysChannelIds = [];
|
const sysChannelIds = []
|
||||||
client.guilds.cache.forEach(element => {
|
client.guilds.cache.forEach(element => {
|
||||||
sysChannelIds.push(element.channels.guild.systemChannelId);
|
sysChannelIds.push(element.channels.guild.systemChannelId)
|
||||||
guildIds.push(element.id);
|
guildIds.push(element.id)
|
||||||
});
|
})
|
||||||
|
|
||||||
// TODO deduplicate
|
// TODO deduplicate
|
||||||
const todayBirthdays = [];
|
const todayBirthdays = []
|
||||||
if (todayBirthdays != []) {
|
if (todayBirthdays != []) {
|
||||||
for (let i = 0; i < guildIds.length; i++) {
|
for (let i = 0; i < guildIds.length; i++) {
|
||||||
const guildId = guildIds[i];
|
const guildId = guildIds[i]
|
||||||
const sysChannelId = sysChannelIds[i];
|
const sysChannelId = sysChannelIds[i]
|
||||||
const guild = client.guilds.cache.find((g) => g.id == guildId);
|
const guild = client.guilds.cache.find((g) => g.id == guildId)
|
||||||
for (let j = 0; j < birthdayList.length; j++) {
|
for (let j = 0; j < birthdayList.length; j++) {
|
||||||
const userId = birthdayList[j].id;
|
const userId = birthdayList[j].id
|
||||||
if ((await guild.members.fetch()).find(user => user.id == userId) != undefined) {
|
if ((await guild.members.fetch()).find(user => user.id == userId) != undefined) {
|
||||||
const gifAmount = 12;
|
const gifAmount = 12
|
||||||
const embed = await help.getGifEmbed(`https://g.tenor.com/v1/search?q=anime-hug&key=${process.env.TENOR}&limit=${gifAmount}`, gifAmount);
|
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}> !!!`);
|
embed.setDescription(`Happy Birthday <@${userId}> !!!`)
|
||||||
client.channels.cache.get(sysChannelId)
|
client.channels.cache.get(sysChannelId)
|
||||||
.send({ embeds: [embed] });
|
.send({ embeds: [embed] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < guildIds.length; i++) {
|
for (let i = 0; i < guildIds.length; i++) {
|
||||||
const guildId = guildIds[i];
|
const guildId = guildIds[i]
|
||||||
const sysChannelId = sysChannelIds[i];
|
const sysChannelId = sysChannelIds[i]
|
||||||
query = eModel.find({ guild: guildId, day: currentDay, month: currentMonth });
|
query = eModel.find({ guild: guildId, day: currentDay, month: currentMonth })
|
||||||
const guildEvents = await query.exec();
|
const guildEvents = await query.exec()
|
||||||
for (let j = 0; j < globalEventList.length; j++) {
|
for (let j = 0; j < globalEventList.length; j++) {
|
||||||
let specialMessage = '';
|
let specialMessage = ''
|
||||||
if (globalEventList[j].name == 'Valentine\'s Day') {
|
if (globalEventList[j].name == 'Valentine\'s Day') {
|
||||||
specialMessage = '\n Don\'t forget I love you all with all my hart 🥺';
|
specialMessage = '\n Don\'t forget I love you all with all my hart 🥺'
|
||||||
}
|
}
|
||||||
client.channels.cache.get(sysChannelId)
|
client.channels.cache.get(sysChannelId)
|
||||||
.send(`It's **${globalEventList[j].name}** today!` + specialMessage);
|
.send(`It's **${globalEventList[j].name}** today!` + specialMessage)
|
||||||
}
|
}
|
||||||
for (let j = 0; j < guildEvents.length; j++) {
|
for (let j = 0; j < guildEvents.length; j++) {
|
||||||
client.channels.cache.get(sysChannelId)
|
client.channels.cache.get(sysChannelId)
|
||||||
.send(`It's **${guildEvents[j].name}** today!`);
|
.send(`It's **${guildEvents[j].name}** today!`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.login(process.env.TOKEN);
|
client.login(process.env.TOKEN)
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node main.js"
|
"webhook": "node git_webhook.js",
|
||||||
|
"moover": "node main.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "16.x"
|
"node": "16.x"
|
||||||
|
|
Loading…
Reference in a new issue