This commit is contained in:
Isaac 2021-02-21 15:58:06 +00:00
parent ed12120f1b
commit 2910a2a201
No known key found for this signature in database
GPG Key ID: 279D1F53391CED07
10 changed files with 171 additions and 29 deletions

View File

@ -32,8 +32,11 @@ module.exports = class NewCommand extends Command {
let settings = await guild.settings; let settings = await guild.settings;
const i18n = this.client.i18n.get(settings.locale); const i18n = this.client.i18n.get(settings.locale);
return new MessageEmbed() channel.send(
new MessageEmbed()
.setColor(settings.colour) .setColor(settings.colour)
.setTitle(i18n('bot.version', require('../../package.json').version)); .setTitle(i18n('bot.version', require('../../package.json').version))
.setDescription(args.topic)
);
} }
}; };

View File

@ -73,7 +73,11 @@ module.exports = async (log) => {
locale: { locale: {
type: DataTypes.STRING, type: DataTypes.STRING,
defaultValue: config.defaults.locale defaultValue: config.defaults.locale
} },
log_messages: {
type: DataTypes.BOOLEAN,
defaultValue: config.defaults.log_messages
},
}, { }, {
tableName: DB_TABLE_PREFIX + 'guilds' tableName: DB_TABLE_PREFIX + 'guilds'
}); });
@ -116,11 +120,84 @@ module.exports = async (log) => {
model: Ticket, model: Ticket,
key: 'id' key: 'id'
}, },
} },
author: {
type: DataTypes.CHAR(18),
allowNull: false,
},
updates: {
type: DataTypes.JSON
},
}, { }, {
tableName: DB_TABLE_PREFIX + 'messages' tableName: DB_TABLE_PREFIX + 'messages'
}); });
// eslint-disable-next-line no-unused-vars
const Channel = sequelize.define('Channel', {
id: {
type: DataTypes.CHAR(18),
primaryKey: true,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
tableName: DB_TABLE_PREFIX + 'channel_entities'
});
// eslint-disable-next-line no-unused-vars
const Role = sequelize.define('Role', {
id: {
type: DataTypes.CHAR(18),
primaryKey: true,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
colour: {
type: DataTypes.INTEGER,
defaultValue: 7506394
},
}, {
tableName: DB_TABLE_PREFIX + 'role_entities'
});
// eslint-disable-next-line no-unused-vars
const Member = sequelize.define('Member', {
id: {
type: DataTypes.CHAR(18),
primaryKey: true,
allowNull: false,
},
username: {
type: DataTypes.STRING,
allowNull: false,
},
discriminator: {
type: DataTypes.STRING,
allowNull: false,
},
nickname: {
type: DataTypes.STRING,
allowNull: false,
},
avatar: {
type: DataTypes.STRING,
},
colour: {
type: DataTypes.INTEGER,
},
bot: {
type: DataTypes.BOOLEAN,
},
}, {
tableName: DB_TABLE_PREFIX + 'member_entities'
});
sequelize.sync(); sequelize.sync();
return sequelize; return sequelize;

View File

@ -13,7 +13,7 @@ module.exports = {
}); });
break; break;
case 2: case 2:
client.commands.execute(interaction.data.name, interaction); client.commands.handle(interaction);
break; break;
} }

View File

@ -1,5 +1,22 @@
module.exports = { module.exports = {
event: 'message', event: 'message',
execute: (client, message) => { execute: async (client, message) => {
let settings = await message.guild.settings;
if (settings.log_messages) {
if (message.type !== 'DEFAULT') return;
let ticket = await client.tickets.get(message.channel.id);
if (ticket) {
client.db.models.Message.create({
id: message.id,
ticket: ticket.id,
author: message.author.id
});
}
}
} }
}; };

View File

@ -35,9 +35,10 @@ module.exports = class Command {
* @param {Object} data - Command data * @param {Object} data - Command data
* @param {string} data.name - The name of the command (3-32) * @param {string} data.name - The name of the command (3-32)
* @param {string} data.description - The description of the command (1-100) * @param {string} data.description - The description of the command (1-100)
* @param {boolean} staff_only - Only allow staff to use this command? * @param {boolean} [data.staff_only] - Only allow staff to use this command?
* @param {string[]} permissions - Array of permissions needed for a user to use this command * @param {string[]} [data.permissions] - Array of permissions needed for a user to use this command
* @param {CommandOption[]} data.options - The command options, max of 10 * @param {boolean} [data.global] - Create a global command?
* @param {CommandOption[]} [data.options] - The command options (parameters), max of 10
*/ */
constructor(client, data) { constructor(client, data) {
@ -75,6 +76,13 @@ module.exports = class Command {
*/ */
this.permissions = data.permissions; this.permissions = data.permissions;
/**
* Is this a global command?
* @type {boolean}
* @default true
*/
this.global = data.global === false ? false : true;
/** /**
* The command options * The command options
* @type {CommandOption[]} * @type {CommandOption[]}
@ -103,6 +111,7 @@ module.exports = class Command {
return this.client.log.error(e); return this.client.log.error(e);
} }
if (this.global)
this.client.api.applications(this.client.user.id).commands.post({ data }); // post command to Discord this.client.api.applications(this.client.user.id).commands.post({ data }); // post command to Discord
let internal = this.internal ? 'internal ' : ''; let internal = this.internal ? 'internal ' : '';
@ -124,9 +133,9 @@ module.exports = class Command {
* @property {string} interaction.id - ID of the interaction * @property {string} interaction.id - ID of the interaction
* @property {number} interaction.type - Type of interaction * @property {number} interaction.type - Type of interaction
* @property {ApplicationCommandInteractionData} interaction.data - Interaction data * @property {ApplicationCommandInteractionData} interaction.data - Interaction data
* @property {Guild} interaction.guild- The guild object * @property {Object} interaction.guild- The guild object
* @property {Channel} interaction.channel- The channel object * @property {Object} interaction.channel- The channel object
* @property {GuildMember} interaction.member - The member object * @property {Object} interaction.member - The member object
* @property {string} interaction.token - The token used to respond to the interaction * @property {string} interaction.token - The token used to respond to the interaction
*/ */
@ -138,7 +147,6 @@ module.exports = class Command {
* @param {Channel} data.channel- The channel object * @param {Channel} data.channel- The channel object
* @param {Guild} data.guild- The guild object * @param {Guild} data.guild- The guild object
* @param {GuildMember} data.member - The member object * @param {GuildMember} data.member - The member object
* @param {string} data.token - The token used to respond to the interaction
* @param {Interaction} interaction - Interaction object * @param {Interaction} interaction - Interaction object
*/ */
async execute(data, interaction) { } async execute(data, interaction) { }
@ -146,15 +154,15 @@ module.exports = class Command {
/** /**
* Defer the response to respond later * Defer the response to respond later
* @param {Interaction} interaction - Interaction object * @param {Interaction} interaction - Interaction object
* @param {boolean} secret - Ephemeral message? **NOTE: EMBEDS AND ATTACHMENTS DO NOT RENDER IF TRUE** * @param {boolean} secret - Ephemeral?
*/ */
async deferResponse(interaction, secret) { async acknowledge(interaction, secret) {
this.client.api.interactions(interaction.id, interaction.token).callback.post({ this.client.api.interactions(interaction.id, interaction.token).callback.post({
data: { data: {
type: 5, type: 5,
data: { // data: {
flags: flags(secret) // flags: flags(secret)
}, // },
} }
}); });
} }

View File

@ -139,10 +139,11 @@ module.exports = class CommandManager {
/** /**
* Execute a command * Execute a command
* @param {string} cmd_name - Name of the command
* @param {Interaction} interaction - Command interaction * @param {Interaction} interaction - Command interaction
*/ */
async execute(cmd_name, interaction) { async handle(interaction) {
const cmd_name = interaction.data.name;
if (!this.commands.has(cmd_name)) if (!this.commands.has(cmd_name))
throw new Error(`Received "${cmd_name}" command invocation, but the command manager does not have a "${cmd_name}" command`); throw new Error(`Received "${cmd_name}" command invocation, but the command manager does not have a "${cmd_name}" command`);
@ -175,11 +176,11 @@ module.exports = class CommandManager {
} }
try { try {
await cmd.deferResponse(interaction, true); await cmd.acknowledge(interaction, true); // respond to discord
this.client.log.commands(`Executing "${cmd_name}" command (invoked by ${data.member.user.tag})`); this.client.log.commands(`Executing "${cmd_name}" command (invoked by ${data.member.user.tag})`);
let res = await cmd.execute(data, interaction); // run the command /* let res = */await cmd.execute(data, interaction); // run the command
if (typeof res === 'object' || typeof res === 'string') // if (typeof res === 'object' || typeof res === 'string')
cmd.sendResponse(interaction, res, res.secret); // cmd.sendResponse(interaction, res, res.secret);
} catch (e) { } catch (e) {
this.client.log.warn(`[COMMANDS] An error occurred whilst executed the ${cmd} command`); this.client.log.warn(`[COMMANDS] An error occurred whilst executed the ${cmd} command`);
this.client.log.error(e); this.client.log.error(e);

View File

@ -1,3 +1,4 @@
module.exports = { module.exports = {
TicketManager: require('./manager'),
Ticket: require('./ticket'),
}; };

View File

@ -0,0 +1,26 @@
const EventEmitter = require('events');
// eslint-disable-next-line no-unused-vars
const { Client } = require('discord.js');
/** Manages tickets */
module.exports = class extends EventEmitter {
/**
* Create a TicketManager instance
* @param {Client} client
*/
constructor(client) {
super();
/** The Discord Client */
this.client = client;
this.setMaxListeners(this.client.config.max_listeners);
}
/**
* Create a new ticket
*/
async create() {
}
};

View File

View File

@ -7,7 +7,7 @@ let current_presence = -1;
module.exports = { module.exports = {
/** /**
* Resolves data and files so embeds can be sent as a response to a slash command * Resolves data and files so embeds can be sent as a response to a slash command
* @param {Discord.Client} channel_id - Text channel ID * @param {Discord.Client} client - The Discord Client
* @param {string} channel_id - Text channel ID * @param {string} channel_id - Text channel ID
* @param {*} content - Message content * @param {*} content - Message content
* @returns {Object} * @returns {Object}
@ -25,6 +25,15 @@ module.exports = {
*/ */
flags: (secret) => secret ? 1 << 64 : undefined, flags: (secret) => secret ? 1 << 64 : undefined,
/**
* Set message entities
* @param {Discord.Message} message - The message to set entities for
*/
messageEntities(message) {
const { client } = message;
},
/** /**
* Select a presence from the config * Select a presence from the config
* @returns {Discord.PresenceData} * @returns {Discord.PresenceData}