begin work

This commit is contained in:
SowinskiBraeden committed 2022-12-06 20:25:59 -08:00
1 parent aed4f777be
commit d3264d4cfc
7 files changed
+2749 -19

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
const { ModalBuilder, ActionRowBuilder } = require('discord.js');
module.exports = {
name: "armbands",
debug: false,
global: false,
description: "view a list of armbads",
usage: "[cmd] [opts]",
permissions: {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: [],
},
options: [],
SlashCommand: {
/**
*
* @param {require("../structures/QuarksBot")} client
* @param {import("discord.js").Message} message
* @param {string[]} args
* @param {*} param3
*/
run: async (client, interaction, args) => {
},
},
Interactions: {
ViewArmbads: {
run: async (client, interaction) => {
}
}
}
}
+33
View File
@@ -0,0 +1,33 @@
const { ModalBuilder, ActionRowBuilder } = require('discord.js');
module.exports = {
name: "channels",
debug: false,
global: false,
description: "view a list of allowed channels",
usage: "[cmd] [opts]",
permissions: {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: [],
},
options: [],
SlashCommand: {
/**
*
* @param {require("../structures/QuarksBot")} client
* @param {import("discord.js").Message} message
* @param {string[]} args
* @param {*} param3
*/
run: async (client, interaction, args) => {
},
},
Interactions: {
ViewArmbads: {
run: async (client, interaction) => {
}
}
}
}
+54 -10
View File
@@ -1,19 +1,22 @@
const { TextInputBuilder, ModalBuilder, ActionRowBuilder, TextInputStyle } = require('discord.js'); const { ActionRowBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const bitfieldCalculator = require('discord-bitfield-calculator');
module.exports = { module.exports = {
name: "", name: "claim",
debug: false, debug: false,
global: false, global: false,
description: "", description: "claim an available armband for your ",
usage: "[cmd] [opts]", usage: "[cmd] [opts]",
permissions: { permissions: {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: [], member: [],
}, },
options: [ options: [{
name: "faction_role",
], description: "Claim an armband for this faction role.",
value: "faction_role",
type: 8,
required: true,
}],
SlashCommand: { SlashCommand: {
/** /**
* *
@@ -22,9 +25,50 @@ module.exports = {
* @param {string[]} args * @param {string[]} args
* @param {*} param3 * @param {*} param3
*/ */
run: async (client, interaction, args) => { run: async (client, interaction, args, GuildDB) => {
if (!interaction.member.roles.includes(args[0].value)) {
const invalidRoleEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription('**Notice:**\n> You cannot claim an armband for a role you don\'t have.');
return interaction.send({ embeds: [invalidRoleEmbed] });
}
// If this faction has an existing record in the db
if (GuildDB.factionArmbads[args[0].value]) {
const warnArmbadChange = new EmbedBuilder()
.setColor(client.config.Colors.Yellow)
.setDescription(`**Notice:**\n> The faction <@&${args[0].value}> already has an armband selected. Are you sure you would like to change this?`)
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`ChangeArmband-yes-${interaction.member.user.id}-${args[0].value}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId(`ChangeArmband-no-${interaction.member.user.id}-${args[0].value}`)
.setLabel("No")
.setStyle(ButtonStyle.Secondary)
)
return interaction.send({ embeds: [warnArmbadChange], components: [opt] });
}
return interaction.send({ content: 'debug' });
}, },
}, },
Interactions: {} Interactions: {
Claim: {
run: async (client, interaction, GuildDB) => {
}
},
ChangeArmband: {
run: async (client, interaction, GuildDB) => {
}
}
}
} }
+307
View File
@@ -0,0 +1,307 @@
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const bitfieldCalculator = require('discord-bitfield-calculator');
module.exports = {
name: "config",
debug: false,
global: false,
description: "Configure your server settings",
usage: "[opt] [action] [value]",
permissions: {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: ["MANAGE_GUILD"],
},
options: [
{
name: "allowed_channels",
description: "Set channels you're allowed to use the bot in",
value: "allowed_channels",
type: 2,
options: [
{
name: "add",
description: "Add channel",
value: "add",
type: 1,
options: [{
name: "channel",
description: "The channel to configure",
value: "channel",
type: 7,
channel_types: [0], // Restrict to text channel
required: true,
}]
},
{
name: "remove",
description: "Remove channel",
value: "remove",
type: 1,
options: [{
name: "channel",
description: "The channel to configure",
value: "channel",
type: 7,
channel_types: [0], // Restrict to text channel
required: true,
}]
},
]
},
{
name: "bot_admin_role",
description: "Set/remove bot admin role",
value: "bot_admin_role",
type: 2,
options: [
{
name: "set",
description: "Set role",
value: "role",
type: 1,
options: [{
name: "role",
description: "Role to set",
value: "role",
type: 8,
required: true,
}]
},
{
name: "remove",
description: "Remove role",
value: "remove",
type: 1,
},
]
},
{
name: "reset",
description: "Restore all settings to default configurations",
value: "reset",
type: 1,
},
{
name: "view",
description: "View current settings configuration",
value: "view",
type: 1,
}
],
SlashCommand: {
/**
*
* @param {require("../structures/QuarksBot")} client
* @param {import("discord.js").Message} message
* @param {string[]} args
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }) => {
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
let canUseCommand = false;
if (permissions.includes("MANAGE_GUILD")) canUseCommand = true;
if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) canUseCommand = true;
if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' });
if (args[0].name == 'allowed_channels') {
const channelid = args[0].options[0].options[0].value;
if (args[0].options[0].name == 'add') {
const channel = client.channels.cache.get(channelid);
const errorEmbed = new EmbedBuilder().setColor(client.config.Colors.Red)
let error = false;
if (!channel) {error=true;errorEmbed.setDescription(`**Error Notice:** Cannot find that channel.`);}
if (channel.type=="voice") {error=true;errorEmbed.setDescription(`**Error Notice:** Cannot add voice channel to allowed channels.`);}
if (error) return interaction.send({ embeds: [errorEmbed] });
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push:{"server.allowedChannels": channelid}}, function (err, res) {
if (err) return client.sendInternalError(interaction, err);
});
const successEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Green)
.setDescription(`**Success:** Set <#${channelid}> as an allowed channel.`);
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].options[0].name=='remove') {
const embed = new EmbedBuilder()
.setDescription(`**Error Notice:** <#${channelid}> is not in allowed channels.`)
.setColor(client.config.Colors.Red)
if (!GuildDB.allowedChannels.includes(channelid)) return interaction.send({ embeds: [embed] });
const prompt = new EmbedBuilder()
.setTitle(`Are you sure you want to remove this channel from allowed channels?`)
.setColor(client.config.Colors.Default)
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`RemoveAllowedChannels-yes-${interaction.member.user.id}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId(`RemoveAllowedChannels-no-${interaction.member.user.id}`)
.setLabel("No")
.setStyle(ButtonStyle.Success)
)
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
} else client.error('exception?');
} else if (args[0].name == 'bot_admin_role') {
if (args[0].options[0].name == 'set') {
const roleId = args[0].options[0].options[0].value;
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.botAdmin": roleId}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
const successEmbed = new EmbedBuilder()
.setDescription(`Successfully set <@&${roleId}> as a bot admin role.\nUsers with this role can use restricted commands.`)
.setColor(client.config.Colors.Green);
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].options[0].name== 'remove') {
const prompt = new EmbedBuilder()
.setTitle(`Are you sure you want to remove this role as a bot admin?`)
.setColor(client.config.Colors.Default)
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`RemoveBotAdminRole-yes-${interaction.member.user.id}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId(`RemoveBotAdminRole-no-${interaction.member.user.id}`)
.setLabel("No")
.setStyle(ButtonStyle.Success)
)
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
}
} else if (args[0].name == 'reset') {
const prompt = new EmbedBuilder()
.setTitle(`Woah!? Hold on.`)
.setDescruotion('Are you sure you wish to remove all your configurations for this guild?')
.setColor(client.config.Colors.Default)
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`ResetSettings-yes-${interaction.member.user.id}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId(`ResetSettings-no-${interaction.member.user.id}`)
.setLabel("No")
.setStyle(ButtonStyle.Success)
)
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
} else if (args[0].name == 'view') {
const channelsInfo = GuildDB.customChannelStatus ? '\n╚➤ \`/channels\` to view' : '';
const channelColor = GuildDB.customChannelStatus ? '+ ' : '- ';
const botAdminRole = GuildDB.botAdmin ? `\n╚➤ <@&${GuildDB.botAdmin}>` : '';
const botAdminRoleColor = GuildDB.botAdmin ? `+ ` : '- ';
const settingsEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Default)
.setTitle('Current Guild Configurations')
.addFields(
{ name: 'Guild ID', value: `\`\`\`arm\n${GuildDB.serverID}\`\`\``, inline: true },
{ name: 'Has Allowed Channels?', value: `\`\`\`diff\n${channelColor}${GuildDB.customChannelStatus}\`\`\`${channelsInfo}`, inline: true },
{ name: 'Has bot admin role?', value: `\`\`\`diff\n${botAdminRoleColor}${client.exists(GuildDB.botAdmin)}\`\`\`${botAdminRole}`, inline: true },
);
return interaction.send({ embeds: [settingsEmbed] });
}
},
},
Interactions: {
RemoveAllowedChannels: {
run: async (client, interaction, GuildDB) => {
if (!queryString.endsWith(interaction.member.user.id)) {
return ButtonInteraction.reply({
content: "This button is not for you",
flags: (1 << 6)
})
}
let action = ''
if (interaction.customId.split('-')[1]=='yes') {
action = 'removed';
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$pull:{"server.allowedChannels": channelid}}, function (err, res) {
if (err) return client.sendInternalError(interaction, err);
});
} else if (interaction.customId.split('-')[1]=='no') action = 'kept';
const successEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Green)
.setTitle(`Success: You ${action} the channel.`)
return interactino.update({ embeds: [successEmbed], components: [] });
}
},
RemoveBotAdminRole: {
run: async (client, interaction, GuildDB) => {
if (!interaction.customId.endsWith(interaction.member.user.id)) {
return ButtonInteraction.reply({
content: "This button is not for you",
flags: (1 << 6)
})
}
let action = '';
if (interaction.customId.split('-')[1]=='yes') {
action = 'removed';
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.botAdmin": null}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
} else if (interaction.customId.split('-')[1]=='no') action = 'kept';
const successEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Green)
.setTitle(`Successfully ${action} <@&${roleId}> as the bot admin role.`)
return interaction.update({ embeds: [successEmbed], components: [] });
}
},
ResetSettings: {
run: async (client, interaction, GuildDB) => {
if (!interaction.customId.endsWith(interaction.member.user.id)) {
return ButtonInteraction.reply({
content: "This button is not for you",
flags: (1 << 6)
})
}
let action = '';
if (interaction.customId.split('-')[1]=='yes') {
action = 'reset';
const defaultGuildConfig = client.getDefaultSettings(GuildDB.serverID);
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server": defaultGuildConfig}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err);
});
} else if (interaction.customId.split('-')[1]=='no') action = 'kept';
const successEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Green)
.setTitle(`Successfully ${action} guild configurations.`)
return interaction.update({ embeds: [successEmbed], components: [] });
}
}
}
}
+2313 -4
View File
File diff suppressed because it is too large. Load diff
+5 -1
View File
@@ -4,7 +4,10 @@
"description": "A Discord Bot to handle DayZ server flags and armbands for in game factions.", "description": "A Discord Bot to handle DayZ server flags and armbands for in game factions.",
"main": "index.js", "main": "index.js",
"nodemonConfig": { "nodemonConfig": {
"ignore": ["logs/*.log", "logs/*.json"] "ignore": [
"logs/*.log",
"logs/*.json"
]
}, },
"scripts": { "scripts": {
"start": "node index.js", "start": "node index.js",
@@ -19,6 +22,7 @@
"discord-bitfield-calculator": "^1.0.0", "discord-bitfield-calculator": "^1.0.0",
"discord.js": "^14.3.0", "discord.js": "^14.3.0",
"dotenv": "^16.0.2", "dotenv": "^16.0.2",
"mongodb": "^4.12.1",
"winston": "^3.8.1" "winston": "^3.8.1"
}, },
"devDependencies": { "devDependencies": {
+4 -4
View File
@@ -2,7 +2,6 @@ const { RegisterGlobalCommands, RegisterGuildCommands} = require("../util/Regist
const { Collection, Client, EmbedBuilder, Routes } = require('discord.js'); const { Collection, Client, EmbedBuilder, Routes } = require('discord.js');
const MongoClient = require('mongodb').MongoClient; const MongoClient = require('mongodb').MongoClient;
const { REST } = require('@discordjs/rest'); const { REST } = require('@discordjs/rest');
const mongoose = require('mongoose');
const Logger = require("../util/Logger"); const Logger = require("../util/Logger");
const path = require("path"); const path = require("path");
const fs = require('fs'); const fs = require('fs');
@@ -97,7 +96,6 @@ class DayzArmbands extends Client {
// Connect to Mongo database. // Connect to Mongo database.
this.db = await MongoClient.connect(mongoURI, {connectTimeoutMS: 1000}); this.db = await MongoClient.connect(mongoURI, {connectTimeoutMS: 1000});
this.dbo = this.db.db(dbo); this.dbo = this.db.db(dbo);
mongoose.connect(`${mongoURI}/${dbo}`);
this.log('Successfully connected to mongoDB'); this.log('Successfully connected to mongoDB');
databaselogs.connected = true; databaselogs.connected = true;
databaselogs.attempts = 0; // reset attempts databaselogs.attempts = 0; // reset attempts
@@ -195,7 +193,8 @@ class DayzArmbands extends Client {
return { return {
serverID: GuildId, serverID: GuildId,
allowedChannels: [], // list of channels the bot is allowed to be used in allowedChannels: [], // list of channels the bot is allowed to be used in
factionArmbands: [], // list of armbands in use factionArmbands: {},
usedArmbands: [],
botAdmin: null, // botAdmin: null, //
} }
} }
@@ -219,7 +218,8 @@ class DayzArmbands extends Client {
serverID: GuildId, serverID: GuildId,
customChannelStatus: guild.server.allowedChannels.length > 0 ? true : false, // not stored but calculated after customChannelStatus: guild.server.allowedChannels.length > 0 ? true : false, // not stored but calculated after
allowedChannels: guild.server.allowedChannels, allowedChannels: guild.server.allowedChannels,
factionArmbands: [], factionArmbands: guild.server.factionArmbands,
usedArmbands: guild.server.usedArmbands,
botAdmin: guild.server.botAdmin, botAdmin: guild.server.botAdmin,
}; };
} }