mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-04 01:11:27 +03:00
feat: allow other CWD
This commit is contained in:
@@ -15,25 +15,28 @@ const ms = require('ms');
|
||||
|
||||
module.exports = class Client extends FrameworkClient {
|
||||
constructor(config, log) {
|
||||
super({
|
||||
intents: [
|
||||
...[
|
||||
GatewayIntentBits.DirectMessages,
|
||||
GatewayIntentBits.DirectMessageReactions,
|
||||
GatewayIntentBits.DirectMessageTyping,
|
||||
GatewayIntentBits.MessageContent,
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
super(
|
||||
{
|
||||
intents: [
|
||||
...[
|
||||
GatewayIntentBits.DirectMessages,
|
||||
GatewayIntentBits.DirectMessageReactions,
|
||||
GatewayIntentBits.DirectMessageTyping,
|
||||
GatewayIntentBits.MessageContent,
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
],
|
||||
...(process.env.PUBLIC_BOT !== 'true' ? [GatewayIntentBits.GuildPresences] : []),
|
||||
],
|
||||
...(process.env.PUBLIC_BOT !== 'true' ? [GatewayIntentBits.GuildPresences] : []),
|
||||
],
|
||||
partials: [
|
||||
Partials.Channel,
|
||||
Partials.Message,
|
||||
Partials.Reaction,
|
||||
],
|
||||
});
|
||||
partials: [
|
||||
Partials.Channel,
|
||||
Partials.Message,
|
||||
Partials.Reaction,
|
||||
],
|
||||
},
|
||||
{ baseDir: __dirname },
|
||||
);
|
||||
|
||||
const locales = {};
|
||||
fs.readdirSync(join(__dirname, 'i18n'))
|
||||
@@ -57,13 +60,19 @@ module.exports = class Client extends FrameworkClient {
|
||||
const levels = ['error', 'info', 'warn'];
|
||||
if (this.config.logs.level === 'debug') levels.push('query');
|
||||
|
||||
/** @type {PrismaClient} */
|
||||
this.prisma = new PrismaClient({
|
||||
const prisma_options = {
|
||||
log: levels.map(level => ({
|
||||
emit: 'event',
|
||||
level,
|
||||
})),
|
||||
});
|
||||
};
|
||||
|
||||
if (process.env.DB_PROVIDER === 'sqlite' && !process.env.DB_CONNECTION_URL) {
|
||||
prisma_options.datasources = { db: { url:'file:' + join(process.cwd(), './user/database.db') } };
|
||||
}
|
||||
|
||||
/** @type {PrismaClient} */
|
||||
this.prisma = new PrismaClient(prisma_options);
|
||||
|
||||
this.prisma.$on('error', e => this.log.error.prisma(`${e.target} ${e.message}`));
|
||||
this.prisma.$on('info', e => this.log.info.prisma(`${e.target} ${e.message}`));
|
||||
|
25
src/index.js
25
src/index.js
@@ -29,6 +29,7 @@ console.log(banner(pkg.version)); // print big title
|
||||
|
||||
const semver = require('semver');
|
||||
const { colours } = require('leeks.js');
|
||||
const path = require('path');
|
||||
|
||||
// check node version
|
||||
if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
|
||||
@@ -36,6 +37,16 @@ if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const base_dir = path.resolve(path.join(__dirname, '../'));
|
||||
const cwd = path.resolve(process.cwd());
|
||||
if (base_dir !== cwd) {
|
||||
console.log('\x07' + colours.yellowBright('Warning: The current working directory is not the same as the base directory.'));
|
||||
console.log(colours.yellowBright('This may result in unexpected behaviour, particularly with missing environment variables.'));
|
||||
console.log(' Base directory: ' + colours.gray(base_dir));
|
||||
console.log(' CWD: ' + colours.gray(cwd));
|
||||
console.log(colours.blueBright(' Learn more at https://lnk.earth/dt-cwd.'));
|
||||
}
|
||||
|
||||
// this could be done first, but then there would be no banner :(
|
||||
process.env.NODE_ENV ??= 'production'; // make sure NODE_ENV is set
|
||||
require('./env').load(); // load and check environment variables
|
||||
@@ -46,16 +57,12 @@ const logger = require('./lib/logger');
|
||||
const Client = require('./client');
|
||||
const http = require('./http');
|
||||
|
||||
// user directory may or may not exist depending on if sqlite is being used
|
||||
// so the config file could be missing even though the directory exists
|
||||
if (!fs.existsSync('./user/config.yml')) {
|
||||
const examplePath = './user/example.config.yml';
|
||||
if (!fs.existsSync(examplePath)) {
|
||||
console.log('\x07' + colours.redBright('The config file does not exist, and the example file is missing so cannot be copied from.'));
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Creating config file...');
|
||||
fs.copyFileSync(examplePath, './user/config.yml');
|
||||
console.log(`Copied config to ${'./user/config.yml'}`);
|
||||
}
|
||||
console.log('The config file does not exist, copying defaults...');
|
||||
fs.cpSync(path.join(__dirname, 'user'), './user', { recursive: true });
|
||||
console.log('Created user directory at', path.join(cwd, 'user'));
|
||||
}
|
||||
|
||||
const config = YAML.parse(fs.readFileSync('./user/config.yml', 'utf8'));
|
||||
|
0
src/user/avatars/.gitkeep
Normal file
0
src/user/avatars/.gitkeep
Normal file
36
src/user/config.yml
Normal file
36
src/user/config.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
#####################################################
|
||||
## ____ _ ##
|
||||
## | _ \ (_) ___ ___ ___ _ __ __| | ##
|
||||
## | | | | | | / __| / __| / _ \ | '__| / _` | ##
|
||||
## | |_| | | | \__ \ | (__ | (_) | | | | (_| | ##
|
||||
## |____/ |_| |___/ \___| \___/ |_| \__,_| ##
|
||||
## _____ _ _ ##
|
||||
## |_ _| (_) ___ | | __ ___ | |_ ___ ##
|
||||
## | | | | / __| | |/ / / _ \ | __| / __| ##
|
||||
## | | | | | (__ | < | __/ | |_ \__ \ ##
|
||||
## |_| |_| \___| |_|\_\ \___| \__| |___/ ##
|
||||
## ##
|
||||
## Documentation: https://discordtickets.app ##
|
||||
## Support: https://lnk.earth/discord ##
|
||||
#####################################################
|
||||
|
||||
logs:
|
||||
files:
|
||||
directory: ./logs
|
||||
enabled: true
|
||||
keepFor: 30
|
||||
level: info
|
||||
presence:
|
||||
activities:
|
||||
- name: /new
|
||||
- name: with {totalTickets} tickets
|
||||
- name: "{openTickets} tickets"
|
||||
type: 3
|
||||
- name: "{avgResponseTime} response time"
|
||||
type: 3
|
||||
interval: 20
|
||||
status: online
|
||||
stats: true
|
||||
templates:
|
||||
transcript: transcript.md
|
||||
updates: true
|
30
src/user/templates/transcript.md.mustache
Normal file
30
src/user/templates/transcript.md.mustache
Normal file
@@ -0,0 +1,30 @@
|
||||
#{{ channelName }} ticket transcript
|
||||
|
||||
---
|
||||
|
||||
* ID: {{ ticket.id }} ({{ guildName }})
|
||||
* Number: {{ ticket.category.name }} #{{ ticket.number }}
|
||||
* Topic: {{ #ticket.topic }}{{ . }}{{ /ticket.topic }}{{ ^ticket.topic }}(no topic){{ /ticket.topic }}
|
||||
* Created on: {{ #ticket }}{{ createdAtFull }}{{ /ticket }}
|
||||
* Created by: {{ #ticket.createdBy }}"{{ displayName }}" @{{ username }}#{{ discriminator }}{{ /ticket.createdBy }}
|
||||
* Closed on: {{ #ticket }}{{ closedAtFull }}{{ /ticket }}
|
||||
* Closed by: {{ #ticket.closedBy }}"{{ displayName }}" @{{ username }}#{{ discriminator }}{{ /ticket.closedBy }}{{ ^ticket.closedBy }}(automated){{ /ticket.closedBy }}
|
||||
* Closed because: {{ #ticket.closedReason }}{{ ticket.closedReason }}{{ /ticket.closedReason }}{{ ^ticket.closedReason }}(no reason){{ /ticket.closedReason }}
|
||||
* Claimed by: {{ #ticket.claimedBy }}"{{ displayName }}" @{{ username }}#{{ discriminator }}{{ /ticket.claimedBy }}{{ ^ticket.claimedBy }}(not claimed){{ /ticket.claimedBy }}
|
||||
{{ #ticket.feedback }}
|
||||
* Feedback:
|
||||
* Rating: {{ rating }}/5
|
||||
* Comment: {{ comment }}{{ ^comment }}(no comment){{ /comment }}
|
||||
{{ /ticket.feedback }}
|
||||
* Participants:
|
||||
{{ #ticket.archivedUsers }}
|
||||
* "{{ displayName }}" @{{ username }}#{{ discriminator }} ({{ userId }})
|
||||
{{ /ticket.archivedUsers }}
|
||||
* Pinned messages: {{ #pinned }}{{ . }}{{ /pinned }}
|
||||
|
||||
---
|
||||
|
||||
{{ #ticket.archivedMessages }}
|
||||
<{{ number }}> [{{ createdAtTimestamp }}] {{author.displayName}}: {{ text }}
|
||||
|
||||
{{ /ticket.archivedMessages }}
|
0
src/user/uploads/.gitkeep
Normal file
0
src/user/uploads/.gitkeep
Normal file
Reference in New Issue
Block a user