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 { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = class BlacklistCommand extends Command {
|
||||
constructor(client) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const Command = require('../modules/commands/command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { footer } = require('../utils/discord');
|
||||
|
||||
module.exports = class CloseCommand extends Command {
|
||||
|
@ -1,5 +1,5 @@
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const Command = require('../modules/commands/command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { footer } = require('../utils/discord');
|
||||
const { letters } = require('../utils/emoji');
|
||||
const { wait } = require('../utils');
|
||||
|
@ -46,6 +46,7 @@ module.exports = class SettingsCommand extends Command {
|
||||
id: c.id
|
||||
}
|
||||
});
|
||||
cat_row.claiming = c.claiming;
|
||||
cat_row.image = c.image;
|
||||
cat_row.max_per_member = c.max_per_member;
|
||||
cat_row.name = c.name;
|
||||
@ -103,6 +104,7 @@ module.exports = class SettingsCommand extends Command {
|
||||
|
||||
await this.client.db.models.Category.create({
|
||||
id: cat_channel.id,
|
||||
claiming: c.claiming,
|
||||
guild: message.guild.id,
|
||||
image: c.image,
|
||||
max_per_member: c.max_per_member,
|
||||
@ -154,6 +156,7 @@ module.exports = class SettingsCommand extends Command {
|
||||
categories: categories.map(c => {
|
||||
return {
|
||||
id: c.id,
|
||||
claiming: c.claiming,
|
||||
image: c.image,
|
||||
max_per_member: c.max_per_member,
|
||||
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'),
|
||||
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 {
|
||||
client.log.info(`Connecting to ${types[type].name} database...`);
|
||||
sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASS, {
|
||||
|
@ -7,6 +7,10 @@ module.exports = ({ config }, sequelize) => {
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
},
|
||||
claiming: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
guild: {
|
||||
type: DataTypes.CHAR(19),
|
||||
allowNull: false,
|
||||
|
@ -15,6 +15,10 @@ module.exports = (client, sequelize) => {
|
||||
key: 'id'
|
||||
},
|
||||
},
|
||||
claimed_by: {
|
||||
type: DataTypes.CHAR(19),
|
||||
allowNull: true,
|
||||
},
|
||||
closed_by: {
|
||||
type: DataTypes.CHAR(19),
|
||||
allowNull: true,
|
||||
@ -53,6 +57,10 @@ module.exports = (client, sequelize) => {
|
||||
type: DataTypes.CHAR(19),
|
||||
allowNull: true,
|
||||
},
|
||||
pinned_messages: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: []
|
||||
},
|
||||
topic: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
|
@ -1,12 +1,20 @@
|
||||
module.exports = {
|
||||
event: 'messageReactionAdd',
|
||||
execute: async (client, r, u) => {
|
||||
if (r.partial) {
|
||||
r = await r.fetch();
|
||||
}
|
||||
|
||||
if (u.id === client.user.id) return;
|
||||
|
||||
const guild = r.message.guild;
|
||||
if (!guild) return;
|
||||
|
||||
let settings = await guild.settings;
|
||||
if (!settings) settings = await guild.createSettings();
|
||||
|
||||
let member = await guild.members.fetch(u.id);
|
||||
|
||||
if (settings.blacklist.includes(u.id)) {
|
||||
return client.log.info(`Ignoring blacklisted member ${u.tag}`);
|
||||
} else {
|
||||
@ -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": {
|
||||
"name": "memberOrRole",
|
||||
"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",
|
||||
@ -152,6 +152,19 @@
|
||||
"response": {
|
||||
"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": {
|
||||
|
@ -105,22 +105,23 @@ module.exports = class TicketArchives {
|
||||
}
|
||||
|
||||
async updateEntities(message) {
|
||||
try {
|
||||
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
|
||||
try {
|
||||
await this.client.db.transaction(async t => {
|
||||
let u_model_data = {
|
||||
user: message.author.id,
|
||||
ticket: message.channel.id
|
||||
};
|
||||
|
||||
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({
|
||||
where: u_model_data,
|
||||
defaults: u_model_data,
|
||||
@ -136,8 +137,17 @@ module.exports = class TicketArchives {
|
||||
bot: message.author.bot
|
||||
}, { transaction: t });
|
||||
|
||||
return u_row;
|
||||
});
|
||||
} 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 = {
|
||||
user: member.user.id,
|
||||
ticket: message.channel.id
|
||||
@ -156,10 +166,19 @@ module.exports = class TicketArchives {
|
||||
colour: member.displayColor === 0 ? null : int2hex(member.displayColor),
|
||||
bot: member.user.bot
|
||||
}, { transaction: t });
|
||||
|
||||
return m_row;
|
||||
});
|
||||
} 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 = {
|
||||
channel: channel.id,
|
||||
ticket: message.channel.id
|
||||
@ -172,10 +191,19 @@ module.exports = class TicketArchives {
|
||||
await c_row.update({
|
||||
name: this.encrypt(channel.name)
|
||||
}, { transaction: t });
|
||||
|
||||
return c_row;
|
||||
});
|
||||
} 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 = {
|
||||
role: role.id,
|
||||
ticket: message.channel.id
|
||||
@ -189,12 +217,15 @@ module.exports = class TicketArchives {
|
||||
name: this.encrypt(role.name),
|
||||
colour: role.color === 0 ? '7289DA' : int2hex(role.color) // 7289DA = 7506394
|
||||
}, { transaction: t });
|
||||
});
|
||||
|
||||
return r_row;
|
||||
});
|
||||
} catch (e) {
|
||||
this.client.log.warn('Failed to update message entities in ticket archive');
|
||||
this.client.log.warn('Failed to update mentioned roles entities in ticket archive');
|
||||
this.client.log.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
@ -23,8 +23,8 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Handle post-creation tasks
|
||||
* @param {*} t_row
|
||||
* @param {*} cat_row
|
||||
* @param {Model} t_row
|
||||
* @param {Model} cat_row
|
||||
*/
|
||||
async postCreate(t_row, cat_row) {
|
||||
|
||||
@ -70,9 +70,16 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
.catch(() => this.client.log.warn('Failed to delete system pin message'));
|
||||
}
|
||||
|
||||
let questions = cat_row.opening_questions
|
||||
if (cat_row.claiming) {
|
||||
await sent.react('🙌');
|
||||
}
|
||||
|
||||
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) {
|
||||
let collector_message = await t_channel.send(
|
||||
@ -111,15 +118,17 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
collector_message
|
||||
.delete()
|
||||
.catch(() => this.client.log.warn('Failed to delete topic collector message'));
|
||||
if (cat_row.opening_questions) {
|
||||
await t_channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.colour)
|
||||
.setDescription(i18n('commands.new.questions', questions))
|
||||
.setFooter(settings.footer)
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (cat_row.opening_questions.length > 0) {
|
||||
if (cat_row.opening_questions) {
|
||||
await t_channel.send(
|
||||
new MessageEmbed()
|
||||
.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}"` : ''}`);
|
||||
|
||||
}
|
||||
|
||||
let pinned = await channel.messages.fetchPinned();
|
||||
|
||||
await t_row.update({
|
||||
open: false,
|
||||
closed_by: closer_id || null,
|
||||
closed_reason: reason || null
|
||||
closed_reason: reason || null,
|
||||
pinned: [ ...pinned.keys() ]
|
||||
});
|
||||
|
||||
this.emit('close', ticket_id);
|
||||
|
@ -13,13 +13,7 @@ Structures.extend('GuildMember', GuildMember => {
|
||||
}
|
||||
});
|
||||
|
||||
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