Skip to content

Commit

Permalink
Various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo0111 committed Jan 13, 2024
1 parent f7e1ff1 commit 4a9f19b
Show file tree
Hide file tree
Showing 16 changed files with 924 additions and 805 deletions.
149 changes: 85 additions & 64 deletions commands/add.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,93 @@
const axios = require('axios').default;
const {PermissionFlagsBits, EmbedBuilder} = require('discord.js');
const Plugin = require('../database/Plugin');
const axios = require("axios").default;
const { PermissionFlagsBits, EmbedBuilder } = require("discord.js");
const Plugin = require("../database/Plugin");

module.exports = {
name: 'add',
executor: async (client,command) => {
if (!client.config.public) {
command.reply("This command is only available in public bots.");
return;
}
const plugin = command.options.getInteger('plugin') || 0;
const channel = command.options.getChannel('channel');
const ping = command.options.getRole('ping') || null;
name: "add",
executor: async (client, command) => {
if (!client.config.public) {
command.reply("This command is only available in public bots.");
return;
}
const plugin = command.options.getInteger("plugin") || 0;
const channel = command.options.getChannel("channel");
const ping = command.options.getRole("ping") || null;

await command.deferReply();

if (!command.member.permissions.has(PermissionFlagsBits.ManageWebhooks)) {
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
"<:severe:926091008645664848> You do not have the permission to manage webhooks."
)
.setColor("#ff9900"),
],
});
return;
}

await command.deferReply();
if (plugin === 0) {
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
"<:severe:926091008645664848> You must specify a plugin id."
)
.setColor("#ff9900"),
],
});
return;
}

if (!command.member.permissions.has(PermissionFlagsBits.ManageWebhooks)) {
command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<:severe:926091008645664848> You do not have the permission to manage webhooks.")
.setColor('#ff9900')]
});
return;
}
if (!channel) {
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
"<:severe:926091008645664848> You must specify a channel."
)
.setColor("#ff9900"),
],
});
return;
}

if (plugin === 0) {
command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<:severe:926091008645664848> You must specify a plugin id.")
.setColor('#ff9900')]
});
return;
}
try {
const { data } = await axios.get(
"https://api.spiget.org/v2/resources/" +
encodeURIComponent(plugin) +
"/updates/latest?size=1"
);
new Plugin({
id: plugin,
server: channel.guild.id,
channel: channel.id,
latest: data.id,
ping: ping != null ? ping.id : null,
}).save();

if (!channel) {
command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<:severe:926091008645664848> You must specify a channel.")
.setColor('#ff9900')]
});
return;
}
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle("<a:tick:983296047965151273> Plugin added successfully!")
.setColor("#ff9900"),
],
});

try {
const {data} = await axios.get("https://api.spiget.org/v2/resources/" + encodeURIComponent(plugin) + "/updates/latest?size=1");
new Plugin({
id: plugin,
server: channel.guild.id,
channel: channel.id,
latest: data.id,
ping: ping != null ? ping.id : null
}).save();

command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<a:tick:983296047965151273> Plugin added successfully!")
.setColor('#ff9900')]
});

client.pluginCount++;
return;
} catch (e) {
command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<:severe:926091008645664848> This plugin does not exist.")
.setColor('#ff9900')]
});
}

client.pluginCount++;
return;
} catch (e) {
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
"<:severe:926091008645664848> This plugin does not exist."
)
.setColor("#ff9900"),
],
});
}
}
},
};
179 changes: 104 additions & 75 deletions commands/addowner.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,119 @@
const axios = require('axios').default;
const {PermissionFlagsBits, EmbedBuilder} = require('discord.js');
const Plugin = require('../database/Plugin');
const axios = require("axios").default;
const { PermissionFlagsBits, EmbedBuilder } = require("discord.js");
const Plugin = require("../database/Plugin");

module.exports = {
name: 'addowner',
executor: async (client,command) => {
if (!client.config.public) {
command.reply("This command is only available in private bots.");
return;
}
const user = command.options.getInteger('user') || 0;
const channel = command.options.getChannel('channel');
const ping = command.options.getRole('ping') || null;
name: "addowner",
executor: async (client, command) => {
if (!client.config.public) {
command.reply("This command is only available in private bots.");
return;
}
const user = command.options.getInteger("user") || 0;
const channel = command.options.getChannel("channel");
const ping = command.options.getRole("ping") || null;

await command.deferReply();
await command.deferReply();

if (!command.member.permissions.has(PermissionFlagsBits.ManageWebhooks)) {
command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<:severe:926091008645664848> You do not have the permission to manage webhooks.")
.setColor('#ff9900')]
});
return;
}
if (!command.member.permissions.has(PermissionFlagsBits.ManageWebhooks)) {
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
"<:severe:926091008645664848> You do not have the permission to manage webhooks."
)
.setColor("#ff9900"),
],
});
return;
}

if (user === 0) {
command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<:severe:926091008645664848> You must specify a user id.")
.setColor('#ff9900')]
});
return;
}
if (user === 0) {
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
"<:severe:926091008645664848> You must specify a user id."
)
.setColor("#ff9900"),
],
});
return;
}

if (!channel) {
command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<:severe:926091008645664848> You must specify a channel.")
.setColor('#ff9900')]
});
return;
}
if (!channel) {
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
"<:severe:926091008645664848> You must specify a channel."
)
.setColor("#ff9900"),
],
});
return;
}

try {
const {data} = await axios.get("https://api.spiget.org/v2/authors/" + encodeURIComponent(user) + "/resources?size=100");
let added = 0;
try {
const { data } = await axios.get(
"https://api.spiget.org/v2/authors/" +
encodeURIComponent(user) +
"/resources?size=100"
);
let added = 0;

for (let index in data) {
const plugin = data[index];
const element = await Plugin.findOne({server:command.guild.id,id: plugin.id,channel:channel.id}).exec();
for (let index in data) {
const plugin = data[index];
const element = await Plugin.findOne({
server: command.guild.id,
id: plugin.id,
channel: channel.id,
}).exec();

if (!element) {
let updateId = null;
if (!element) {
let updateId = null;

try {
const {data: updateData} = await axios.get("https://api.spiget.org/v2/resources/" + encodeURIComponent(plugin.id) + "/updates/latest?size=1");
try {
const { data: updateData } = await axios.get(
"https://api.spiget.org/v2/resources/" +
encodeURIComponent(plugin.id) +
"/updates/latest?size=1"
);

updateId = updateData.id;
} catch (ignored) {}
updateId = updateData.id;
} catch (ignored) {}

new Plugin({
id: plugin.id,
server: channel.guild.id,
channel: channel.id,
latest: updateId,
ping: ping != null ? ping.id : null
}).save();
new Plugin({
id: plugin.id,
server: channel.guild.id,
channel: channel.id,
latest: updateId,
ping: ping != null ? ping.id : null,
}).save();

added++;
}
}

command.editReply({
embeds: [new EmbedBuilder()
.setTitle(`<a:tick:983296047965151273> Successfully added ${added} plugin(s) from the author requested!`)
.setColor('#ff9900')]
});
client.pluginCount += added;
return;
} catch (e) {
command.editReply({
embeds: [new EmbedBuilder()
.setTitle("<:severe:926091008645664848> This user does not exist.")
.setColor('#ff9900')]
});
added++;
}

}

command.editReply({
embeds: [
new EmbedBuilder()
.setTitle(
`<a:tick:983296047965151273> Successfully added ${added} plugin(s) from the author requested!`
)
.setColor("#ff9900"),
],
});
client.pluginCount += added;
return;
} catch (e) {
command.editReply({
embeds: [
new EmbedBuilder()
.setTitle("<:severe:926091008645664848> This user does not exist.")
.setColor("#ff9900"),
],
});
}
}
},
};
Loading

0 comments on commit 4a9f19b

Please sign in to comment.