This commit is contained in:
Isaac (eartharoid)
2020-08-17 14:46:23 +01:00
parent fa36d8dbe2
commit 62494aaa4d
29 changed files with 1612 additions and 186 deletions

View File

@@ -8,15 +8,43 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const lineReader = require('line-reader');
const fs = require('fs');
const config = require('../../user/config');
module.exports.create = (client, channel) => {
// channel.members
if(config.transcripts.text.enabled) {
// text/channel.txt
}
if(config.transcripts.web.enabled) {
// raw/channel.log
}
};
module.exports.addUser = (client, channel, user) => {
};
module.exports.addMessage = (client, channel, message) => {
// if !entities.users.user, add
};
module.exports.export = (client, channel) => {
let path = `user/transcripts/raw/${channel.id}.log`;
if(config.transcripts.web.enabled && fs.existsSync(path)) {
lineReader.eachLine(path, (line, last) => {
console.log(line);
//if raw id exists, overwrite previous
});
}
/**
* @TODO users, roles, etc
* check channel.members again!
* */
};

View File

@@ -7,6 +7,8 @@
*/
const { version, homepage } = require('../../package.json');
const link = require('terminal-link');
module.exports = (leeks) => {
console.log(leeks.colours.cyan(`
######## #### ###### ###### ####### ######## ########
@@ -26,6 +28,7 @@ module.exports = (leeks) => {
## #### ###### ## ## ######## ## ######
`));
console.log(leeks.colours.cyanBright(`DiscordTickets bot v${version} by eartharoid`));
console.log(leeks.colours.cyanBright(homepage));
console.log(leeks.colours.cyanBright(homepage + '\n'));
console.log(leeks.colours.cyanBright(`Please ${link('donate', 'https://ko-fi.com/eartharoid')} if you find this bot useful`));
console.log('\n\n');
};

180
src/utils/panel.js Normal file
View File

@@ -0,0 +1,180 @@
/**
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
*
*/
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const Discord = require('discord.js');
const fs = require('fs');
const config = require('../../user/config');
module.exports = async (client, Ticket, Setting) => {
let panelID = await Setting.findOne({ where: { key: 'panel_msg_id' } });
if (!panelID) return;
let chanID = await Setting.findOne({ where: { key: 'panel_chan_id' } });
if (!chanID) return;
let channel = client.channels.cache.get(chanID.get('value'));
if (!channel)
return Setting.destroy({ where: { key: 'panel_chan_id' } });
let panel = channel.messages.cache.get(panelID.get('value'));
if(!panel)
return Setting.destroy({ where: { key: 'panel_msg_id' } });
const collector = panel.createReactionCollector(
(r, u) => r.emoji.name === config.panel.reaction && u.id !== client.user.id);
collector.on('collect', async (r, u) => {
await r.users.remove(u.id); // effectively cancel reaction
const supportRole = channel.guild.roles.cache.get(config.staff_role);
if (!supportRole)
return channel.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setTitle(':x: **Error**')
.setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``)
.setFooter(channel.guild.name, channel.guild.iconURL())
);
let tickets = await Ticket.findAndCountAll({
where: {
creator: u.id,
open: true
},
limit: config.tickets.max
});
if (tickets.count >= config.tickets.max) {
let ticketList = [];
for (let t in tickets.rows) {
let desc = tickets.rows[t].topic.substring(0, 30);
ticketList
.push(`<#${tickets.rows[t].channel}>: \`${desc}${desc.length > 30 ? '...' : ''}\``);
}
let dm = u.dmChannel || await u.createDM();
let m = await dm.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setAuthor(u.username, u.displayAvatarURL())
.setTitle(`:x: **You already have ${tickets.count} or more open tickets**`)
.setDescription(`Use \`${config.prefix}close\` to close unneeded tickets.\n\n${ticketList.join(',\n')}`)
.setFooter(channel.guild.name + ' | This message will be deleted in 15 seconds', channel.guild.iconURL())
);
return m.delete({ timeout: 15000 });
}
let topic = 'No topic given (created via panel)';
let ticket = await Ticket.create({
channel: '',
creator: u.id,
open: true,
archived: false,
topic: topic
});
let name = 'ticket-' + ticket.get('id');
channel.guild.channels.create(name, {
type: 'text',
topic: `${u} | ${topic}`,
parent: config.tickets.category,
permissionOverwrites: [{
id: channel.guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: channel.guild.member(u),
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']
},
{
id: supportRole,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']
}
],
reason: 'User requested a new support ticket channel'
}).then(async c => {
Ticket.update({
channel: c.id
}, {
where: {
id: ticket.id
}
});
let ping;
switch (config.tickets.ping) {
case 'staff':
ping = `<@&${config.staff_role}>,\n`;
break;
case false:
ping = '';
break;
default:
ping = `@${config.tickets.ping},\n`;
}
await c.send(ping + `${u} has created a new ticket`);
if (config.tickets.send_img) {
const images = fs.readdirSync('user/images');
await c.send({
files: [
'user/images/' +
images[Math.floor(Math.random() * images.length)]
]
});
}
let text = config.tickets.text
.replace('{{ name }}', u.username)
.replace('{{ tag }}', u);
let w = await c.send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(u.username, u.displayAvatarURL())
.setDescription(text)
.addField('Topic', `\`${topic}\``)
.setFooter(channel.guild.name, channel.guild.iconURL())
);
if (config.tickets.pin)
await w.pin();
// await w.pin().then(m => m.delete()); // oopsie, this deletes the pinned message
if (config.logs.discord.enabled)
client.channels.cache.get(config.logs.discord.channel).send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(u.username, u.displayAvatarURL())
.setTitle('New ticket (via panel)')
.setDescription(`\`${topic}\``)
.addField('Creator', u, true)
.addField('Channel', c, true)
.setFooter(channel.guild.name, channel.guild.iconURL())
.setTimestamp()
);
log.info(`${u.tag} created a new ticket (#${name}) via panel`);
}).catch(log.error);
});
};

View File

@@ -8,10 +8,13 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const leeks = require('leeks.js');
const fetch = require('node-fetch');
const config = require('../../user/config');
let {version} = require('../../package.json');
version = 'v' + version;
const boxen = require('boxen');
const link = require('terminal-link');
module.exports = () => {
if(!config.updater)
@@ -21,11 +24,24 @@ module.exports = () => {
.then(res => res.json())
.then(json => {
const update = json[0];
let notice = [];
if (version !== update.tag_name) {
log.notice('There is an update available for Discord Tickets');
log.info(`Download "&f${update.name}&3" from &6https://github.com/eartharoid/DiscordTickets/releases/`);
log.notice(`You currently have ${version}; The latest is ${update.tag_name}`);
log.notice(log.f(`There is an update available for Discord Tickets (${version} -> ${update.tag_name})`));
notice.push(`&6You are currently using &c${version}&6, the latest is &a${update.tag_name}&6.`);
notice.push(`&6Download "&f${update.name}&6" from`);
notice.push(link('&6the GitHub releases page', 'https://github.com/eartharoid/DiscordTickets/releases/'));
console.log(
boxen(log.f(notice.join('\n')), {
padding: 1,
margin: 1,
align: 'center',
borderColor: 'yellow',
borderStyle: 'round'
})
);
}
});
};