initial commit - base code
This commit is contained in:
15 files changed
+2257
No files matched your search
+13
@@ -0,0 +1,13 @@
|
|||||||
|
# Node modules
|
||||||
|
node_modules/*
|
||||||
|
|
||||||
|
# Testing/dev related
|
||||||
|
*_test.js
|
||||||
|
dev-*.js
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs/*
|
||||||
|
npm-debug.log
|
||||||
|
|
||||||
|
#env
|
||||||
|
.env
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder } = require("discord.js");
|
||||||
|
const settings = require('../config/settingsHelp');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "help",
|
||||||
|
debug: false,
|
||||||
|
global: true,
|
||||||
|
description: "Get information on a specific command",
|
||||||
|
usage: "[option]",
|
||||||
|
permissions: {
|
||||||
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||||
|
member: [],
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "commands",
|
||||||
|
description: "List all commands",
|
||||||
|
value: "commands",
|
||||||
|
type: 1,
|
||||||
|
options: [{
|
||||||
|
name: "command",
|
||||||
|
description: "Get information on a specific command",
|
||||||
|
value: "command",
|
||||||
|
type: 3,
|
||||||
|
required: false,
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "support",
|
||||||
|
description: "Get support for Applicatz",
|
||||||
|
value: "support",
|
||||||
|
type: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "credits",
|
||||||
|
description: "Applicantz Credits",
|
||||||
|
value: "credits",
|
||||||
|
type: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "version",
|
||||||
|
description: "Current version of the bot",
|
||||||
|
value: "version",
|
||||||
|
type: 1,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
SlashCommand: {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {require("../structures/QuarksBot")} client
|
||||||
|
* @param {import("discord.js").Message} message
|
||||||
|
* @param {string[]} args
|
||||||
|
* @param {*} param3
|
||||||
|
*/
|
||||||
|
|
||||||
|
run: async (client, interaction, args) => {
|
||||||
|
if (args[0].name == 'version') {
|
||||||
|
const versionEmbed = new EmbedBuilder()
|
||||||
|
.setTitle(`Current Applicantz Version`)
|
||||||
|
.setDescription(client.config.Version);
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [versionEmbed] });
|
||||||
|
} else if (args[0].name == 'commands') {
|
||||||
|
let Commands = client.commands.filter((cmd) => {
|
||||||
|
return !cmd.debug
|
||||||
|
}).map((cmd) =>
|
||||||
|
`\`/${cmd.name}${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}`
|
||||||
|
);
|
||||||
|
|
||||||
|
let Embed = new EmbedBuilder()
|
||||||
|
.setTitle('Commands')
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setDescription(`${Commands.join("\n")}
|
||||||
|
|
||||||
|
Applicantz Version: v${client.config.Version}`);
|
||||||
|
if (!args[0].options[0]) return interaction.send({ embeds: [Embed] });
|
||||||
|
else {
|
||||||
|
let cmd =
|
||||||
|
client.commands.get(args[0].options[0].value) ||
|
||||||
|
client.commands.find(
|
||||||
|
(x) => x.aliases && x.aliases.includes(args[0].options[0].value)
|
||||||
|
);
|
||||||
|
if (!cmd)
|
||||||
|
return client.sendError(
|
||||||
|
interaction,
|
||||||
|
`❌ | Unable to find that command.`
|
||||||
|
);
|
||||||
|
|
||||||
|
let embed = new EmbedBuilder()
|
||||||
|
.setDescription(cmd.description)
|
||||||
|
.setColor(client.config.Colors.Green)
|
||||||
|
.setTitle(`How to use /${cmd.name} command`)
|
||||||
|
|
||||||
|
if (cmd.SlashCommand.options && cmd.SlashCommand.options[0].type == 1) {
|
||||||
|
let description = `${cmd.description}\n\n**Usage**\n`;
|
||||||
|
|
||||||
|
for (let i = 0; i < cmd.SlashCommand.options.length; i++) {
|
||||||
|
if (cmd.SlashCommand.options[i].type == 1) {
|
||||||
|
let param = '';
|
||||||
|
if (cmd.SlashCommand.options[i].options) {
|
||||||
|
param = cmd.SlashCommand.options[i].options.length > 0 ? ' ' : '';
|
||||||
|
for (let j = 0; j < cmd.SlashCommand.options[i].options.length; j++) {
|
||||||
|
if (cmd.SlashCommand.options[i].options[j].required) param += `[${cmd.SlashCommand.options[i].options[j].name}] `
|
||||||
|
}
|
||||||
|
}
|
||||||
|
description += `\`/${cmd.name} ${cmd.SlashCommand.options[i].name}${param}\`\n${cmd.SlashCommand.options[i].description}\n\n`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
embed.setDescription(description);
|
||||||
|
} else embed.addFields({ name: "Usage", value: `\`/${cmd.name}\`${cmd.usage ? " " + cmd.usage : ""}`, inline: true })
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
} else if (args[0].name == 'support') {
|
||||||
|
const supportEmbed = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setDescription(`**__Applicantz Support__**
|
||||||
|
|
||||||
|
Are you experiencing troubles with Applicantz?
|
||||||
|
Do you have questions or concerns?
|
||||||
|
Do you require help to use the bot?
|
||||||
|
Do you have a feature you'd like to see?
|
||||||
|
|
||||||
|
Join the support server to have all your needs fulfilled.
|
||||||
|
╚➤ ${client.config.SupportServer}
|
||||||
|
`)
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [supportEmbed] });
|
||||||
|
|
||||||
|
} else if (args[0].name == 'credits') {
|
||||||
|
const creditsEmbed = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setTitle('QuarksBot Credits')
|
||||||
|
.setDescription(`
|
||||||
|
**Bot Author:** McDazzzled#5307
|
||||||
|
|
||||||
|
${client.config.SupportServer}
|
||||||
|
`);
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [creditsEmbed] })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "ping",
|
||||||
|
debug: true,
|
||||||
|
global: true,
|
||||||
|
description: "Test bot activity",
|
||||||
|
usage: "",
|
||||||
|
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, start) => {
|
||||||
|
const end = new Date().getTime();
|
||||||
|
const pingEmbed = new EmbedBuilder()
|
||||||
|
.setDescription(`🏓 **Pong!** Bot ping: ${end - start}ms`)
|
||||||
|
.setColor(client.config.Colors.Default);
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [pingEmbed] });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
const { EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: "stats",
|
||||||
|
debug: true,
|
||||||
|
global: true,
|
||||||
|
description: "check bot statistics",
|
||||||
|
usage: "",
|
||||||
|
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, start) => {
|
||||||
|
const end = new Date().getTime();
|
||||||
|
const stats = new EmbedBuilder()
|
||||||
|
.setColor(client.config.Colors.Default)
|
||||||
|
.setTitle('QuarksBot Statistics')
|
||||||
|
.addFields(
|
||||||
|
{ name: 'Guilds', value: `${client.guilds.cache.size}`, inline: true },
|
||||||
|
{ name: 'Users', value: `${client.users.cache.size}`, inline: true },
|
||||||
|
{ name: 'Latency', value: `${end - start}ms`, inline: true },
|
||||||
|
{ name: 'Uptime', value: `${client.secondsToDhms(process.uptime().toFixed(2))}`, inline: true },
|
||||||
|
{ name: 'Bot Version', value: `${client.config.Dev} v${client.config.Version}`, inline: true },
|
||||||
|
{ name: 'Discord Version', value: 'Discord.js v14.3.0', inline: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
return interaction.send({ embeds: [stats] })
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
const package = require('../package.json');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Dev: "PROD.",
|
||||||
|
Version: package.version, // (major).(feature).(revision/bug/refactoring)
|
||||||
|
Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot
|
||||||
|
ServerID: "",
|
||||||
|
SupportServer: "", //Support Server Link
|
||||||
|
Token: process.env.token || "", //Discord Bot Token
|
||||||
|
Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes
|
||||||
|
IconURL: "",
|
||||||
|
Colors: {
|
||||||
|
Default: "#6e5145",
|
||||||
|
Red: "#ba0f0f",
|
||||||
|
Green: "#32a852",
|
||||||
|
Yellow: "#ffb01f"
|
||||||
|
},
|
||||||
|
Permissions: 2205281600,
|
||||||
|
mongoURI: process.env.mongoURI || "mongodb://localhost:27017",
|
||||||
|
dbo: process.env.dbo || "knoldus",
|
||||||
|
Presence: {
|
||||||
|
status: "online", // You can show online, idle, and dnd
|
||||||
|
name: "Grand Theft Auto V", // The message shown
|
||||||
|
type: "PLAYING", // PLAYING, WATCHING, LISTENING, STREAMING
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
module.exports = {
|
||||||
|
settings: [
|
||||||
|
{
|
||||||
|
name: "allowed_channels",
|
||||||
|
description: `
|
||||||
|
If you wish to limit users to use the bot in some channels, you can configure \`allowed_channels\`. To do so, use \`/config allowed_channels add <your channel>\` to add a channel to a list of allowed channels.
|
||||||
|
|
||||||
|
To remove a channel, use \`/config allowed_channel remove <your channel>\`.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "action_channel",
|
||||||
|
description: `
|
||||||
|
To save the hastle of cluttered channels, you can configure a dedicated channel for the \`/action\` command. To do so, use \`/config action_channel set <channel>\`. This will send any output for the \`/action\` command to this channel.
|
||||||
|
|
||||||
|
To remove this configuration, use \`/config action_channel remove\`
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tweet_channel",
|
||||||
|
description: `
|
||||||
|
To save the hastle of cluttered channels, you can configure a dedicated channel for the \`/tweet\` command. To do so, use \`/config tweet_channel set <channel>\`. This will send any output for the \`/tweet\` command to this channel.
|
||||||
|
|
||||||
|
To remove this configuration, use \`/config tweet_channel remove\`
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "adverts_channel",
|
||||||
|
description: `
|
||||||
|
Users with the configured commercial role can create advertisements for their commercial business. To keep your channels clean, you can limit the output of this command to a dedicated channel. To do so, use \`/config adverts_channel set <channel>\`. This will send any adverts to this channel.
|
||||||
|
|
||||||
|
To remove this configuration, use \`/config adverts_channel remove\`.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "dispatcher_channel",
|
||||||
|
description: `
|
||||||
|
In order for the \`/311\` or \`/911\` commands to be used, you need to configure two settings. \`dispatcher_channel\` is one of the settings to configure. This will redirect all \`/311\` or \`/911\` reports to a dedicated channel. Use \`/config dispatcher_channel set <channel>\` to configure this setting.
|
||||||
|
|
||||||
|
To remove this configuration, use \`/config dispatcher_channel remove\`.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "starting_balance",
|
||||||
|
description: `
|
||||||
|
New users in your guild receive $1000.00 as their starting balance. This can be configured, use \`/config starting_balance <amount>\`. This can be a floating point number, e.g 150.40
|
||||||
|
|
||||||
|
floating point number: a number value with a decimal.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "income_role",
|
||||||
|
description: `
|
||||||
|
Users can work once a day to earn money, but this will require a role with a set daily income. To configure a new income role, use \`/config income_role set <role> <daily income>\`.
|
||||||
|
|
||||||
|
Users with one of these configured roles can use the \`/work\` command once a day to earn their set daily income.
|
||||||
|
|
||||||
|
Note: If a user has more than one role to earn income, using the \`/work\` command will earn them the highest income from one of the roles they have.
|
||||||
|
|
||||||
|
To remove one of the configured roles, use \`/config income_roles remove <role>\`.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bot_admin_role",
|
||||||
|
description: `
|
||||||
|
Some commands are limited to users who can manage the guild (Admin privilages), but if you wish for users without admin privilages to access commands such as \`/config\` \`/money\` or \`/reset\`. You can configure a bot admin role.
|
||||||
|
|
||||||
|
Use \`/config bot_admin_role set <role>\` to configure the bot admin role.
|
||||||
|
|
||||||
|
To remove this configuration, use \`/config bot_admin_role remove\`.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "commercial_role",
|
||||||
|
description: `
|
||||||
|
Users with the commercial_role have access to business related commands, to configure this role to give to some users, use \`/config commercial_role set <role>\`.
|
||||||
|
|
||||||
|
To remove this configured role, use \`/config commercial_role remove\`.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "officer_role",
|
||||||
|
description: `
|
||||||
|
The \`/fine\` command requires a user to have a configured officer role. To configure this role, use \`/config officer_role set <role>\`
|
||||||
|
|
||||||
|
To remove this configured role, use \`/config officer_role remove\`.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "dispatcher_role",
|
||||||
|
description: `
|
||||||
|
In order for the \`/311\` or \`/911\` commands to be used, you need to configure two settings. \`dispatcher_role\` is one of the settings to configure. This will allow users to interact with all \`/311\` or \`/911\` reports. Use \`/config dispatcher_role set <role>\` to configure this setting.
|
||||||
|
|
||||||
|
To remove this configuration, use \`/config dispatcher_role remove\`.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "only_officers_search",
|
||||||
|
description: `
|
||||||
|
The \`/search\` command allows users to view other users inventories. If you wish to limit this command, you can do so by configuring \`only_officers_search\`. Use \`/config only_officers_search <true/false>\`. This will optionally limit the \`/search\` command to users with the configured officer role.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "can_dismiss_invoices",
|
||||||
|
description: `
|
||||||
|
This configurations allows users who have been given an invoice to \`Dismiss & Delete\` an invoice they choose rather than pay. This can be set to false, so users must pay their invoice.\n\n**Note:** Invoices are paid from a users bank balance, and not with their cash balance.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "view",
|
||||||
|
description: `
|
||||||
|
There is a lot of settings you can configure. To view a all configured settings, use the following: \`/config view\`. This will display all configured settings, and their values if configured.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "reset",
|
||||||
|
description:`
|
||||||
|
This will reset all configurations back to default settings, clearing all set roles and channels.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "casino_multiplier",
|
||||||
|
description: `
|
||||||
|
This configurations allows you to customize the multiplier used to determine the winnings from casino games.
|
||||||
|
`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "work_limiter",
|
||||||
|
description: `
|
||||||
|
This configuration allows you to alter the number of hours a user has to wait between the use of the \`/work\` command. By default, users need to wait **24** hours before the can use the \`/work\` command again.
|
||||||
|
`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (client, guild) => {
|
||||||
|
require("../util/RegisterSlashCommands").RegisterGuildCommands(client, guild.id);
|
||||||
|
};
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
module.exports = async (client, interaction) => {
|
||||||
|
if (interaction.isCommand()) return;
|
||||||
|
/*
|
||||||
|
This file handles all menu and button interactions
|
||||||
|
from any command
|
||||||
|
*/
|
||||||
|
|
||||||
|
let GuildDB = await client.GetGuild(interaction.guildId);
|
||||||
|
const interactionName = interaction.customId.split("-")[0];
|
||||||
|
let interactionHandler = client.interactionHandlers.get(interactionName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
interactionHandler.run(client, interaction, GuildDB);
|
||||||
|
} catch (err) {
|
||||||
|
client.sendInternalError(interaction, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
module.exports = async (client) => {
|
||||||
|
(client.Ready = true),
|
||||||
|
client.user.setActivity(
|
||||||
|
client.config.Presence.name,
|
||||||
|
client.config.Presence.type
|
||||||
|
);
|
||||||
|
client.log(`Successfully Logged in as ${client.user.tag}`);
|
||||||
|
client.log(`Ready to serve in ${client.channels.cache.size} channels on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users.`)
|
||||||
|
client.RegisterSlashCommands();
|
||||||
|
};
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const Applicantz = require('./structures/Applicantz');
|
||||||
|
const config = require('./config/config');
|
||||||
|
const { GatewayIntentBits } = require('discord.js');
|
||||||
|
|
||||||
|
let client = new Applicantz({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] }, config);
|
||||||
|
client.build()
|
||||||
Generated
+1545
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "applicantz",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Application Handler for Discord",
|
||||||
|
"main": "index.js",
|
||||||
|
"nodemonConfig": {
|
||||||
|
"ignore": ["logs/*.log", "logs/*.json"]
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
|
"dev": "node dev-index.js",
|
||||||
|
"debug": "nodemon dev-index.js"
|
||||||
|
},
|
||||||
|
"author": "Braeden Sowinski",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@discordjs/rest": "^1.1.0",
|
||||||
|
"colors": "^1.4.0",
|
||||||
|
"discord-bitfield-calculator": "^1.0.0",
|
||||||
|
"discord.js": "^14.3.0",
|
||||||
|
"dotenv": "^16.0.2",
|
||||||
|
"winston": "^3.8.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.20"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
const { RegisterGlobalCommands, RegisterGuildCommands} = require("../util/RegisterSlashCommands");
|
||||||
|
const { Collection, Client, EmbedBuilder, Routes } = require('discord.js');
|
||||||
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
|
const { REST } = require('@discordjs/rest');
|
||||||
|
const mongoose = require('mongoose');
|
||||||
|
const Logger = require("../util/Logger");
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
class Applicantz extends Client {
|
||||||
|
|
||||||
|
constructor(options, config) {
|
||||||
|
super(options)
|
||||||
|
|
||||||
|
this.config = config;
|
||||||
|
this.commands = new Collection();
|
||||||
|
this.interactionHandlers = new Collection();
|
||||||
|
this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log"));
|
||||||
|
|
||||||
|
if (this.config.Token === "")
|
||||||
|
throw new TypeError(
|
||||||
|
"The config.js is not filled out. Please make sure nothing is blank, otherwise the bot will not work properly."
|
||||||
|
);
|
||||||
|
|
||||||
|
this.LoadCommandsAndInteractionHandlers();
|
||||||
|
this.LoadEvents();
|
||||||
|
|
||||||
|
this.Ready = false;
|
||||||
|
|
||||||
|
this.ws.on("INTERACTION_CREATE", async (interaction) => {
|
||||||
|
const start = new Date().getTime();
|
||||||
|
if (interaction.type!=3) {
|
||||||
|
|
||||||
|
const command = interaction.data.name.toLowerCase();
|
||||||
|
const args = interaction.data.options;
|
||||||
|
|
||||||
|
client.log(`Interaction - ${command}`);
|
||||||
|
|
||||||
|
interaction.guild = await this.guilds.fetch(interaction.guild_id);
|
||||||
|
interaction.send = async (message) => {
|
||||||
|
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||||
|
|
||||||
|
return await rest.post(Routes.interactionCallback(interaction.id, interaction.token), {
|
||||||
|
body: {
|
||||||
|
type: 4,
|
||||||
|
data: message,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
let cmd = client.commands.get(command);
|
||||||
|
try {
|
||||||
|
cmd.SlashCommand.run(this, interaction, args, start); // start is only used in ping / stats command
|
||||||
|
} catch (err) {
|
||||||
|
this.sendInternalError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const client = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
exists(n) {return null != n && undefined != n && "" != n}
|
||||||
|
|
||||||
|
secondsToDhms(seconds) {
|
||||||
|
seconds = Number(seconds);
|
||||||
|
const d = Math.floor(seconds / (3600*24));
|
||||||
|
const h = Math.floor(seconds % (3600*24) / 3600);
|
||||||
|
const m = Math.floor(seconds % 3600 / 60);
|
||||||
|
const s = Math.floor(seconds % 60);
|
||||||
|
|
||||||
|
const dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
|
||||||
|
const hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
|
||||||
|
const mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
|
||||||
|
const sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
|
||||||
|
return dDisplay + hDisplay + mDisplay + sDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadCommandsAndInteractionHandlers() {
|
||||||
|
let CommandsDir = path.join(__dirname, '..', 'commands');
|
||||||
|
fs.readdir(CommandsDir, (err, files) => {
|
||||||
|
if (err) this.error(err);
|
||||||
|
else
|
||||||
|
files.forEach((file) => {
|
||||||
|
let cmd = require(CommandsDir + "/" + file);
|
||||||
|
if (!this.exists(cmd.name) || !this.exists(cmd.description))
|
||||||
|
return this.error(
|
||||||
|
"Unable to load Command: " +
|
||||||
|
file.split(".")[0] +
|
||||||
|
", Reason: File doesn't had name/desciption"
|
||||||
|
);
|
||||||
|
this.commands.set(file.split(".")[0].toLowerCase(), cmd);
|
||||||
|
if (this.exists(cmd.Interactions)) {
|
||||||
|
for (let [interaction, handler] of Object.entries(cmd.Interactions)) {
|
||||||
|
this.interactionHandlers.set(interaction, handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.log("Command Loaded: " + file.split(".")[0]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadEvents() {
|
||||||
|
let EventsDir = path.join(__dirname, '..', 'events');
|
||||||
|
fs.readdir(EventsDir, (err, files) => {
|
||||||
|
if (err) this.error(err);
|
||||||
|
else
|
||||||
|
files.forEach((file) => {
|
||||||
|
const event = require(EventsDir + "/" + file);;
|
||||||
|
if (file.split(".")[0] == 'interactionCreate') this.on(file.split(".")[0], i => event(this, i));
|
||||||
|
else this.on(file.split(".")[0], event.bind(null, this));
|
||||||
|
this.logger.log("Event Loaded: " + file.split(".")[0]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
sendError(Channel, Error) {
|
||||||
|
let embed = new EmbedBuilder()
|
||||||
|
.setColor(this.config.Red)
|
||||||
|
.setDescription(Error);
|
||||||
|
|
||||||
|
Channel.send(embed);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendInternalError(Interaction, Error) {
|
||||||
|
this.error(Error);
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\n${this.config.SupportServer}`)
|
||||||
|
.setColor(this.config.Colors.Red)
|
||||||
|
|
||||||
|
Interaction.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calls register for guild and global commands
|
||||||
|
RegisterSlashCommands() {
|
||||||
|
RegisterGlobalCommands(this);
|
||||||
|
this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
log(Text) { this.logger.log(Text); }
|
||||||
|
error(Text) { this.logger.error(Text); }
|
||||||
|
|
||||||
|
build() {
|
||||||
|
this.login(this.config.Token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Applicantz;
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
const winston = require("winston");
|
||||||
|
const colors = require("colors");
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
constructor(LoggingFile) {
|
||||||
|
this.logger = winston.createLogger({
|
||||||
|
transports: [new winston.transports.File({ filename: LoggingFile })],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
log(Text) {
|
||||||
|
let d = new Date();
|
||||||
|
this.logger.log({
|
||||||
|
level: "info",
|
||||||
|
message:
|
||||||
|
`${d.getHours()}:${
|
||||||
|
d.getMinutes
|
||||||
|
} - ${d.getDate()}:${d.getMonth()}:${d.getFullYear()} | Info: ` + Text,
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
colors.green(
|
||||||
|
`${d.getDate()}:${d.getMonth()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}`
|
||||||
|
) + colors.yellow(" | Info: " + Text)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
error(Text) {
|
||||||
|
let d = new Date();
|
||||||
|
this.logger.log({
|
||||||
|
level: "error",
|
||||||
|
message:
|
||||||
|
`${d.getHours()}:${
|
||||||
|
d.getMinutes
|
||||||
|
} - ${d.getDate()}:${d.getMonth()}:${d.getFullYear()} | Error: ` + Text,
|
||||||
|
});
|
||||||
|
console.log(
|
||||||
|
colors.green(
|
||||||
|
`${d.getDate()}:${d.getMonth()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}`
|
||||||
|
) + colors.yellow(" | Error: ") + colors.red(Text)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Logger;
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const { Routes } = require('discord.js');
|
||||||
|
const { REST } = require('@discordjs/rest');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register slash commands for a guild
|
||||||
|
* @param {require("../structures/QuarksBot")} client
|
||||||
|
*/
|
||||||
|
module.exports = {
|
||||||
|
// Register guild commands
|
||||||
|
RegisterGuildCommands: async function(client, guild) {
|
||||||
|
const commands = [];
|
||||||
|
const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
// Place your client and guild ids here
|
||||||
|
const clientId = client.application.id;
|
||||||
|
const guildId = guild;
|
||||||
|
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const command = require(`../commands/${file}`);
|
||||||
|
if (!commands.global) commands.push(command); // don't include global commands
|
||||||
|
}
|
||||||
|
|
||||||
|
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||||
|
|
||||||
|
try {
|
||||||
|
client.log(`[${guildId}] Started refreshing guild (/) commands.`);
|
||||||
|
|
||||||
|
await rest.put(
|
||||||
|
Routes.applicationGuildCommands(clientId, guildId),
|
||||||
|
{ body: commands },
|
||||||
|
);
|
||||||
|
|
||||||
|
client.log(`[${guildId}] Successfully reloaded guild (/) commands.`);
|
||||||
|
} catch (error) {
|
||||||
|
client.error(error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Register global commands
|
||||||
|
RegisterGlobalCommands: async function(client) {
|
||||||
|
const commands = [];
|
||||||
|
const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
// Place your client and guild ids here
|
||||||
|
const clientId = client.application.id;
|
||||||
|
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const command = require(`../commands/${file}`);
|
||||||
|
if (command.global) commands.push(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||||
|
|
||||||
|
try {
|
||||||
|
client.log('[global] Started refreshing global (/) commands.');
|
||||||
|
|
||||||
|
await rest.put(
|
||||||
|
Routes.applicationCommands(clientId),
|
||||||
|
{ body: commands },
|
||||||
|
);
|
||||||
|
|
||||||
|
client.log('[global] Successfully reloaded global (/) commands.');
|
||||||
|
} catch (error) {
|
||||||
|
client.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user