Skip to content

Commit

Permalink
Changed configuration to have autoClose be configured per category (#121
Browse files Browse the repository at this point in the history
)

* Changed configuration to have autoclose be configured per category.

* Added option to disable pinging of support roles.

* Update support roles for bug type.
  • Loading branch information
McJeffr authored Mar 3, 2021
1 parent b7398b9 commit 7ca3296
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 27 deletions.
30 changes: 22 additions & 8 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,42 @@ module.exports = {
},
support: {
category: '740654285154549901',
automaticDeletion: 3600000,
types: {
'minez': {
description: "Support for MineZ: Stuck in a block; Broken dungeons; Death due to cheaters, bugs, and broken dungeons.",
roles: ['618856455206076417']
roles: [{ id: '618856455206076417', ping: true }],
logRoom: '748963030888349736',
autoClose: {
warning: ONE_DAY_IN_MS,
closing: 2 * ONE_DAY_IN_MS
}
},
'abuse': {
description: "Open a private chat with the leadership team to report staff abuse.",
roles: ['440505209580683274', '441611057878794240'],
roles: [
{ id: '440505209580683274', ping: true },
{ id: '441611057878794240', ping: true }
],
logRoom: '748963030888349736',
autoClose: {
warning: ONE_DAY_IN_MS,
closing: 2 * ONE_DAY_IN_MS
}
},
'bug': {
description: "Open a support channel to report a bug to the development team.",
roles: [
{ id: '223821346763833344', ping: false },
{ id: '815871997871128576', ping: true }
],
logRoom: '748963030888349736'
}
},
autoClose: {
warning: ONE_DAY_IN_MS,
closing: 2 * ONE_DAY_IN_MS
}
},
nitro: {
channel: '585535847110017028',
manualUpgradeStaffer: 'Navarr'
},
supportCategory: 'Support',
messageRemoveDelay: 60000,
pingspam: {
threshold: 5,
Expand Down
26 changes: 15 additions & 11 deletions src/Command/Support.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ module.exports = Command.extend({
return message.channel.send(this.i18n.__mf(messages.notASupportRoom));
}

if (!RoleDeterminer.hasOneOfRoles(message.member, this.config.support.types[typeKey].roles)) {
const roleIds = this.config.support.types[typeKey].roles.map(role => role.id);
if (!RoleDeterminer.hasOneOfRoles(message.member, roleIds)) {
return message.channel.send(this.i18n.__mf(messages.noPermission));
}

Expand Down Expand Up @@ -108,8 +109,8 @@ module.exports = Command.extend({
VIEW_CHANNEL: true
}))
.then(async channel => {
for (const supportRoleId of type.roles) {
await channel.updateOverwrite(supportRoleId, {
for (const supportRole of type.roles) {
await channel.updateOverwrite(supportRole.id, {
ADD_REACTIONS: true,
ATTACH_FILES: true,
EMBED_LINKS: true,
Expand All @@ -124,8 +125,9 @@ module.exports = Command.extend({
})
.catch(() => {
/* If something went wrong with room creation, we delete it (if it was created) and notify the user */
supportChannel.delete().catch(() => {
});
if (supportChannel) {
supportChannel.delete().catch(() => {});
}
return message.channel.send(this.i18n.__mf(messages.roomCreationError));
});

Expand All @@ -136,19 +138,20 @@ module.exports = Command.extend({
}));

/* Add the collector to deal with post-creation events */
this.addCollector(supportChannel, message.member, welcomeMessage);
this.addCollector(supportChannel, type, message.member, welcomeMessage);

await supportChannel.send(this.i18n.__mf(messages.supportRules));
return message.channel.send(this.i18n.__mf(messages.roomCreated, {type: typeKey}));
},
addCollector: function (supportChannel, creator, welcomeMessage) {
addCollector: function (supportChannel, supportType, creator, welcomeMessage) {
const collectorFilter = (message) => message.member.id === creator.id;

const automaticDelete = this.config.support.automaticDeletion;

let collector;
if (automaticDelete < 0) {
if (!supportType.autoClose || !supportType.autoClose.closing
|| supportType.autoClose.closing < 0) {
collector = supportChannel.createMessageCollector(collectorFilter);
} else {
const automaticDelete = supportType.autoClose.closing;
collector = supportChannel.createMessageCollector(collectorFilter,
{time: automaticDelete});
collector.on('end', async (_, reason) => {
Expand All @@ -161,7 +164,8 @@ module.exports = Command.extend({
collector.once('collect', (message) => {
const supportType = parseRoomType(supportChannel.name);
const supportRoles = this.config.support.types[supportType].roles
.map(supportRole => `<@&${supportRole}>`)
.filter(supportRole => supportRole.ping)
.map(supportRole => `<@&${supportRole.id}>`)
.join(', ');

message.channel.send(this.i18n.__mf(messages.supportMessageReceived, {roles: supportRoles}));
Expand Down
8 changes: 4 additions & 4 deletions src/Helper/SupportRoomConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ const convertRoom = async (message, tokens, i18n) => {
}

/* Remove old support roles and add new ones */
for (const supportRoleId of oldType.roles) {
await supportRoom.permissionOverwrites.get(supportRoleId)
for (const supportRole of oldType.roles) {
await supportRoom.permissionOverwrites.get(supportRole.id)
.delete('Support room type conversion')
.catch((e) => {
console.log(e)
});
}
for (const supportRoleId of newType.roles) {
await supportRoom.updateOverwrite(supportRoleId, {
for (const supportRole of newType.roles) {
await supportRoom.updateOverwrite(supportRole.id, {
ADD_REACTIONS: true,
ATTACH_FILES: true,
EMBED_LINKS: true,
Expand Down
8 changes: 6 additions & 2 deletions src/Utility/SupportCloser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const BotModule = require('../BotModule');
const archiveRoom = require('../Helper/SupportRoomArchiver');
const parseRoomType = require('../Helper/SupportRoomTypeParser');

const messages = {
'warning': 'It appears that there was no activity in this room for a while. If no more activity takes place, I will automatically close this channel.'
Expand Down Expand Up @@ -36,8 +37,10 @@ module.exports = BotModule.extend({
const now = this.moment();

/* Check if we should send a warning notice */
const typeKey = parseRoomType(supportRoom.name);
let messageTimestamp = this.moment(lastMessage.createdTimestamp);
if (now.isAfter(messageTimestamp.add(this.config.support.autoClose.warning, 'ms'))
if (this.config.support.types[typeKey].autoClose && this.config.support.types[typeKey].autoClose.warning
&& now.isAfter(messageTimestamp.add(this.config.support.types[typeKey].autoClose.warning, 'ms'))
&& lastMessage.content !== messages.warning) {
supportRoom.send(this.i18n.__mf(messages.warning, {timeInactivity: 0, timeToClose: 0}));
return;
Expand All @@ -46,7 +49,8 @@ module.exports = BotModule.extend({
/* Check if we should close the channel (moment mutates the timestamp, hence the re-init) */
messageTimestamp = this.moment(lastMessage.createdTimestamp);
if (lastMessage.content === messages.warning
&& now.isAfter(messageTimestamp.add(this.config.support.autoClose.closing, 'ms'))) {
&& this.config.support.types[typeKey].autoClose && this.config.support.types[typeKey].autoClose.closing
&& now.isAfter(messageTimestamp.add(this.config.support.types[typeKey].autoClose.closing, 'ms'))) {
await archiveRoom(lastMessage, this.i18n, this.discordClient);
}
});
Expand Down
2 changes: 0 additions & 2 deletions src/Utility/TrickcordTreat.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = BotModule.extend({
this.timeout = typeof this.config.trickcordTreatDeleteTime != 'undefined' ?
this.config.trickcordTreatDeleteTime :
ONE_MINUTE_IN_MS;

console.log(this.config.trickcordTreatRoom);
},

/**
Expand Down

0 comments on commit 7ca3296

Please sign in to comment.