fix formatting

This commit is contained in:
Jelle van Snik 2022-05-30 16:51:47 +02:00
parent ff5e87cf4a
commit 103ee3f00d
13 changed files with 215 additions and 214 deletions

View file

@ -9,7 +9,7 @@ const modalSubmitHandler = require('./events/modalSubmit');
const config = require('../config.json');
if (!config.guild_id) {
throw new Error("No guild id set in config, exiting");
throw new Error('No guild id set in config, exiting');
}
const client = new Discord.Client({

View file

@ -4,25 +4,25 @@ const { guild_id } = require('../../config.json');
const { SlashCommandBuilder } = require('@discordjs/builders');
const editableOptions = [
"mod-applications.channel.log",
"report.channel.log",
"joinmsg.channels.readme",
"joinmsg.channels.rules",
"stats.channels.members",
"stats.channels.people",
"stats.channels.bots",
]
'mod-applications.channel.log',
'report.channel.log',
'joinmsg.channels.readme',
'joinmsg.channels.rules',
'stats.channels.members',
'stats.channels.people',
'stats.channels.bots',
];
async function isValidkey(interaction) {
const key = interaction.options.getString("key");
if (!editableOptions.includes(key)) {
await interaction.reply({
content: "Cannot edit this setting - not a valid setting",
ephemeral: true,
})
return false;
}
return true;
const key = interaction.options.getString('key');
if (!editableOptions.includes(key)) {
await interaction.reply({
content: 'Cannot edit this setting - not a valid setting',
ephemeral: true,
});
return false;
}
return true;
}
/**
@ -30,55 +30,56 @@ async function isValidkey(interaction) {
* @param {Discord.CommandInteraction} interaction
*/
async function settingsHandler(interaction) {
if (interaction.guildId !== guild_id) {
await interaction.reply({
content: "Cannot edit this setting - this guild is not whitelisted",
ephemeral: true,
})
return;
}
if (interaction.guildId !== guild_id) {
await interaction.reply({
content: 'Cannot edit this setting - this guild is not whitelisted',
ephemeral: true,
});
return;
}
const key = interaction.options.getString("key");
if (interaction.options.getSubcommand() === "get") {
if (!await isValidkey(interaction))
return;
// this is hellish string concatenation, I know
await interaction.reply({
content: "```\n" + key + "=" + '"' + `${db.getDB().get(key)}` +'"' + "\n```",
ephemeral: true,
allowedMentions: {
parse: [], // dont allow tagging anything
}
})
return;
}
const key = interaction.options.getString('key');
if (interaction.options.getSubcommand() === 'get') {
if (!(await isValidkey(interaction))) return;
// this is hellish string concatenation, I know
await interaction.reply({
content:
'```\n' + key + '=' + '\'' + `${db.getDB().get(key)}` + '\'' + '\n```',
ephemeral: true,
allowedMentions: {
parse: [], // dont allow tagging anything
},
});
return;
}
if (interaction.options.getSubcommand() === "set") {
if (!await isValidkey(interaction))
return;
db.getDB().set(key, interaction.options.getString("value"))
await interaction.reply({
content: `setting \`${key}\` has been saved successfully`,
ephemeral: true,
allowedMentions: {
parse: [], // dont allow tagging anything
}
})
return;
}
if (interaction.options.getSubcommand() === 'set') {
if (!(await isValidkey(interaction))) return;
db.getDB().set(key, interaction.options.getString('value'));
await interaction.reply({
content: `setting \`${key}\` has been saved successfully`,
ephemeral: true,
allowedMentions: {
parse: [], // dont allow tagging anything
},
});
return;
}
if (interaction.options.getSubcommand() === "which") {
await interaction.reply({
content: `**possible settings**:\n${editableOptions.map(v=>`\`${v}\``).join("\n")}`,
ephemeral: true,
allowedMentions: {
parse: [], // dont allow tagging anything
}
})
return;
}
if (interaction.options.getSubcommand() === 'which') {
await interaction.reply({
content: `**possible settings**:\n${editableOptions
.map((v) => `\`${v}\``)
.join('\n')}`,
ephemeral: true,
allowedMentions: {
parse: [], // dont allow tagging anything
},
});
return;
}
throw new Error("unhandled subcommand");
throw new Error('unhandled subcommand');
}
const command = new SlashCommandBuilder();
@ -86,43 +87,43 @@ const command = new SlashCommandBuilder();
command.setDefaultPermission(false);
command.setName('settings');
command.setDescription('Setup the bot');
command.addSubcommand(cmd => {
cmd.setName("set");
cmd.setDescription("Change a settings key");
cmd.addStringOption(option => {
option.setName('key');
option.setDescription('Key to modify');
option.setRequired(true);
return option;
});
cmd.addStringOption(option => {
option.setName('value');
option.setDescription('value to set the setting to');
option.setRequired(true);
return option;
});
return cmd;
})
command.addSubcommand(cmd => {
cmd.setName("get");
cmd.setDescription("Get value of settings key");
cmd.addStringOption(option => {
option.setName('key');
option.setDescription('Key to modify');
option.setRequired(true);
return option;
});
return cmd;
})
command.addSubcommand(cmd => {
cmd.setName("which");
cmd.setDescription("which settings are valid?");
return cmd;
})
command.addSubcommand((cmd) => {
cmd.setName('set');
cmd.setDescription('Change a settings key');
cmd.addStringOption((option) => {
option.setName('key');
option.setDescription('Key to modify');
option.setRequired(true);
return option;
});
cmd.addStringOption((option) => {
option.setName('value');
option.setDescription('value to set the setting to');
option.setRequired(true);
return option;
});
return cmd;
});
command.addSubcommand((cmd) => {
cmd.setName('get');
cmd.setDescription('Get value of settings key');
cmd.addStringOption((option) => {
option.setName('key');
option.setDescription('Key to modify');
option.setRequired(true);
return option;
});
return cmd;
});
command.addSubcommand((cmd) => {
cmd.setName('which');
cmd.setDescription('which settings are valid?');
return cmd;
});
module.exports = {
name: command.name,
help: 'Change settings of the bot',
handler: settingsHandler,
deploy: command.toJSON()
deploy: command.toJSON(),
};

View file

@ -2,9 +2,9 @@ const Discord = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const allowedSelfAssignRoles = [
"streamping",
"updates"
]
'streamping',
'updates'
];
/**
*
@ -21,14 +21,14 @@ async function toggleroleHandler(interaction) {
const roles = await guild.roles.fetch();
const role = roles.find(role => role.name.toLowerCase() === roleName);
if (!allowedSelfAssignRoles.includes(roleName)) {
await interaction.followUp({
content: "Requested role is not self-assignable.",
ephemeral: true,
});
if (!allowedSelfAssignRoles.includes(roleName)) {
await interaction.followUp({
content: 'Requested role is not self-assignable.',
ephemeral: true,
});
return;
}
return;
}
if (!role) {
await interaction.followUp({
@ -73,7 +73,7 @@ module.exports = {
help: 'Toggle on/off a given user role.\n```\nUsage: /togglerole <role>\n```',
handler: toggleroleHandler,
deploy: command.toJSON(),
extra: {
allowedSelfAssignRoles
}
extra: {
allowedSelfAssignRoles,
},
};

View file

@ -9,7 +9,7 @@ const { modal: reportUserModal } = require('../../modals/report-user');
* @param {Discord.ContextMenuInteraction} interaction
*/
async function reportUserHandler(interaction) {
// TODO report user should also be an command, context menus are not available on mobile
// TODO report user should also be an command, context menus are not available on mobile
const { targetId } = interaction;
if (targetId === interaction.user.id) {

View file

@ -1,11 +1,11 @@
const JSONdb = require('simple-json-db');
const path = require('path');
const db = new JSONdb(path.join(__dirname, "../db.json"));
const db = new JSONdb(path.join(__dirname, '../db.json'));
function getDB() {
return db;
return db;
}
module.exports = {
getDB
getDB
};

View file

@ -9,26 +9,26 @@ const db = require('../db');
async function guildMemberAddHandler(member) {
const guild = member.guild;
const channels = await guild.channels.fetch();
const readmeChannel = channels.find(channel => channel.id === db.getDB().get("joinmsg.channels.readme"));
const rulesChannel = channels.find(channel => channel.id === db.getDB().get("joinmsg.channels.rules"));
const readmeChannel = channels.find(channel => channel.id === db.getDB().get('joinmsg.channels.readme'));
const rulesChannel = channels.find(channel => channel.id === db.getDB().get('joinmsg.channels.rules'));
if (readmeChannel && rulesChannel) {
const welcomeEmbed = new Discord.MessageEmbed();
welcomeEmbed.setColor(0x1B1F3B);
welcomeEmbed.setTitle('Welcome to Pretendo Network :tada:');
welcomeEmbed.setURL('https://pretendo.network');
welcomeEmbed.setDescription(`**Thank you for joining the Pretendo Network Discord server! Be sure to refer to the <#${readmeChannel.id}> and <#${rulesChannel.id}> channels for detailed information about the server**\n\n_**Links**_:\nWebsite - https://pretendo.network\nGitHub - https://github.com/PretendoNetwork\nPatreon - https://patreon.com/PretendoNetwork\nTwitter - https://twitter.com/PretendoNetwork\nTwitch - https://twitch.tv/PretendoNetwork\nYouTube - https://youtube.com/c/PretendoNetwork`);
welcomeEmbed.setThumbnail('https://i.imgur.com/8clyKqx.png');
welcomeEmbed.setImage('https://i.imgur.com/CF7qgW1.png');
// caught because user could have dm's disabled
try {
await member.send({
embeds: [welcomeEmbed],
});
} catch {}
}
if (readmeChannel && rulesChannel) {
const welcomeEmbed = new Discord.MessageEmbed();
welcomeEmbed.setColor(0x1B1F3B);
welcomeEmbed.setTitle('Welcome to Pretendo Network :tada:');
welcomeEmbed.setURL('https://pretendo.network');
welcomeEmbed.setDescription(`**Thank you for joining the Pretendo Network Discord server! Be sure to refer to the <#${readmeChannel.id}> and <#${rulesChannel.id}> channels for detailed information about the server**\n\n_**Links**_:\nWebsite - https://pretendo.network\nGitHub - https://github.com/PretendoNetwork\nPatreon - https://patreon.com/PretendoNetwork\nTwitter - https://twitter.com/PretendoNetwork\nTwitch - https://twitch.tv/PretendoNetwork\nYouTube - https://youtube.com/c/PretendoNetwork`);
welcomeEmbed.setThumbnail('https://i.imgur.com/8clyKqx.png');
welcomeEmbed.setImage('https://i.imgur.com/CF7qgW1.png');
// caught because user could have dm's disabled
try {
await member.send({
embeds: [welcomeEmbed],
});
} catch {}
}
await util.updateMemberCountChannels(member.guild);
}

View file

@ -19,11 +19,11 @@ async function modalSubmitHandler(interaction) {
}
// run the modal
try {
await modal.handler(interaction);
} catch {
console.error("handler failed modal");
}
try {
await modal.handler(interaction);
} catch {
console.error('handler failed modal');
}
}
module.exports = modalSubmitHandler;

View file

@ -14,16 +14,16 @@ async function readyHandler(client) {
loadBotHandlersCollection('modals', client.modals);
loadBotHandlersCollection('select-menus', client.selectMenus);
// deploy commands globally
await deployCommands(client);
console.log(`Registered global commands`);
// deploy commands globally
await deployCommands(client);
console.log('Registered global commands');
// setup joined guilds
// setup joined guilds
const guilds = await client.guilds.fetch();
for (let guild of guilds) {
guild = await guild[1].fetch();
await setupGuild(guild);
console.log(`setup guild: ${guild.name}`);
console.log(`setup guild: ${guild.name}`);
}
console.log(`Logged in as ${client.user.tag}`);

View file

@ -60,15 +60,15 @@ async function modApplicationHandler(interaction) {
const guild = await interaction.guild.fetch();
const channels = await guild.channels.fetch();
const channel = channels.find(channel => channel.id === db.getDB().get("mod-applications.channel.log"));
const channel = channels.find(channel => channel.id === db.getDB().get('mod-applications.channel.log'));
if (!channel) {
await interaction.editReply({
content: 'application failed to submit - channel not setup!',
ephemeral: true
});
return;
}
if (!channel) {
await interaction.editReply({
content: 'application failed to submit - channel not setup!',
ephemeral: true
});
return;
}
const modApplicationEmbed = new Discord.MessageEmbed();

View file

@ -44,15 +44,15 @@ async function reportUserHandler(interaction) {
}
const channels = await interaction.guild.channels.fetch();
const reportsChannel = channels.find(channel => channel.id === db.getDB().get("report.channel.log"));
const reportsChannel = channels.find(channel => channel.id === db.getDB().get('report.channel.log'));
if (!reportsChannel) {
await interaction.editReply({
content: 'Report failed to submit - channel not setup',
ephemeral: true
});
return;
}
if (!reportsChannel) {
await interaction.editReply({
content: 'Report failed to submit - channel not setup',
ephemeral: true
});
return;
}
const reportEmbed = new Discord.MessageEmbed();

View file

@ -1,5 +1,5 @@
const Discord = require('discord.js');
const { allowedSelfAssignRoles } = require("../commands/togglerole").extra;
const { allowedSelfAssignRoles } = require('../commands/togglerole').extra;
const roleSelectMenu = new Discord.MessageSelectMenu();
roleSelectMenu.setCustomId('role-self-assign');
@ -33,14 +33,14 @@ async function roleSelfAssignHandler(interaction) {
const roles = await guild.roles.fetch();
const role = roles.find(role => role.name.toLowerCase() === roleName);
if (!allowedSelfAssignRoles.includes(roleName)) {
await interaction.followUp({
content: "Requested role is not self-assignable.",
ephemeral: true,
});
if (!allowedSelfAssignRoles.includes(roleName)) {
await interaction.followUp({
content: 'Requested role is not self-assignable.',
ephemeral: true,
});
return;
}
return;
}
if (!role) {
await interaction.followUp({

View file

@ -1,29 +1,29 @@
const Discord = require("discord.js");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v10");
const util = require("./util");
const { bot_token: botToken, application_id: applicationId } = require("../config.json");
const rest = new REST({ version: "10" }).setToken(botToken);
const Discord = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10');
const util = require('./util');
const { bot_token: botToken, application_id: applicationId } = require('../config.json');
const rest = new REST({ version: '10' }).setToken(botToken);
/**
*
* @param {Discord.Guild} guild
*/
async function setupGuild(guild) {
// do nothing if the bot does not have the correct permissions
if (!guild.me.permissions.has([Discord.Permissions.FLAGS.MANAGE_CHANNELS])) {
console.log("Bot does not have permissions to set up in guild", guild.name);
return;
}
// do nothing if the bot does not have the correct permissions
if (!guild.me.permissions.has([Discord.Permissions.FLAGS.MANAGE_CHANNELS])) {
console.log('Bot does not have permissions to set up in guild', guild.name);
return;
}
// Setup commands
await deployCommandsToGuild(guild);
try {
await util.updateMemberCountChannels(guild);
} catch {
// we dont care if it fails on setup, itll sync again on join
}
// Setup commands
await deployCommandsToGuild(guild);
try {
await util.updateMemberCountChannels(guild);
} catch {
// we dont care if it fails on setup, itll sync again on join
}
}
/**
@ -31,39 +31,39 @@ async function setupGuild(guild) {
* @param {Discord.Guild} guild
*/
async function deployCommandsToGuild(guild) {
const deploy = [];
const deploy = [];
guild.client.commands.forEach((command) => {
deploy.push(command.deploy);
});
guild.client.commands.forEach((command) => {
deploy.push(command.deploy);
});
guild.client.contextMenus.forEach((contextMenu) => {
deploy.push(contextMenu.deploy);
});
guild.client.contextMenus.forEach((contextMenu) => {
deploy.push(contextMenu.deploy);
});
await rest.put(Routes.applicationGuildCommands(guild.me.id, guild.id), {
body: deploy,
});
await rest.put(Routes.applicationGuildCommands(guild.me.id, guild.id), {
body: deploy,
});
}
async function deployCommands(client) {
const deploy = [];
const deploy = [];
client.commands.forEach((command) => {
deploy.push(command.deploy);
});
client.commands.forEach((command) => {
deploy.push(command.deploy);
});
client.contextMenus.forEach((contextMenu) => {
deploy.push(contextMenu.deploy);
});
client.contextMenus.forEach((contextMenu) => {
deploy.push(contextMenu.deploy);
});
await rest.put(Routes.applicationCommands(applicationId), {
body: deploy,
});
await rest.put(Routes.applicationCommands(applicationId), {
body: deploy,
});
}
module.exports = {
setupGuild,
deployCommands,
setupGuild,
deployCommands,
};

View file

@ -6,13 +6,13 @@ const db = require('./db');
* @param {Discord.Guild} guild
*/
async function updateMemberCountChannels(guild) {
// TODO this should really done on interval, a bot raid will ratelimit the bot so it cant take any more actions for a while
// (this is on global ratelimit iirc)
// TODO this should really done on interval, a bot raid will ratelimit the bot so it cant take any more actions for a while
// (this is on global ratelimit iirc)
const channels = await guild.channels.fetch();
const membersChannel = channels.find(channel => channel.id === db.getDB().get("stats.channels.members"));
const peopleChannel = channels.find(channel => channel.id === db.getDB().get("stats.channels.people"));
const botsChannel = channels.find(channel => channel.id === db.getDB().get("stats.channels.bots"));
const membersChannel = channels.find(channel => channel.id === db.getDB().get('stats.channels.members'));
const peopleChannel = channels.find(channel => channel.id === db.getDB().get('stats.channels.people'));
const botsChannel = channels.find(channel => channel.id === db.getDB().get('stats.channels.bots'));
const members = await guild.members.fetch();
const membersCount = guild.memberCount;
@ -28,7 +28,7 @@ async function updateMemberCountChannels(guild) {
}
});
if (membersChannel) await membersChannel.setName(`Members - ${membersCount}`);
if (membersChannel) await membersChannel.setName(`Members - ${membersCount}`);
if (peopleChannel) await peopleChannel.setName(`People - ${peopleCount}`);
if (botsChannel) await botsChannel.setName(`Bots - ${botsCount}`);
}