This commit is contained in:
Isaac 2021-02-20 17:09:08 +00:00
parent 9016da2f73
commit 5e9e23bbf2
No known key found for this signature in database
GPG Key ID: 279D1F53391CED07
12 changed files with 74 additions and 18 deletions

View File

@ -2,7 +2,7 @@
"name": "@eartharoid/discordtickets", "name": "@eartharoid/discordtickets",
"version": "3.0.0", "version": "3.0.0",
"private": true, "private": true,
"description": "An open-source & self-hosted Discord bot for ticket management.", "description": "An open-source Discord bot for ticket management",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"start": "node src/", "start": "node src/",

View File

@ -28,14 +28,13 @@ module.exports = class NewCommand extends Command {
} }
async execute({ guild, member, channel, args}, interaction) { async execute({ guild, member, channel, args}, interaction) {
console.log(args);
// console.log(channel.name);
// console.log(member.user.tag);
// console.log(guild.name);
const i18n = this.client.i18n.get(/* GET GUILD LOCALE FROM SETTINGS */); let settings = await guild.settings;
const i18n = this.client.i18n.get(settings.locale);
return new MessageEmbed() return new MessageEmbed()
.setTitle(i18n('bot.version', require('../../package.json').version)); .setColor(settings.colour)
.setTitle(i18n('bot.version', require('../../package.json').version))
.secret = true;
} }
}; };

View File

@ -66,6 +66,10 @@ module.exports = async (log) => {
primaryKey: true, primaryKey: true,
allowNull: false, allowNull: false,
}, },
colour: {
type: DataTypes.STRING,
defaultValue: config.defaults.colour
},
locale: { locale: {
type: DataTypes.STRING, type: DataTypes.STRING,
defaultValue: config.defaults.locale defaultValue: config.defaults.locale

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
* *
* @name @eartharoid/discordtickets * @name @eartharoid/discordtickets
* @description An open-source & self-hosted Discord bot for ticket management. * @description An open-source Discord bot for ticket management
* @copyright 2021 Isaac Saunders * @copyright 2021 Isaac Saunders
* @license GNU-GPLv3 * @license GNU-GPLv3
*/ */
@ -52,8 +52,6 @@ if (!checkFile('./.env', './example.env')) {
checkFile('./user/config.js', './user/example.config.js'); checkFile('./user/config.js', './user/example.config.js');
require('dotenv').config({ require('dotenv').config({
path: path('./.env') path: path('./.env')
}); });
@ -67,6 +65,7 @@ const log = new Logger({
name: 'DiscordTickets by eartharoid', name: 'DiscordTickets by eartharoid',
debug: config.debug, debug: config.debug,
logToFile: config.logs.enabled, logToFile: config.logs.enabled,
directory: path('./logs/'),
keepFor: config.logs.keep_for, keepFor: config.logs.keep_for,
custom: { custom: {
commands: { commands: {
@ -76,6 +75,10 @@ const log = new Logger({
plugins: { plugins: {
title: 'info', title: 'info',
prefix: 'plugins' prefix: 'plugins'
},
tickets: {
title: 'info',
prefix: 'tickets'
} }
} }
}); });
@ -85,6 +88,8 @@ const I18n = require('@eartharoid/i18n');
const { CommandManager } = require('./modules/commands'); const { CommandManager } = require('./modules/commands');
const { PluginManager } = require('./modules/plugins'); const { PluginManager } = require('./modules/plugins');
require('./modules/structures')(); // load extended structures before creating the client
const { const {
Client, Client,
Intents Intents

View File

@ -0,0 +1,7 @@
module.exports = {
event: 'guildCreate',
execute: async (client, guild) => {
client.log.console(`Added to ${guild.name}`);
await guild.createSettings();
}
};

View File

@ -0,0 +1,7 @@
module.exports = {
event: 'guildDelete',
execute: async (client, guild) => {
client.log.console(`Removed from ${guild.name}`);
await guild.deleteSettings();
}
};

View File

@ -8,7 +8,7 @@ module.exports = {
client.log.debug('Received interaction ping, responding with pong'); client.log.debug('Received interaction ping, responding with pong');
await client.api.interactions(interaction.id, interaction.token).callback.post({ await client.api.interactions(interaction.id, interaction.token).callback.post({
data: { data: {
type: 1, type: 1, // PONG
} }
}); });
break; break;
@ -17,7 +17,5 @@ module.exports = {
break; break;
} }
} }
}; };

View File

@ -1,5 +1,13 @@
{ {
"admin_only": "❌ You must be an administrator to use this command.",
"bot": { "bot": {
"version": "DiscordTickets v%s by eartharoid" "version": "DiscordTickets v%s by eartharoid"
},
"cmd": {
"new": {
} }
},
"no_perm": "❌ You do not have the permissions required to use this command:\n%s",
"support_only": "❌ You must be a member of staff to use this command."
} }

View File

@ -177,8 +177,10 @@ module.exports = class Command {
data: { data: {
type: 4, type: 4,
flags: flags(secret), flags: flags(secret),
data: {
content content
} }
}
}); });
} }

View File

@ -140,7 +140,7 @@ module.exports = class CommandManager {
/** /**
* Execute a command * Execute a command
* @param {string} cmd_name - Name of the 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 execute(cmd_name, interaction) {
if (!this.commands.has(cmd_name)) if (!this.commands.has(cmd_name))
@ -157,6 +157,11 @@ module.exports = class CommandManager {
const cmd = this.commands.get(cmd_name); const cmd = this.commands.get(cmd_name);
let settings = await data.guild.settings;
if (!settings)
settings = await data.guild.createSettings();
const i18n = this.client.i18n.get(settings.locale);
// if (cmd.staff_only) { // if (cmd.staff_only) {
// return await cmd.sendResponse(interaction, msg, true); // return await cmd.sendResponse(interaction, msg, true);
// } // }
@ -165,7 +170,7 @@ module.exports = class CommandManager {
&& !data.member.hasPermission(cmd.permissions); && !data.member.hasPermission(cmd.permissions);
if (no_perm) { if (no_perm) {
let perms = cmd.permissions.map(p => `\`${p}\``).join(', '); let perms = cmd.permissions.map(p => `\`${p}\``).join(', ');
let msg = `❌ You do not have the permissions required to use this command:\n${perms}`; let msg = i18n('no_perm', perms);
return await cmd.sendResponse(interaction, msg, true); return await cmd.sendResponse(interaction, msg, true);
} }

10
src/modules/structures.js Normal file
View File

@ -0,0 +1,10 @@
const fs = require('fs');
const { path } = require('../utils/fs');
module.exports = () => {
const files = fs.readdirSync(path('./src/structures'))
.filter(file => file.endsWith('.js'));
for (const file of files)
require(`../structures/${file}`);
};

View File

@ -6,8 +6,19 @@ Structures.extend('Guild', Guild => {
super(client, data); super(client, data);
} }
createSettings() {
return this.client.db.models.Guild.create({
id: this.id
});
}
async deleteSettings() {
let row = await this.settings;
return await row.destroy();
}
get settings() { get settings() {
return this.client.db.Guild.findOne({ return this.client.db.models.Guild.findOne({
where: { where: {
id: this.id id: this.id
} }