-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* padding fixes, dynamic voice channels * clean up deprecations * more details on template commands list templates command * lockfile, commands manifest * codacy cleanups
- Loading branch information
Tobiah
committed
Oct 2, 2018
1 parent
133a623
commit 0b433a1
Showing
19 changed files
with
431 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const Command = require('../../models/Command.js'); | ||
|
||
const relayRegex = new RegExp('--relay', 'ig'); | ||
|
||
class AddTemplateChannel extends Command { | ||
/** | ||
* Constructs a callable command | ||
* @param {Genesis} bot The bot object | ||
*/ | ||
constructor(bot) { | ||
super(bot, 'dynamicchannels.add', 'templates add', 'Add Template Channel'); | ||
this.regex = new RegExp(`^${this.call}\\s?(?:(?:<#)?(\\d+)(?:>)?)?(?:\\s+(--relay))?$`, 'i'); | ||
this.requiresAuth = true; | ||
this.allowDM = false; | ||
this.usages = [ | ||
{ | ||
description: 'Add a template channel. If `--relay` is specified, it will use relay naming.', | ||
parameters: ['channel mention', '--relay'], | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* Run the command | ||
* @param {Message} message Message with a command to handle, reply to, | ||
* or perform an action based on parameters. | ||
* @returns {string} success status | ||
*/ | ||
async run(message) { | ||
const newTemplateChannelId = message.strippedContent.match(this.regex)[1]; | ||
const isRelay = relayRegex.test(message.strippedContent); | ||
if (newTemplateChannelId && this.bot.client.channels.has(newTemplateChannelId.trim())) { | ||
const newTemplateChannel = this.bot.client.channels.get(newTemplateChannelId.trim()); | ||
await this.settings.addTemplate(newTemplateChannel, isRelay); | ||
this.messageManager.reply(message, `${newTemplateChannel} added as a template.`, true, true); | ||
return this.messageManager.statuses.SUCCESS; | ||
} | ||
return this.messageManager.statuses.FAILURE; | ||
} | ||
} | ||
|
||
module.exports = AddTemplateChannel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const Command = require('../../models/Command.js'); | ||
|
||
class DeleteTemplateChannel extends Command { | ||
/** | ||
* Constructs a callable command | ||
* @param {Genesis} bot The bot object | ||
*/ | ||
constructor(bot) { | ||
super(bot, 'dynamicchannels.delete', 'templates delete', 'Delete Template Channel'); | ||
this.regex = new RegExp(`^${this.call}\\s?(?:(?:<#)?(\\d+)(?:>)?)?$`, 'i'); | ||
this.requiresAuth = true; | ||
this.allowDM = false; | ||
this.usages = [ | ||
{ | ||
description: 'Remove a template channel', | ||
parameters: ['channel mention'], | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* Run the command | ||
* @param {Message} message Message with a command to handle, reply to, | ||
* or perform an action based on parameters. | ||
* @returns {string} success status | ||
*/ | ||
async run(message) { | ||
const templateId = message.strippedContent.match(this.regex)[1]; | ||
if (templateId && this.bot.client.channels.has(templateId.trim())) { | ||
const template = this.bot.client.channels.get(templateId.trim()); | ||
await this.settings.deleteTemplate(template); | ||
this.messageManager.reply(message, `${template} removed as a template.`, true, true); | ||
return this.messageManager.statuses.SUCCESS; | ||
} | ||
return this.messageManager.statuses.FAILURE; | ||
} | ||
} | ||
|
||
module.exports = DeleteTemplateChannel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
const rpad = require('right-pad'); | ||
|
||
const Command = require('../../models/Command.js'); | ||
const BaseEmbed = require('../../embeds/BaseEmbed'); | ||
|
||
class AddTemplateChannel extends Command { | ||
/** | ||
* Constructs a callable command | ||
* @param {Genesis} bot The bot object | ||
*/ | ||
constructor(bot) { | ||
super(bot, 'dynamicchannels.list', 'templates list', 'List Template Channels'); | ||
this.requiresAuth = true; | ||
this.allowDM = false; | ||
} | ||
|
||
/** | ||
* Run the command | ||
* @param {Message} message Message with a command to handle, reply to, | ||
* or perform an action based on parameters. | ||
* @returns {string} success status | ||
*/ | ||
async run(message) { | ||
const templateIds = await this.settings.getTemplates([message.guild]); | ||
const templates = []; | ||
templateIds.forEach((templateId) => { | ||
if (message.guild.channels.has(templateId)) { | ||
templates.push(message.guild.channels.get(templateId)); | ||
} | ||
}); | ||
const embed = new BaseEmbed(this.bot); | ||
const longestName = templates.length ? templates.map(template => template.name).reduce((a, b) => (a.length > b.length ? a : b)) : ''; | ||
embed.description = `\`${rpad('Template', longestName.length, '\u2003')} | ${'# ch'.padStart(5, '\u2003')} | # Empty\`\n`; | ||
embed.description += (await Promise.all(templates.map(async (template) => { | ||
const instancesRes = await this.settings.getInstances(template); | ||
return `\`${rpad(template.name, longestName.length, '\u2003')} | ${String(instancesRes.instances.length).padStart(5, '\u2003')} | ${String(instancesRes.remainingEmpty).padStart(7, '\u2003')}\``; | ||
}))).join('\n'); | ||
this.messageManager.embed(message, embed, true, true); | ||
return this.messageManager.statuses.SUCCESS; | ||
} | ||
} | ||
|
||
module.exports = AddTemplateChannel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.