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

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

View File

@ -73,7 +73,11 @@ module.exports = async (log) => {
locale: {
type: DataTypes.STRING,
defaultValue: config.defaults.locale
}
},
log_messages: {
type: DataTypes.BOOLEAN,
defaultValue: config.defaults.log_messages
},
}, {
tableName: DB_TABLE_PREFIX + 'guilds'
});
@ -116,11 +120,84 @@ module.exports = async (log) => {
model: Ticket,
key: 'id'
},
}
},
author: {
type: DataTypes.CHAR(18),
allowNull: false,
},
updates: {
type: DataTypes.JSON
},
}, {
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();
return sequelize;

View File

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

View File

@ -1,5 +1,22 @@
module.exports = {
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 {string} data.name - The name of the command (3-32)
* @param {string} data.description - The description of the command (1-100)
* @param {boolean} staff_only - Only allow staff to use this command?
* @param {string[]} 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.staff_only] - Only allow staff to use this command?
* @param {string[]} [data.permissions] - Array of permissions needed for a user to use this command
* @param {boolean} [data.global] - Create a global command?
* @param {CommandOption[]} [data.options] - The command options (parameters), max of 10
*/
constructor(client, data) {
@ -75,6 +76,13 @@ module.exports = class Command {
*/
this.permissions = data.permissions;
/**
* Is this a global command?
* @type {boolean}
* @default true
*/
this.global = data.global === false ? false : true;
/**
* The command options
* @type {CommandOption[]}
@ -103,7 +111,8 @@ module.exports = class Command {
return this.client.log.error(e);
}
this.client.api.applications(this.client.user.id).commands.post({ data }); // post command to Discord
if (this.global)
this.client.api.applications(this.client.user.id).commands.post({ data }); // post command to Discord
let internal = this.internal ? 'internal ' : '';
this.client.log.commands(`Loaded ${internal}"${this.name}" command`);
@ -124,9 +133,9 @@ module.exports = class Command {
* @property {string} interaction.id - ID of the interaction
* @property {number} interaction.type - Type of interaction
* @property {ApplicationCommandInteractionData} interaction.data - Interaction data
* @property {Guild} interaction.guild- The guild object
* @property {Channel} interaction.channel- The channel object
* @property {GuildMember} interaction.member - The member object
* @property {Object} interaction.guild- The guild object
* @property {Object} interaction.channel- The channel object
* @property {Object} interaction.member - The member object
* @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 {Guild} data.guild- The guild 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
*/
async execute(data, interaction) { }
@ -146,15 +154,15 @@ module.exports = class Command {
/**
* Defer the response to respond later
* @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({
data: {
type: 5,
data: {
flags: flags(secret)
},
// data: {
// flags: flags(secret)
// },
}
});
}

View File

@ -139,10 +139,11 @@ module.exports = class CommandManager {
/**
* Execute a command
* @param {string} cmd_name - Name of the command
* @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))
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 {
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})`);
let res = await cmd.execute(data, interaction); // run the command
if (typeof res === 'object' || typeof res === 'string')
cmd.sendResponse(interaction, res, res.secret);
/* let res = */await cmd.execute(data, interaction); // run the command
// if (typeof res === 'object' || typeof res === 'string')
// cmd.sendResponse(interaction, res, res.secret);
} catch (e) {
this.client.log.warn(`[COMMANDS] An error occurred whilst executed the ${cmd} command`);
this.client.log.error(e);

View File

@ -1,3 +1,4 @@
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 = {
/**
* 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 {*} content - Message content
* @returns {Object}
@ -25,6 +25,15 @@ module.exports = {
*/
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
* @returns {Discord.PresenceData}