Code Optimization for all files
This commit is contained in:
parent
cb8a312d93
commit
85f2d8d04a
@ -1,43 +1,31 @@
|
|||||||
const {
|
const { EmbedBuilder } = require('discord.js');
|
||||||
EmbedBuilder
|
const giveMeAJoke = require('give-me-a-joke');
|
||||||
} = require('discord.js');
|
|
||||||
var giveMeAJoke = require('give-me-a-joke');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "joke",
|
name: "joke",
|
||||||
description: "Gets a funny joke",
|
description: "Gets a funny joke",
|
||||||
|
|
||||||
run: async (client, interaction) => {
|
async run(client, interaction) {
|
||||||
giveMeAJoke.getRandomDadJoke(function (joke) {
|
let joke = await giveMeAJoke.getRandomDadJoke();
|
||||||
|
|
||||||
if (joke.includes("?")){
|
if (joke.includes("?")){
|
||||||
let jokeData = joke.split("?")
|
let jokeData = joke.split("?");
|
||||||
const embed = new EmbedBuilder()
|
joke = `${jokeData[0]}?||${jokeData[1]}||`;
|
||||||
.setColor("#FF0000")
|
}
|
||||||
.setTitle("Here is your joke...")
|
|
||||||
.setDescription(jokeData[0] + "?||" + jokeData[1] + "||")
|
const embed = createJokeEmbed(joke, interaction.user);
|
||||||
.setTimestamp()
|
interaction.editReply({ embeds: [embed] });
|
||||||
.setFooter({
|
},
|
||||||
text: `Requested by ${interaction.user.tag}`,
|
};
|
||||||
iconURL: `${interaction.user.displayAvatarURL()}`
|
|
||||||
});
|
function createJokeEmbed(joke, user) {
|
||||||
interaction.editReply({
|
return new EmbedBuilder()
|
||||||
embeds: [embed]
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setColor("#FF0000")
|
.setColor("#FF0000")
|
||||||
.setTitle("Here is your joke...")
|
.setTitle("Here is your joke...")
|
||||||
.setDescription(joke)
|
.setDescription(joke)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: `Requested by ${interaction.user.tag}`,
|
text: `Requested by ${user.tag}`,
|
||||||
iconURL: `${interaction.user.displayAvatarURL()}`
|
iconURL: user.displayAvatarURL()
|
||||||
});
|
});
|
||||||
interaction.editReply({
|
}
|
||||||
embeds: [embed]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
@ -1,47 +1,40 @@
|
|||||||
const {
|
const { EmbedBuilder } = require('discord.js');
|
||||||
EmbedBuilder
|
const urban = require('urban');
|
||||||
} = require('discord.js');
|
|
||||||
var urban = require('urban')
|
|
||||||
const isNotDefined = require("is-not-defined");
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "urban",
|
name: "urban",
|
||||||
description: "Searches Urban Dictionary",
|
description: "Searches Urban Dictionary",
|
||||||
options: [{
|
options: [{
|
||||||
"name": "query",
|
name: "query",
|
||||||
"description": "The thing you want to search for",
|
description: "The thing you want to search for",
|
||||||
"required": true,
|
required: true,
|
||||||
"type": 3 // 6 is type USER
|
type: 3 // 6 is type USER
|
||||||
}],
|
}],
|
||||||
|
|
||||||
run: async (client, interaction) => {
|
async run(client, interaction) {
|
||||||
|
let searchWord = interaction.options._hoistedOptions[0].value;
|
||||||
|
let search = urban(searchWord);
|
||||||
|
|
||||||
let searchWord = interaction.options._hoistedOptions[0].value
|
let data = await search.first();
|
||||||
search = urban(searchWord);
|
|
||||||
|
|
||||||
search.first(function(data) {
|
if (data) {
|
||||||
|
const embed = createUrbanEmbed(data, searchWord, interaction.user);
|
||||||
if (!isNotDefined(data)) {
|
interaction.editReply({ embeds: [embed] });
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setColor("#FF0000")
|
|
||||||
.setTitle("Results for: " + searchWord)
|
|
||||||
.setDescription("Definition: " + data.definition)
|
|
||||||
.addFields({
|
|
||||||
name: 'Example',
|
|
||||||
value: data.example
|
|
||||||
})
|
|
||||||
.setTimestamp()
|
|
||||||
.setFooter({
|
|
||||||
text: `Requested by ${interaction.user.tag}`,
|
|
||||||
iconURL: `${interaction.user.displayAvatarURL()}`
|
|
||||||
});
|
|
||||||
interaction.editReply({
|
|
||||||
embeds: [embed]
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
return interaction.editReply("Sorry, no results were found!")
|
interaction.editReply("Sorry, no results were found!");
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createUrbanEmbed(data, searchWord, user) {
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setColor("#FF0000")
|
||||||
|
.setTitle(`Results for: ${searchWord}`)
|
||||||
|
.setDescription(`Definition: ${data.definition}`)
|
||||||
|
.addFields({ name: 'Example', value: data.example })
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter({
|
||||||
|
text: `Requested by ${user.tag}`,
|
||||||
|
iconURL: user.displayAvatarURL()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -4,49 +4,40 @@ module.exports = {
|
|||||||
name: "8ball",
|
name: "8ball",
|
||||||
description: "Ask a question, get a response.",
|
description: "Ask a question, get a response.",
|
||||||
options: [{
|
options: [{
|
||||||
"name": "question",
|
name: "question",
|
||||||
"description": "The question you would like to ask.",
|
description: "The question you would like to ask.",
|
||||||
"required": true,
|
required: true,
|
||||||
"type": 3 // 6 is type USER
|
type: 3 // 6 is type USER
|
||||||
}],
|
}],
|
||||||
run: async (client, interaction) => {
|
run: async (client, interaction) => {
|
||||||
let question = interaction.options._hoistedOptions[0].value
|
let question = interaction.options._hoistedOptions[0].value;
|
||||||
|
|
||||||
function send(question, message){
|
const responses = [
|
||||||
const embed = new EmbedBuilder()
|
"It is certain",
|
||||||
.setColor("#FF0000")
|
"It is decidedly so",
|
||||||
.setTitle(question)
|
"Reply hazy try again",
|
||||||
.setDescription(message)
|
"Cannot predict now",
|
||||||
.setTimestamp()
|
"Do not count on it",
|
||||||
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
"My sources say no",
|
||||||
|
"Outlook not so good",
|
||||||
|
"Signs point to yes"
|
||||||
|
];
|
||||||
|
|
||||||
|
const response = responses[Math.floor(Math.random() * responses.length)];
|
||||||
|
|
||||||
|
const embed = create8BallEmbed(question, response, interaction.user);
|
||||||
interaction.editReply({ embeds: [embed] });
|
interaction.editReply({ embeds: [embed] });
|
||||||
}
|
|
||||||
|
|
||||||
var answer = Math.floor(Math.random() * 8);
|
|
||||||
|
|
||||||
if (answer === 0) {
|
|
||||||
send(question, "it is certain")
|
|
||||||
}
|
|
||||||
else if (answer === 1) {
|
|
||||||
send(question, "It is decidedly so");
|
|
||||||
}
|
|
||||||
else if (answer === 2) {
|
|
||||||
send(question, "Reply hazy try again");
|
|
||||||
}
|
|
||||||
else if (answer === 3) {
|
|
||||||
send(question, "Cannot predict now");
|
|
||||||
}
|
|
||||||
else if (answer === 4) {
|
|
||||||
send(question, "Do not count on it");
|
|
||||||
}
|
|
||||||
else if (answer === 5) {
|
|
||||||
send(question, "My sources say no");
|
|
||||||
}
|
|
||||||
else if (answer === 6) {
|
|
||||||
send(question, "Outlook not so good");
|
|
||||||
}
|
|
||||||
else if (answer === 7) {
|
|
||||||
send(question, "Signs point to yes");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function create8BallEmbed(question, response, user) {
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setColor("#FF0000")
|
||||||
|
.setTitle(question)
|
||||||
|
.setDescription(response)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter({
|
||||||
|
text: `Requested by ${user.tag}`,
|
||||||
|
iconURL: user.displayAvatarURL()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -1,26 +1,31 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
var unirest = require('unirest');
|
const unirest = require('unirest');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "bored",
|
name: "bored",
|
||||||
description: "Find an activity to do when you are bored.",
|
description: "Find an activity to do when you are bored.",
|
||||||
|
|
||||||
run: async (client, interaction) => {
|
async run(client, interaction) {
|
||||||
|
let response = await unirest
|
||||||
unirest
|
|
||||||
.get('https://www.boredapi.com/api/activity')
|
.get('https://www.boredapi.com/api/activity')
|
||||||
.headers({
|
.headers({
|
||||||
'Accept': 'application/json', 'Content-Type': 'application/json',
|
'Accept': 'application/json', 'Content-Type': 'application/json',
|
||||||
})
|
});
|
||||||
.then((response) => {
|
|
||||||
let data = response.body
|
let data = response.body;
|
||||||
const embed = new EmbedBuilder()
|
const embed = createBoredEmbed(data, interaction.user);
|
||||||
|
interaction.followUp({ embeds: [embed] });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function createBoredEmbed(data, user) {
|
||||||
|
return new EmbedBuilder()
|
||||||
.setColor("#FF0000")
|
.setColor("#FF0000")
|
||||||
.setTitle("Here is something to do!")
|
.setTitle("Here is something to do!")
|
||||||
.setDescription(data.activity)
|
.setDescription(data.activity)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
.setFooter({
|
||||||
interaction.followUp({ embeds: [embed] });
|
text: `Requested by ${user.tag}`,
|
||||||
})
|
iconURL: user.displayAvatarURL()
|
||||||
},
|
});
|
||||||
};
|
}
|
||||||
|
@ -1,124 +1,82 @@
|
|||||||
const {
|
const { EmbedBuilder, AttachmentBuilder } = require('discord.js');
|
||||||
EmbedBuilder
|
const unirest = require('unirest');
|
||||||
} = require('discord.js');
|
const download = require('download-file');
|
||||||
const {
|
|
||||||
AttachmentBuilder
|
|
||||||
} = require('discord.js');
|
|
||||||
var download = require('download-file')
|
|
||||||
const notDefined = require("is-not-defined");
|
const notDefined = require("is-not-defined");
|
||||||
let phonetic
|
|
||||||
var unirest = require('unirest');
|
function createDictionaryEmbed(word, phonetic, meaningsArray, user) {
|
||||||
let meaningsArray = []
|
return new EmbedBuilder()
|
||||||
|
.setColor("#FF0000")
|
||||||
|
.setTitle(word + ": " + phonetic)
|
||||||
|
.addFields(meaningsArray)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter({
|
||||||
|
text: `Requested by ${user.tag}`,
|
||||||
|
iconURL: `${user.displayAvatarURL()}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "dictionary",
|
name: "dictionary",
|
||||||
description: "Returns information about a word",
|
description: "Returns information about a word",
|
||||||
options: [{
|
options: [{
|
||||||
"name": "word",
|
name: "word",
|
||||||
"description": "The data you would like inside of the QR",
|
description: "The data you would like inside of the QR",
|
||||||
"required": true,
|
required: true,
|
||||||
"type": 3 // 6 is type USER
|
type: 3 // 6 is type USER
|
||||||
}],
|
}],
|
||||||
run: async (client, interaction) => {
|
async run(client, interaction) {
|
||||||
let rand = Math.floor(Math.random() * 99999).toString();
|
let rand = Math.floor(Math.random() * 99999).toString();
|
||||||
let word = interaction.options._hoistedOptions[0].value
|
let word = interaction.options._hoistedOptions[0].value;
|
||||||
|
let meaningsArray = [];
|
||||||
|
|
||||||
unirest
|
let response = await unirest
|
||||||
.get('https://api.dictionaryapi.dev/api/v2/entries/en/' + word)
|
.get(`https://api.dictionaryapi.dev/api/v2/entries/en/${word}`)
|
||||||
.headers({
|
.headers({
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
})
|
});
|
||||||
.then((response) => {
|
|
||||||
let data = response.body[0]
|
let data = response.body[0];
|
||||||
if (notDefined(data)) {
|
if (notDefined(data)) {
|
||||||
return interaction.editReply("Sorry, nothing was found!")
|
return interaction.editReply("Sorry, nothing was found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notDefined(data.phonetics[1])) {
|
let phonetic = data.phonetics[1] ? data.phonetics[1].text : "";
|
||||||
phonetic = ""
|
let audio = data.phonetics[0].audio;
|
||||||
} else {
|
|
||||||
phonetic = data.phonetics[1].text
|
|
||||||
}
|
|
||||||
|
|
||||||
let audio = data.phonetics[0].audio
|
|
||||||
if (!audio) {
|
if (!audio) {
|
||||||
|
for (let wordData of data.meanings) {
|
||||||
data.meanings.forEach(wordData => {
|
let definition = wordData.definitions[0];
|
||||||
|
|
||||||
if (wordData.definitions[0].example) {
|
|
||||||
meaningsArray.push({
|
meaningsArray.push({
|
||||||
"name": wordData.partOfSpeech,
|
name: wordData.partOfSpeech,
|
||||||
"value": wordData.definitions[0].definition + "\nExample: " + wordData.definitions[0].example
|
value: `${definition.definition}\nExample: ${definition.example || ""}`
|
||||||
})
|
});
|
||||||
} else {
|
|
||||||
meaningsArray.push({
|
|
||||||
"name": wordData.partOfSpeech,
|
|
||||||
"value": wordData.definitions[0].definition
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
});
|
let embed = createDictionaryEmbed(word, phonetic, meaningsArray, interaction.user);
|
||||||
|
interaction.editReply({ embeds: [embed] });
|
||||||
const embed = new EmbedBuilder()
|
meaningsArray = [];
|
||||||
.setColor("#FF0000")
|
|
||||||
.setTitle(word + ": " + phonetic)
|
|
||||||
.addFields(meaningsArray)
|
|
||||||
.setTimestamp()
|
|
||||||
.setFooter({
|
|
||||||
text: `Requested by ${interaction.user.tag}`,
|
|
||||||
iconURL: `${interaction.user.displayAvatarURL()}`
|
|
||||||
});
|
|
||||||
interaction.editReply({
|
|
||||||
embeds: [embed]
|
|
||||||
});
|
|
||||||
meaningsArray = []
|
|
||||||
rand = Math.floor(Math.random() * 99999).toString();
|
rand = Math.floor(Math.random() * 99999).toString();
|
||||||
} else {
|
} else {
|
||||||
// Options for Audio Download
|
// Options for Audio Download
|
||||||
var options = {
|
let options = {
|
||||||
directory: "./audio/",
|
directory: "./audio/",
|
||||||
filename: rand + ".mp3"
|
filename: rand + ".mp3"
|
||||||
}
|
}
|
||||||
|
|
||||||
download(audio, options, function(err) {
|
download(audio, options, function(err) {
|
||||||
if (err) throw err
|
if (err) throw err;
|
||||||
console.log("audio downloaded")
|
for (let wordData of data.meanings) {
|
||||||
console.log(data.meanings)
|
let definition = wordData.definitions[0];
|
||||||
data.meanings.forEach(wordData => {
|
|
||||||
|
|
||||||
if (wordData.definitions[0].example) {
|
|
||||||
meaningsArray.push({
|
meaningsArray.push({
|
||||||
"name": wordData.partOfSpeech,
|
name: wordData.partOfSpeech,
|
||||||
"value": wordData.definitions[0].definition + "\nExample: " + wordData.definitions[0].example
|
value: `${definition.definition}\nExample: ${definition.example || ""}`
|
||||||
})
|
});
|
||||||
} else {
|
|
||||||
meaningsArray.push({
|
|
||||||
"name": wordData.partOfSpeech,
|
|
||||||
"value": wordData.definitions[0].definition
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
});
|
let file = new AttachmentBuilder(`./audio/${rand}.mp3`);
|
||||||
|
let embed = createDictionaryEmbed(word, phonetic, meaningsArray, interaction.user);
|
||||||
const file = new AttachmentBuilder('./audio/' + rand + ".mp3");
|
interaction.editReply({ files: [file], embeds: [embed] });
|
||||||
|
meaningsArray = [];
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setColor("#FF0000")
|
|
||||||
.setTitle(word + ": " + phonetic)
|
|
||||||
.addFields(meaningsArray)
|
|
||||||
.setTimestamp()
|
|
||||||
.setFooter({
|
|
||||||
text: `Requested by ${interaction.user.tag}`,
|
|
||||||
iconURL: `${interaction.user.displayAvatarURL()}`
|
|
||||||
});
|
|
||||||
interaction.editReply({
|
|
||||||
embeds: [embed],
|
|
||||||
files: [file]
|
|
||||||
});
|
|
||||||
meaningsArray = []
|
|
||||||
rand = Math.floor(Math.random() * 99999).toString();
|
rand = Math.floor(Math.random() * 99999).toString();
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
}
|
||||||
},
|
|
||||||
};
|
|
@ -1,33 +1,33 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
var generator = require('generate-password');
|
const generator = require('generate-password');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "password-generator",
|
name: "password-generator",
|
||||||
description: "Generates a random secure password",
|
description: "Generates a random secure password",
|
||||||
private: true,
|
private: true,
|
||||||
options: [{
|
options: [{
|
||||||
"name": "length",
|
name: "length",
|
||||||
"description": "Provide a number for how long to make the password.",
|
description: "Provide a number for how long to make the password.",
|
||||||
"required": true,
|
required: true,
|
||||||
"type": 3 // 6 is type USER
|
type: 3 // 6 is type USER
|
||||||
}],
|
}],
|
||||||
|
|
||||||
run: async (client, interaction) => {
|
run: async (client, interaction) => {
|
||||||
let length = interaction.options._hoistedOptions[0].value
|
const { value: length } = interaction.options._hoistedOptions[0];
|
||||||
|
const password = generator.generate({
|
||||||
var password = generator.generate({
|
length,
|
||||||
length: length,
|
|
||||||
numbers: true,
|
numbers: true,
|
||||||
symbols: true,
|
symbols: true,
|
||||||
excludeSimilarCharacters: true
|
excludeSimilarCharacters: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor("#FF0000")
|
.setColor("#FF0000")
|
||||||
.setTitle("Password Generated!")
|
.setTitle("Password Generated!")
|
||||||
.setDescription("Click to reveal: " + "||" + password + "||")
|
.setDescription(`Click to reveal: ||${password}||`)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
.setFooter({
|
||||||
|
text: `Requested by ${interaction.user.tag}`,
|
||||||
|
iconURL: `${interaction.user.displayAvatarURL()}`
|
||||||
|
});
|
||||||
interaction.editReply({ embeds: [embed] });
|
interaction.editReply({ embeds: [embed] });
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { MessageEmbed, Attachment, TextChannel } = require('discord.js');
|
||||||
const { AttachmentBuilder } = require('discord.js');
|
|
||||||
const { AwesomeQR } = require("awesome-qr");
|
const { AwesomeQR } = require("awesome-qr");
|
||||||
const fs = require("fs");
|
const fs = require("fs").promises;
|
||||||
|
|
||||||
|
let fileName;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "qr",
|
name: "qr",
|
||||||
@ -14,32 +15,36 @@ module.exports = {
|
|||||||
}],
|
}],
|
||||||
|
|
||||||
run: async (client, interaction) => {
|
run: async (client, interaction) => {
|
||||||
|
if (!fileName) {
|
||||||
|
fileName = Math.floor(Math.random() * 99999).toString();
|
||||||
|
}
|
||||||
|
|
||||||
(async () => {
|
const text = interaction.options._hoistedOptions[0].value;
|
||||||
let rand = Math.floor(Math.random() * 99999).toString();
|
const background = Buffer.from(fs.readFileSync("Terminal-icon.png"));
|
||||||
let text = interaction.options._hoistedOptions[0].value
|
|
||||||
|
|
||||||
const background = fs.readFileSync("Terminal-icon.png");
|
|
||||||
|
|
||||||
const buffer = await new AwesomeQR({
|
const buffer = await new AwesomeQR({
|
||||||
text: text,
|
text: text,
|
||||||
size: 500,
|
size: 500,
|
||||||
backgroundImage: background,
|
backgroundImage: background,
|
||||||
|
|
||||||
}).draw();
|
}).draw();
|
||||||
|
|
||||||
fs.writeFileSync("./images/" + rand + ".png", buffer);
|
await fs.writeFile(`./images/${fileName}.png`, buffer);
|
||||||
const file = new AttachmentBuilder('./images/' + rand + ".png");
|
const file = new Attachment(`./images/${fileName}.png`);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new MessageEmbed()
|
||||||
.setColor("#FF0000")
|
.setColor("#FF0000")
|
||||||
.setTitle("Your Generated QR Code")
|
.setTitle("Your Generated QR Code")
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setImage('attachment://images/' + rand + ".png")
|
.setImage(`attachment://images/${fileName}.png`)
|
||||||
|
|
||||||
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
||||||
interaction.editReply({ embeds: [embed], files: [file] });
|
try {
|
||||||
})();
|
const message = await interaction.channel.send({ embeds: [embed], files: [file] });
|
||||||
|
setTimeout(async () => {
|
||||||
|
// await message.delete();
|
||||||
|
console.log(message)
|
||||||
|
await fs.unlink(`./images/${fileName}.png`);
|
||||||
|
}, 10000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const { EmbedBuilder } = require('discord.js');
|
const { EmbedBuilder } = require('discord.js');
|
||||||
const fs = require('fs');
|
const fs = require('fs').promises;
|
||||||
const { exec } = require("child_process");
|
const { spawn } = require("child_process");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "short-url",
|
name: "short-url",
|
||||||
@ -13,43 +13,50 @@ module.exports = {
|
|||||||
}],
|
}],
|
||||||
run: async (client, interaction) => {
|
run: async (client, interaction) => {
|
||||||
let rand = Math.floor(Math.random() * 99999).toString();
|
let rand = Math.floor(Math.random() * 99999).toString();
|
||||||
let URL = interaction.options._hoistedOptions[0].value
|
let URL = interaction.options._hoistedOptions[0].value;
|
||||||
var dir = '/var/www/html/short/' + rand;
|
var dir = '/var/www/html/short/' + rand;
|
||||||
|
|
||||||
const content = "<?php\nheader(\"Location: " + URL + "\")\n?>";
|
const content = "<?php\nheader(\"Location: " + URL + "\")\n?>";
|
||||||
|
|
||||||
console.log(content)
|
console.log(content);
|
||||||
|
|
||||||
if (!fs.existsSync(dir)) {
|
|
||||||
fs.mkdirSync(dir);
|
|
||||||
console.log("Created: " + '/var/www/html/short/' + rand)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync('/var/www/html/short/' + rand + "/index.php", content);
|
const stats = await fs.stat(dir);
|
||||||
// file written successfully
|
if (!stats.isDirectory()) {
|
||||||
exec("chown -R www-data:www-data /var/www/html/short/", (error, stdout, stderr) => {
|
throw new Error(`${dir} is not a directory`);
|
||||||
if (error) {
|
|
||||||
console.log(`error: ${error.message}`);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (stderr) {
|
} catch (error) {
|
||||||
console.log(`stderr: ${stderr}`);
|
if (error.code === 'ENOENT') {
|
||||||
return;
|
console.log(`${dir} does not exist`);
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
await fs.mkdir(dir);
|
||||||
|
console.log(`Created: ${dir}`);
|
||||||
|
await fs.writeFile(`${dir}/index.php`, content);
|
||||||
|
console.log(`Wrote ${dir}/index.php`);
|
||||||
|
|
||||||
|
const chown = spawn("chown", ["-R", "www-data:www-data", `/var/www/html/short/${rand}`]);
|
||||||
|
chown.on("exit", (code) => {
|
||||||
|
console.error(`chown exited with code ${code}`);
|
||||||
|
});
|
||||||
|
chown.stdout.on("data", (data) => {
|
||||||
|
console.log(`chown stdout: ${data}`);
|
||||||
|
});
|
||||||
|
chown.stderr.on("data", (data) => {
|
||||||
|
console.error(`chown stderr: ${data}`);
|
||||||
|
});
|
||||||
|
chown.on("error", (error) => {
|
||||||
|
console.error(`chown error: ${error.message}`);
|
||||||
|
});
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor("#FF0000")
|
.setColor("#FF0000")
|
||||||
.setTitle("The URL has been shrunk!")
|
.setTitle("The URL has been shrunk!")
|
||||||
.setDescription("https://short.ssh.surf/" + rand)
|
.setDescription(`https://short.ssh.surf/${rand}`)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
|
||||||
interaction.followUp({ embeds: [embed] });
|
interaction.followUp({ embeds: [embed] });
|
||||||
rand = Math.floor(Math.random() * 99999).toString();
|
rand = Math.floor(Math.random() * 99999).toString();
|
||||||
});
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,63 +1,35 @@
|
|||||||
const client = require("../index");
|
const client = require("../index");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const { glob } = require("glob");
|
const fs = require("fs").promises;
|
||||||
const { promisify } = require("util");
|
|
||||||
const globPromise = promisify(glob);
|
|
||||||
|
|
||||||
client.on("interactionCreate", async (interaction) => {
|
client.on("interactionCreate", async (interaction) => {
|
||||||
|
|
||||||
// Slash Commands
|
// Slash Commands
|
||||||
const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`);
|
const slashCommands = await fs.readdir(`${process.cwd()}/commands/*/*.js`);
|
||||||
const arrayOfSlashCommands = [];
|
const arrayOfSlashCommands = slashCommands.map((filename) => {
|
||||||
slashCommands.map((value) => {
|
const file = require(`${process.cwd()}/commands/${filename}`);
|
||||||
const file = require(value);
|
|
||||||
const splitted = value.split("/");
|
|
||||||
const directory = splitted[splitted.length - 2];
|
|
||||||
|
|
||||||
if (!file?.name) return;
|
if (!file?.name) return;
|
||||||
|
|
||||||
const properties = { directory, ...file };
|
|
||||||
client.slashCommands.set(file.name, properties);
|
|
||||||
|
|
||||||
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
|
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
|
||||||
arrayOfSlashCommands.push(file);
|
return file;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Slash Command Handling
|
// Slash Command Handling
|
||||||
if (interaction.isChatInputCommand()) {
|
if (interaction.isChatInputCommand()) {
|
||||||
|
const commandData = arrayOfSlashCommands.find(
|
||||||
let commandData = []
|
(command) => command.name === interaction.commandName
|
||||||
await arrayOfSlashCommands.forEach(command => {
|
);
|
||||||
console.log(command.name)
|
if (!commandData) return;
|
||||||
if (command.name == interaction.commandName) {
|
|
||||||
commandData.push(command)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let dataToProcess = JSON.stringify(commandData[0])
|
|
||||||
let parsedData = JSON.parse(dataToProcess)
|
|
||||||
|
|
||||||
if (parsedData.private == true) {
|
|
||||||
await interaction.deferReply({ ephemeral: true }).catch(() => { });
|
|
||||||
|
|
||||||
} else {
|
|
||||||
await interaction.deferReply({ ephemeral: false }).catch(() => { });
|
|
||||||
}
|
|
||||||
|
|
||||||
const cmd = client.slashCommands.get(interaction.commandName);
|
const cmd = client.slashCommands.get(interaction.commandName);
|
||||||
if (!cmd)
|
if (!cmd) return interaction.followUp({ content: "An error has occurred " });
|
||||||
return interaction.followUp({ content: "An error has occurred " });
|
|
||||||
|
|
||||||
const args = [];
|
const args = interaction.options.data.map((option) => {
|
||||||
|
|
||||||
for (let option of interaction.options.data) {
|
|
||||||
if (option.type === "SUB_COMMAND") {
|
if (option.type === "SUB_COMMAND") {
|
||||||
if (option.name) args.push(option.name);
|
if (option.name) return option.name;
|
||||||
option.options?.forEach((x) => {
|
return option.options?.map((x) => x.value).filter((x) => x);
|
||||||
if (x.value) args.push(x.value);
|
|
||||||
});
|
|
||||||
} else if (option.value) args.push(option.value);
|
|
||||||
}
|
}
|
||||||
|
return option.value;
|
||||||
|
});
|
||||||
|
|
||||||
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
|
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
|
||||||
|
|
||||||
cmd.run(client, interaction, args);
|
cmd.run(client, interaction, args);
|
||||||
@ -69,5 +41,4 @@ client.on("interactionCreate", async (interaction) => {
|
|||||||
const command = client.slashCommands.get(interaction.commandName);
|
const command = client.slashCommands.get(interaction.commandName);
|
||||||
if (command) command.run(client, interaction);
|
if (command) command.run(client, interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,38 +1,60 @@
|
|||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const { glob } = require("glob");
|
const fs = require("fs").promises;
|
||||||
const { promisify } = require("util");
|
|
||||||
const globPromise = promisify(glob);
|
|
||||||
|
|
||||||
module.exports = async (client) => {
|
module.exports = async (client) => {
|
||||||
// Slash Commands
|
// Slash Commands
|
||||||
const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`);
|
const slashCommands = await fs.readdir(`${process.cwd()}/commands/*/*.js`);
|
||||||
const arrayOfSlashCommands = [];
|
const arrayOfSlashCommands = slashCommands.map((filename) => {
|
||||||
slashCommands.map((value) => {
|
const file = require(`${process.cwd()}/commands/${filename}`);
|
||||||
const file = require(value);
|
|
||||||
const splitted = value.split("/");
|
|
||||||
const directory = splitted[splitted.length - 2];
|
|
||||||
|
|
||||||
if (!file?.name) return;
|
if (!file?.name) return;
|
||||||
|
|
||||||
const properties = { directory, ...file };
|
|
||||||
client.slashCommands.set(file.name, properties);
|
|
||||||
|
|
||||||
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
|
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
|
||||||
arrayOfSlashCommands.push(file);
|
return file;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
const eventFiles = await globPromise(`${process.cwd()}/events/*.js`);
|
const eventFiles = await fs.readdir(`${process.cwd()}/events/*.js`);
|
||||||
eventFiles.map((value) => require(value));
|
eventFiles.forEach((filename) => require(`${process.cwd()}/events/${filename}`));
|
||||||
|
|
||||||
// Slash Commands Register
|
// Slash Commands Register
|
||||||
client.on("ready", async () => {
|
client.on("ready", async () => {
|
||||||
// // Register for a single guild
|
|
||||||
// await client.guilds.cache.get("GUIDIDHERE").commands.set(arrayOfSlashCommands);
|
|
||||||
|
|
||||||
console.log(arrayOfSlashCommands)
|
|
||||||
// Register for all the guilds the bot is in
|
// Register for all the guilds the bot is in
|
||||||
await client.application.commands.set(arrayOfSlashCommands);
|
await client.application.commands.set(arrayOfSlashCommands);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
client.on("interactionCreate", async (interaction) => {
|
||||||
|
// Slash Command Handling
|
||||||
|
if (interaction.isChatInputCommand()) {
|
||||||
|
let commandData = arrayOfSlashCommands.find((command) => command.name === interaction.commandName);
|
||||||
|
if (!commandData) return interaction.followUp({ content: "An error has occurred " });
|
||||||
|
const cmd = client.slashCommands.get(interaction.commandName);
|
||||||
|
if (!cmd) return interaction.followUp({ content: "An error has occurred " });
|
||||||
|
|
||||||
|
const args = [];
|
||||||
|
for (let option of interaction.options.data) {
|
||||||
|
if (option.type === "SUB_COMMAND") {
|
||||||
|
if (option.name) args.push(option.name);
|
||||||
|
option.options?.forEach((x) => {
|
||||||
|
if (x.value) args.push(x.value);
|
||||||
|
});
|
||||||
|
} else if (option.value) args.push(option.value);
|
||||||
|
}
|
||||||
|
interaction.member = interaction.guild.members.cache.get(interaction.user.id);
|
||||||
|
|
||||||
|
if (commandData.private) {
|
||||||
|
await interaction.deferReply({ ephemeral: true }).catch(() => { });
|
||||||
|
} else {
|
||||||
|
await interaction.deferReply({ ephemeral: false }).catch(() => { });
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.run(client, interaction, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Context Menu Handling
|
||||||
|
if (interaction.isContextMenuCommand()) {
|
||||||
|
await interaction.deferReply({ ephemeral: false });
|
||||||
|
const command = client.slashCommands.get(interaction.commandName);
|
||||||
|
if (command) command.run(client, interaction);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user