Enable dev team dot commands

This commit is contained in:
Skylar Grant 2023-06-03 15:40:12 -04:00
parent 105fb2827f
commit a28957b956
8 changed files with 119 additions and 48 deletions

View File

@ -5,5 +5,10 @@
"treeHeight": 0,
"validCommands": [],
"rankMessageId": "",
"rankings": []
"rankings": [],
"devTeamIds": [
"481933290912350209",
"269249959973355520"
],
"ownerId": "481933290912350209"
}

View File

@ -4,7 +4,15 @@ module.exports = {
name: "",
description: "",
usage: "",
execute(message, commandData) {
// Code here...
permission: "devTeam", // "devTeam" or "owner"
async execute(message, commandData) {
if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) {
try {
// Code Here
} catch (err) {
console.error(err);
await message.reply(fn.builders.errorEmbed("There was an error running the command."));
}
}
}
}

View File

@ -4,37 +4,46 @@ module.exports = {
name: "message",
description: "Send a message to a server owner or server",
usage: ".message <serverID> <content>",
permission: "owner",
async execute(message, commandData) {
args = commandData.args.split(" ");
if (message.client.guildInfos.has(args[0])) {
let guildInfo = message.client.guildInfos.get(args[0]);
const guild = await message.client.guilds.fetch(args[0]).catch(async e => {
await message.reply("I was unable to fetch the guild.");
console.error(`Error fetching guild to send message: ${e}`);
});
const guildOwner = await message.client.users.fetch(guild.ownerId).catch(async e => {
await message.reply("I was unable to fetch the guild owner.");
console.error(`Error fetching guild owner to send message: ${e}`);
});
await guildOwner.createDM().then(async dm => {
await dm.send(args.join(" ")).catch(async e => {
await message.reply("I was unable to send the DM.");
console.error(`Error sending DM message: ${e}`);
});
}).catch(async e => {
await message.reply("I was unable to create the DM.");
console.error(`Error creating DM to send message: ${e}`);
const channel = await guild.channels.fetch(guildInfo.reminderChannelId).catch(async e => {
await message.reply("I was unable to fetch the channel.");
console.error(`Error fetching channel to send message: ${e}`);
});
await channel.send(args.join(" ")).catch(async e => {
await message.reply("I was unable to send the message.");
console.error(`Error sending message: ${e}`);
});
});
} else {
throw "Guild doesn't exist in database!";
if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) {
try {
// Code Here
args = commandData.args.split(" ");
if (message.client.guildInfos.has(args[0])) {
let guildInfo = message.client.guildInfos.get(args[0]);
const guild = await message.client.guilds.fetch(args[0]).catch(async e => {
await message.reply("I was unable to fetch the guild.");
console.error(`Error fetching guild to send message: ${e}`);
});
const guildOwner = await message.client.users.fetch(guild.ownerId).catch(async e => {
await message.reply("I was unable to fetch the guild owner.");
console.error(`Error fetching guild owner to send message: ${e}`);
});
await guildOwner.createDM().then(async dm => {
await dm.send(args.join(" ")).catch(async e => {
await message.reply("I was unable to send the DM.");
console.error(`Error sending DM message: ${e}`);
});
}).catch(async e => {
await message.reply("I was unable to create the DM.");
console.error(`Error creating DM to send message: ${e}`);
const channel = await guild.channels.fetch(guildInfo.reminderChannelId).catch(async e => {
await message.reply("I was unable to fetch the channel.");
console.error(`Error fetching channel to send message: ${e}`);
});
await channel.send(args.join(" ")).catch(async e => {
await message.reply("I was unable to send the message.");
console.error(`Error sending message: ${e}`);
});
});
} else {
throw "Guild doesn't exist in database!";
}
} catch (err) {
console.error(err);
await message.reply(fn.builders.errorEmbed("There was an error running the command."));
}
}
}
}

View File

@ -4,8 +4,15 @@ module.exports = {
name: "ping",
description: "pong",
usage: "ping pong",
permission: "devTeam",
async execute(message, commandData) {
// Code here...
await message.reply("Pong!");
if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) {
try {
await message.reply("Pong!");
} catch (err) {
console.error(err);
await message.reply(fn.builders.errorEmbed("There was an error running the command."));
}
}
}
}

View File

@ -4,14 +4,19 @@ module.exports = {
name: "servers",
description: "Get a list of servers the bot is in",
usage: ".servers",
permission: "owner",
async execute(message, commandData) {
let servers = [];
const count = JSON.stringify(message.client.guilds.cache.size);
servers.push("I'm currently in " + count + " servers.");
const guilds = await message.client.guilds.cache;
// await guilds.each(g => {
// servers.push(g.name + "," + g.ownerId);
// });
await message.reply(servers.join("\n"));
if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) {
try {
let servers = [];
const count = JSON.stringify(message.client.guilds.cache.size);
servers.push("I'm currently in " + count + " servers.");
const guilds = await message.client.guilds.cache;
await message.reply(servers.join("\n"));
} catch (err) {
console.error(err);
await message.reply(fn.builders.errorEmbed("There was an error running the command."));
}
}
}
}

24
dot-commands/setupview.js Normal file
View File

@ -0,0 +1,24 @@
const fn = require('../modules/functions.js');
module.exports = {
name: "setupview",
description: "",
usage: "",
permission: "devTeam",
async execute(message, commandData) {
// Code here...
if (fn.dotCommands.checkPermissions(this.permission, message.author.id)) {
try {
if (message.client.guildInfos.has(message.guildId)) {
let guildInfo = message.client.guildInfos.get(message.guildId);
await message.reply(fn.builders.embed(guildInfo.generateSetupInfo()));
} else {
await message.reply(fn.builders.errorEmbed("Guild doesn't exist in database!"));
}
} catch (err) {
console.error(err);
await message.reply(fn.builders.errorEmbed("There was an error running the command."));
}
}
}
}

View File

@ -111,7 +111,7 @@ client.on('messageCreate', async message => {
const commandData = fn.dotCommands.getCommandData(message);
// if (isDev) console.log(commandData);
if (commandData.isValid && commandData.isCommand && (message.author.id == process.env.ownerId)) {
if (commandData.isValid && commandData.isCommand) {
try {
client.dotCommands.get(commandData.command).execute(message, commandData);
}

View File

@ -247,9 +247,9 @@ const functions = {
}
commandData.isCommand = true;
// Get the first part of the message, everything leading up to the final period
commandData.args = message.content.slice(0,finalPeriod).toLowerCase();
commandData.args = message.content.slice(0, finalPeriod).toLowerCase();
// Get the last part of the message, everything after the final period
commandData.command = message.content.slice(finalPeriod).replace('.','').toLowerCase();
commandData.command = message.content.slice(finalPeriod).replace('.', '').toLowerCase();
commandData.author = `${message.author.username}#${message.author.discriminator}`;
return this.checkCommand(commandData);
},
@ -265,6 +265,19 @@ const functions = {
console.error('Somehow a non-command made it to checkCommands()');
}
return commandData;
},
checkPermissions(type, userId) {
if (type === "devTeam") {
const { devTeamIds } = config;
let matchFound = false;
for (let i = 0; i < devTeamIds.length; i++) {
if (userId === devTeamIds[i]) matchFound = true;
}
return matchFound;
} else if (type === "owner") {
return config.ownerId === userId;
}
}
},
rankings: {
@ -762,7 +775,7 @@ const functions = {
errorFlag = true;
status = strings.error.noTakeRole;
});
if(!errorFlag) status = strings.error.yesTakeRole;
if (!errorFlag) status = strings.error.yesTakeRole;
} else {
await functions.roles.giveRole(interaction.member, role).catch(e => {
errorFlag = true;
@ -824,7 +837,7 @@ const functions = {
// Make sure guildInfo is what we expect, the watch channel isnt blank, and notifications are enabled
if (guildInfo instanceof GuildInfo && guildInfo.watchChannelId != "" && guildInfo.notificationsEnabled) {
// Fetch the Guild
const guild = await client.guilds.fetch(guildInfo.guildId).catch(e => {throw "Attempted to fetch guild I'm no longer in."});
const guild = await client.guilds.fetch(guildInfo.guildId).catch(e => { throw "Attempted to fetch guild I'm no longer in." });
// Fetch the Channel
const channel = await guild.channels.fetch(guildInfo.watchChannelId);
// Create the filter function