mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-05 12:23:09 +02:00
Database things, pinned messages, start on ticket claiming
This commit is contained in:
parent
eb1fb737bb
commit
a7248d88ea
@ -1,5 +1,5 @@
|
|||||||
const { MessageEmbed } = require('discord.js');
|
|
||||||
const Command = require('../modules/commands/command');
|
const Command = require('../modules/commands/command');
|
||||||
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
module.exports = class BlacklistCommand extends Command {
|
module.exports = class BlacklistCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const { MessageEmbed } = require('discord.js');
|
|
||||||
const Command = require('../modules/commands/command');
|
const Command = require('../modules/commands/command');
|
||||||
|
const { MessageEmbed } = require('discord.js');
|
||||||
const { footer } = require('../utils/discord');
|
const { footer } = require('../utils/discord');
|
||||||
|
|
||||||
module.exports = class CloseCommand extends Command {
|
module.exports = class CloseCommand extends Command {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const { MessageEmbed } = require('discord.js');
|
|
||||||
const Command = require('../modules/commands/command');
|
const Command = require('../modules/commands/command');
|
||||||
|
const { MessageEmbed } = require('discord.js');
|
||||||
const { footer } = require('../utils/discord');
|
const { footer } = require('../utils/discord');
|
||||||
const { letters } = require('../utils/emoji');
|
const { letters } = require('../utils/emoji');
|
||||||
const { wait } = require('../utils');
|
const { wait } = require('../utils');
|
||||||
|
@ -46,6 +46,7 @@ module.exports = class SettingsCommand extends Command {
|
|||||||
id: c.id
|
id: c.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
cat_row.claiming = c.claiming;
|
||||||
cat_row.image = c.image;
|
cat_row.image = c.image;
|
||||||
cat_row.max_per_member = c.max_per_member;
|
cat_row.max_per_member = c.max_per_member;
|
||||||
cat_row.name = c.name;
|
cat_row.name = c.name;
|
||||||
@ -103,6 +104,7 @@ module.exports = class SettingsCommand extends Command {
|
|||||||
|
|
||||||
await this.client.db.models.Category.create({
|
await this.client.db.models.Category.create({
|
||||||
id: cat_channel.id,
|
id: cat_channel.id,
|
||||||
|
claiming: c.claiming,
|
||||||
guild: message.guild.id,
|
guild: message.guild.id,
|
||||||
image: c.image,
|
image: c.image,
|
||||||
max_per_member: c.max_per_member,
|
max_per_member: c.max_per_member,
|
||||||
@ -154,6 +156,7 @@ module.exports = class SettingsCommand extends Command {
|
|||||||
categories: categories.map(c => {
|
categories: categories.map(c => {
|
||||||
return {
|
return {
|
||||||
id: c.id,
|
id: c.id,
|
||||||
|
claiming: c.claiming,
|
||||||
image: c.image,
|
image: c.image,
|
||||||
max_per_member: c.max_per_member,
|
max_per_member: c.max_per_member,
|
||||||
name: c.name,
|
name: c.name,
|
||||||
|
31
src/commands/transfer.js
Normal file
31
src/commands/transfer.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const Command = require('../modules/commands/command');
|
||||||
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
const { footer } = require('../utils/discord');
|
||||||
|
|
||||||
|
module.exports = class TransferCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
const i18n = client.i18n.getLocale(client.config.locale);
|
||||||
|
super(client, {
|
||||||
|
internal: true,
|
||||||
|
name: i18n('commands.transfer.name'),
|
||||||
|
description: i18n('commands.transfer.description'),
|
||||||
|
aliases: [],
|
||||||
|
process_args: false,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
name: i18n('commands.transfer.args.member.name'),
|
||||||
|
description: i18n('commands.transfer.args.member.description'),
|
||||||
|
example: i18n('commands.transfer.args.member.example'),
|
||||||
|
required: false,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute(message, args) {
|
||||||
|
|
||||||
|
let settings = await message.guild.settings;
|
||||||
|
const i18n = this.client.i18n.getLocale(settings.locale);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
@ -39,6 +39,7 @@ module.exports = async (client) => {
|
|||||||
storage: path('./user/database.sqlite'),
|
storage: path('./user/database.sqlite'),
|
||||||
logging: text => client.log.debug(text)
|
logging: text => client.log.debug(text)
|
||||||
});
|
});
|
||||||
|
client.log.warn('SQLite is not sufficient for a production environment if you want to use ticket archives. You should disable "log_messages" in your servers\' settings or use a different database.');
|
||||||
} else {
|
} else {
|
||||||
client.log.info(`Connecting to ${types[type].name} database...`);
|
client.log.info(`Connecting to ${types[type].name} database...`);
|
||||||
sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASS, {
|
sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASS, {
|
||||||
|
@ -7,6 +7,10 @@ module.exports = ({ config }, sequelize) => {
|
|||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
|
claiming: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
guild: {
|
guild: {
|
||||||
type: DataTypes.CHAR(19),
|
type: DataTypes.CHAR(19),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
|
@ -15,6 +15,10 @@ module.exports = (client, sequelize) => {
|
|||||||
key: 'id'
|
key: 'id'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
claimed_by: {
|
||||||
|
type: DataTypes.CHAR(19),
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
closed_by: {
|
closed_by: {
|
||||||
type: DataTypes.CHAR(19),
|
type: DataTypes.CHAR(19),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
@ -53,6 +57,10 @@ module.exports = (client, sequelize) => {
|
|||||||
type: DataTypes.CHAR(19),
|
type: DataTypes.CHAR(19),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
|
pinned_messages: {
|
||||||
|
type: DataTypes.JSON,
|
||||||
|
defaultValue: []
|
||||||
|
},
|
||||||
topic: {
|
topic: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
event: 'messageReactionAdd',
|
event: 'messageReactionAdd',
|
||||||
execute: async (client, r, u) => {
|
execute: async (client, r, u) => {
|
||||||
|
if (r.partial) {
|
||||||
|
r = await r.fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (u.id === client.user.id) return;
|
||||||
|
|
||||||
const guild = r.message.guild;
|
const guild = r.message.guild;
|
||||||
if (!guild) return;
|
if (!guild) return;
|
||||||
|
|
||||||
let settings = await guild.settings;
|
let settings = await guild.settings;
|
||||||
if (!settings) settings = await guild.createSettings();
|
if (!settings) settings = await guild.createSettings();
|
||||||
|
|
||||||
|
let member = await guild.members.fetch(u.id);
|
||||||
|
|
||||||
if (settings.blacklist.includes(u.id)) {
|
if (settings.blacklist.includes(u.id)) {
|
||||||
return client.log.info(`Ignoring blacklisted member ${u.tag}`);
|
return client.log.info(`Ignoring blacklisted member ${u.tag}`);
|
||||||
@ -17,6 +25,22 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
let t_row = await client.db.models.Ticket.findOne({
|
||||||
|
where: {
|
||||||
|
id: r.message.channel.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
client.log.info('got t row')
|
||||||
|
if (t_row) {
|
||||||
|
if (
|
||||||
|
t_row.opening_message === r.message.id
|
||||||
|
&& r.emoji.name === '🙌'
|
||||||
|
&& await member.isStaff()
|
||||||
|
) {
|
||||||
|
// ticket claiming
|
||||||
|
client.log.info('claimed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -25,7 +25,7 @@
|
|||||||
"member_or_role": {
|
"member_or_role": {
|
||||||
"name": "memberOrRole",
|
"name": "memberOrRole",
|
||||||
"description": "A member mention, a role mention, or the ID of a member or role",
|
"description": "A member mention, a role mention, or the ID of a member or role",
|
||||||
"example": "@naughty-member"
|
"example": "@NaughtyMember"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"description": "Blacklist/unblacklist a member from interacting with the bot",
|
"description": "Blacklist/unblacklist a member from interacting with the bot",
|
||||||
@ -152,6 +152,19 @@
|
|||||||
"response": {
|
"response": {
|
||||||
"updated": "✅ Settings have been updated."
|
"updated": "✅ Settings have been updated."
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"transfer": {
|
||||||
|
"aliases": {},
|
||||||
|
"args": {
|
||||||
|
"member": {
|
||||||
|
"description": "A member mention or the ID of the member to transfer the ticket to",
|
||||||
|
"example": "@StaffMember",
|
||||||
|
"name": "member"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Transfer a ticket to another staff member",
|
||||||
|
"name": "transfer",
|
||||||
|
"response": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"command_execution_error": {
|
"command_execution_error": {
|
||||||
|
@ -105,22 +105,23 @@ module.exports = class TicketArchives {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateEntities(message) {
|
async updateEntities(message) {
|
||||||
|
|
||||||
|
let m_row = await this.client.db.models.Message.findOne({
|
||||||
|
where: {
|
||||||
|
id: message.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!m_row) return;
|
||||||
|
|
||||||
|
// message author
|
||||||
try {
|
try {
|
||||||
await this.client.db.transaction(async t => {
|
await this.client.db.transaction(async t => {
|
||||||
let m_row = await this.client.db.models.Message.findOne({
|
|
||||||
where: {
|
|
||||||
id: message.id
|
|
||||||
},
|
|
||||||
transaction: t
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!m_row) return;
|
|
||||||
|
|
||||||
// message author
|
|
||||||
let u_model_data = {
|
let u_model_data = {
|
||||||
user: message.author.id,
|
user: message.author.id,
|
||||||
ticket: message.channel.id
|
ticket: message.channel.id
|
||||||
};
|
};
|
||||||
|
|
||||||
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({
|
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({
|
||||||
where: u_model_data,
|
where: u_model_data,
|
||||||
defaults: u_model_data,
|
defaults: u_model_data,
|
||||||
@ -136,8 +137,17 @@ module.exports = class TicketArchives {
|
|||||||
bot: message.author.bot
|
bot: message.author.bot
|
||||||
}, { transaction: t });
|
}, { transaction: t });
|
||||||
|
|
||||||
// mentioned members
|
return u_row;
|
||||||
message.mentions.members.forEach(async member => {
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.client.log.warn('Failed to update message author entity in ticket archive');
|
||||||
|
this.client.log.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mentioned members
|
||||||
|
message.mentions.members.forEach(async member => {
|
||||||
|
try {
|
||||||
|
await this.client.db.transaction(async t => {
|
||||||
let m_model_data = {
|
let m_model_data = {
|
||||||
user: member.user.id,
|
user: member.user.id,
|
||||||
ticket: message.channel.id
|
ticket: message.channel.id
|
||||||
@ -156,10 +166,19 @@ module.exports = class TicketArchives {
|
|||||||
colour: member.displayColor === 0 ? null : int2hex(member.displayColor),
|
colour: member.displayColor === 0 ? null : int2hex(member.displayColor),
|
||||||
bot: member.user.bot
|
bot: member.user.bot
|
||||||
}, { transaction: t });
|
}, { transaction: t });
|
||||||
});
|
|
||||||
|
|
||||||
// mentioned channels
|
return m_row;
|
||||||
message.mentions.channels.forEach(async channel => {
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.client.log.warn('Failed to update mentioned members entities in ticket archive');
|
||||||
|
this.client.log.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// mentioned channels
|
||||||
|
message.mentions.channels.forEach(async channel => {
|
||||||
|
try {
|
||||||
|
await this.client.db.transaction(async t => {
|
||||||
let c_model_data = {
|
let c_model_data = {
|
||||||
channel: channel.id,
|
channel: channel.id,
|
||||||
ticket: message.channel.id
|
ticket: message.channel.id
|
||||||
@ -172,10 +191,19 @@ module.exports = class TicketArchives {
|
|||||||
await c_row.update({
|
await c_row.update({
|
||||||
name: this.encrypt(channel.name)
|
name: this.encrypt(channel.name)
|
||||||
}, { transaction: t });
|
}, { transaction: t });
|
||||||
});
|
|
||||||
|
|
||||||
// mentioned roles
|
return c_row;
|
||||||
message.mentions.roles.forEach(async role => {
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.client.log.warn('Failed to update mentioned channels entities in ticket archive');
|
||||||
|
this.client.log.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// mentioned roles
|
||||||
|
message.mentions.roles.forEach(async role => {
|
||||||
|
try {
|
||||||
|
await this.client.db.transaction(async t => {
|
||||||
let r_model_data = {
|
let r_model_data = {
|
||||||
role: role.id,
|
role: role.id,
|
||||||
ticket: message.channel.id
|
ticket: message.channel.id
|
||||||
@ -189,12 +217,15 @@ module.exports = class TicketArchives {
|
|||||||
name: this.encrypt(role.name),
|
name: this.encrypt(role.name),
|
||||||
colour: role.color === 0 ? '7289DA' : int2hex(role.color) // 7289DA = 7506394
|
colour: role.color === 0 ? '7289DA' : int2hex(role.color) // 7289DA = 7506394
|
||||||
}, { transaction: t });
|
}, { transaction: t });
|
||||||
|
|
||||||
|
return r_row;
|
||||||
});
|
});
|
||||||
});
|
} catch (e) {
|
||||||
} catch (e) {
|
this.client.log.warn('Failed to update mentioned roles entities in ticket archive');
|
||||||
this.client.log.warn('Failed to update message entities in ticket archive');
|
this.client.log.error(e);
|
||||||
this.client.log.error(e);
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
@ -23,8 +23,8 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle post-creation tasks
|
* Handle post-creation tasks
|
||||||
* @param {*} t_row
|
* @param {Model} t_row
|
||||||
* @param {*} cat_row
|
* @param {Model} cat_row
|
||||||
*/
|
*/
|
||||||
async postCreate(t_row, cat_row) {
|
async postCreate(t_row, cat_row) {
|
||||||
|
|
||||||
@ -70,10 +70,17 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
.catch(() => this.client.log.warn('Failed to delete system pin message'));
|
.catch(() => this.client.log.warn('Failed to delete system pin message'));
|
||||||
}
|
}
|
||||||
|
|
||||||
let questions = cat_row.opening_questions
|
if (cat_row.claiming) {
|
||||||
.map((q, index) => `**${index + 1}.** ${q}`)
|
await sent.react('🙌');
|
||||||
.join('\n\n');
|
}
|
||||||
|
|
||||||
|
let questions;
|
||||||
|
if (cat_row.opening_questions) {
|
||||||
|
questions = cat_row.opening_questions
|
||||||
|
.map((q, index) => `**${index + 1}.** ${q}`)
|
||||||
|
.join('\n\n');
|
||||||
|
}
|
||||||
|
|
||||||
if (cat_row.require_topic && topic.length === 0) {
|
if (cat_row.require_topic && topic.length === 0) {
|
||||||
let collector_message = await t_channel.send(
|
let collector_message = await t_channel.send(
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
@ -111,15 +118,17 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
collector_message
|
collector_message
|
||||||
.delete()
|
.delete()
|
||||||
.catch(() => this.client.log.warn('Failed to delete topic collector message'));
|
.catch(() => this.client.log.warn('Failed to delete topic collector message'));
|
||||||
await t_channel.send(
|
if (cat_row.opening_questions) {
|
||||||
new MessageEmbed()
|
await t_channel.send(
|
||||||
.setColor(settings.colour)
|
new MessageEmbed()
|
||||||
.setDescription(i18n('commands.new.questions', questions))
|
.setColor(settings.colour)
|
||||||
.setFooter(settings.footer)
|
.setDescription(i18n('commands.new.questions', questions))
|
||||||
);
|
.setFooter(settings.footer)
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (cat_row.opening_questions.length > 0) {
|
if (cat_row.opening_questions) {
|
||||||
await t_channel.send(
|
await t_channel.send(
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(settings.colour)
|
.setColor(settings.colour)
|
||||||
@ -280,13 +289,15 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.client.log.info(`A ticket was closed (${ticket_id})${reason ? `: "${reason}"` : ''}`);
|
this.client.log.info(`A ticket was closed (${ticket_id})${reason ? `: "${reason}"` : ''}`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pinned = await channel.messages.fetchPinned();
|
||||||
|
|
||||||
await t_row.update({
|
await t_row.update({
|
||||||
open: false,
|
open: false,
|
||||||
closed_by: closer_id || null,
|
closed_by: closer_id || null,
|
||||||
closed_reason: reason || null
|
closed_reason: reason || null,
|
||||||
|
pinned: [ ...pinned.keys() ]
|
||||||
});
|
});
|
||||||
|
|
||||||
this.emit('close', ticket_id);
|
this.emit('close', ticket_id);
|
||||||
|
@ -12,14 +12,8 @@ Structures.extend('GuildMember', GuildMember => {
|
|||||||
guild: this.guild.id
|
guild: this.guild.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
guild_categories.forEach(cat => {
|
|
||||||
cat.roles.forEach(r => {
|
|
||||||
if (this.roles.cache.has(r)) return true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
return guild_categories.some(cat => cat.roles.some(r => this.roles.cache.has(r)));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user