-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
320 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const util = require('util'); | ||
|
||
/** | ||
* Execute the given code | ||
* @param {client} client Discord.js client instance | ||
* @param {Object} request Express.js request payload | ||
* @param {response} response The response to send back | ||
* @returns {void} | ||
*/ | ||
module.exports = (client, request, response) => { | ||
const interaction = request.body; | ||
const args = interaction.data.options; | ||
|
||
if (!client.config.ownerIDs.includes(interaction.member.user.id || interaction.member.user.id)) { | ||
return response.send({ | ||
type: 4, | ||
data: { | ||
content: 'Unfortunately, you cannot use this command.', | ||
flags: 64 | ||
} | ||
}); | ||
} | ||
|
||
try { | ||
const code = args.find(option => option.name === 'code').value == '-a' ? args.find(option => option.name === 'code').value.slice(1).join(' ') : args.find(option => option.name === 'code').value.join(' '); | ||
|
||
const fullCode = args[0].toLowerCase() == '-a' ? '(async () => {\n{code}\n})()': '{code}'; | ||
const str = fullCode.replace('{code}', code); | ||
const evaluation = util.inspect(eval(str), { | ||
depth: 0, | ||
}); | ||
|
||
return response.send({ | ||
type: 4, | ||
data: { | ||
content: `\`\`\`js\n${evaluation}\`\`\`` | ||
} | ||
}).catch(console.error); | ||
} catch (e) { | ||
return response.send({ | ||
type: 4, | ||
data: { | ||
content: `\`\`\`js\n${e.message}\`\`\`` | ||
} | ||
}).catch(console.error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Shows the help embed | ||
* @param {client} client Discord.js client instance | ||
* @param {Object} request Express.js request payload | ||
* @param {response} response The response to send back | ||
* @returns {void} | ||
*/ | ||
module.exports = (client, request, response) => { | ||
const interaction = request.body; | ||
|
||
response.send({ | ||
type: 4, | ||
data: { | ||
embeds: [{ | ||
author: { | ||
name: 'NoStickers\' Help Menu', | ||
icon_url: client.user.avatarURL() | ||
}, | ||
color: [240, 71, 71], | ||
description: ` | ||
\`help\` - Shows the list of commands. | ||
\`invite\` - Invite me to your server. | ||
\`nostickers\` - Disables stickers for the specific channels. | ||
\`stickers\` - Enables stickers for the specific channels. | ||
`, | ||
footer: { | ||
text: `Requested by ${interaction.member.user.username + '#' + interaction.member.user.discriminator || interaction.user.username + '#' + interaction.user.discriminator}`, | ||
icon_url: `https://cdn.discordapp.com/avatars/${interaction.member.user.id || interaction.user.id}/${interaction.member.user.avatar || interaction.user.avatar}.gif`, | ||
timestamp: Date.now() | ||
} | ||
}] | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* The link for inviting the bot | ||
* @param {client} client Discord.js client instance | ||
* @param {Object} request Express.js request payload | ||
* @param {response} response The response to send back | ||
* @returns {void} | ||
*/ | ||
module.exports = (client, request, response) => { | ||
response.send({ | ||
type: 4, | ||
data: { | ||
content: `https://discord.com/oauth2/authorize?client_id=${client.user.id}&scope=bot+applications.commands&permissions=338944` | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const Guild = require('../Models/Guild.js'); | ||
|
||
/** | ||
* Delete stickers in the specified channel(s) | ||
* @param {client} client Discord.js client instance | ||
* @param {Object} request Express.js request payload | ||
* @param {response} response The response to send back | ||
*/ | ||
module.exports = async (client, request, response) => { | ||
const interaction = request.body; | ||
const args = interaction.data.options; | ||
|
||
if (!interaction.guild_id) { | ||
response.send({ | ||
type: 4, | ||
data: { | ||
content: 'Unfortunately, this command cannot be used on direct messages. Try running `/invite` to invite me to your server.' | ||
} | ||
}); | ||
} | ||
|
||
if ((interaction.member.permissions & 8208) == 0) { | ||
response.send({ | ||
type: 4, | ||
data: { | ||
content: 'You do not have both the `MANAGE_CHANNELS` and the `MANAGE_MESSAGES` permissions.' | ||
} | ||
}); | ||
} | ||
|
||
if (interaction.data.resolved.channels[interaction.data.options[0].value].type !== 0) { | ||
response.send({ | ||
type: 4, | ||
data: { | ||
content: 'You need to input a valid server text channel.' | ||
} | ||
}); | ||
} | ||
|
||
await Guild.findOneAndUpdate( | ||
{ | ||
guildID: interaction.guild_id, | ||
}, | ||
{ | ||
$addToSet: { | ||
disableStickerUsage: { | ||
$each: args.find(option => option.name === 'channel').value, | ||
}, | ||
}, | ||
}, | ||
{ | ||
upsert: true, | ||
}, | ||
); | ||
|
||
response.send({ | ||
type: 4, | ||
data: { | ||
embeds: [{ | ||
description: 'Stickers will be deleted in the given channel(s).', | ||
color: [254, 251, 251] | ||
}] | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const fetch = require('node-fetch'); | ||
const Guild = require('../Models/Guild.js'); | ||
|
||
/** | ||
* Allows stickers in the specified channel(s) | ||
* @param {client} client Discord.js client instance | ||
* @param {Object} request Express.js request payload | ||
* @param {response} response The response to send back | ||
*/ | ||
module.exports = async (client, request, response) => { | ||
const interaction = request.body; | ||
const args = interaction.data.options; | ||
|
||
if (!interaction.guild_id) { | ||
response.send({ | ||
type: 4, | ||
data: { | ||
content: 'Unfortunately, this command cannot be used on direct messages. Try running `/invite` to invite me to your server.' | ||
} | ||
}); | ||
} | ||
|
||
if ((interaction.member.permissions & 8208) == 0) { | ||
response.send({ | ||
type: 4, | ||
data: { | ||
content: 'You do not have both the `MANAGE_CHANNELS` and the `MANAGE_MESSAGES` permissions.' | ||
} | ||
}); | ||
} | ||
|
||
if (interaction.data.resolved.channels[interaction.data.options[0].value].type !== 0) { | ||
response.send({ | ||
type: 4, | ||
data: { | ||
content: 'You need to input a valid server text channel.' | ||
} | ||
}); | ||
} | ||
|
||
await Guild.findOneAndUpdate( | ||
{ | ||
guildID: interaction.guild_id, | ||
}, | ||
{ | ||
$pullAll: { | ||
disableStickerUsage: args.find(option => option.name === 'channel').value, | ||
}, | ||
}, | ||
{ | ||
upsert: true, | ||
}, | ||
); | ||
|
||
response.send({ | ||
type: 4, | ||
data: { | ||
embeds: [{ | ||
description: 'Stickers will be allowed in the given channel(s).', | ||
color: [254, 251, 251] | ||
}] | ||
} | ||
}); | ||
|
||
setTimeout(() => { | ||
fetch(`https://discord.com/api/webhooks/${client.user.id}/${interaction.token}/messages/@original`, { | ||
method: 'DELETE', | ||
headers: { | ||
'Authorization': `Bot ${client.token ?? client.config.token}`, | ||
} | ||
}); | ||
}, 10000); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
module.exports = { | ||
module.exports = { | ||
publicKey: 'YOUR_APP_PUBLIC_KEY', | ||
prefix: 'YOUR_BOT_PREFIX', | ||
token: 'YOUR_BOT_TOKEN', | ||
mongoURL: ',YOUR_MONGODB_URL', | ||
ownerIDs: [ | ||
'YOUR_USER_ID' | ||
] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { verifyKeyMiddleware } = require('discord-interactions'); | ||
const server = require('express')(); | ||
const fs = require('fs'); | ||
|
||
const files = fs.readdirSync('./Interactions').filter(file => file.endsWith('.js')); | ||
|
||
module.exports = (client) => { | ||
server.post('/interactions', verifyKeyMiddleware(client.config.publicKey), (request, response) => { | ||
const interaction = request.body; | ||
|
||
if (interaction.type == 1) { | ||
response.send({ type: 1 }); | ||
} | ||
|
||
if (interaction.type == 2) { | ||
if (!files.has(interaction.data.name + '.js')) { | ||
response.send({ | ||
type: 4, | ||
data: { | ||
content: 'The invoked slash command could not be found.', | ||
flags: 64 | ||
} | ||
}); | ||
} | ||
require(`./interactions/${interaction.data.name + '.js'}`)(client, request, response); | ||
} | ||
}); | ||
|
||
server.listen(8000); | ||
}; |