Skip to content

Commit

Permalink
Dynamic voice (#231)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 19 changed files with 431 additions and 23 deletions.
2 changes: 1 addition & 1 deletion commands.json

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"raven": "^2.6.3",
"request-promise": "^4.2.2",
"right-pad": "^1.0.1",
"sql-template-strings": "^2.2.2"
"sql-template-strings": "^2.2.2",
"warframe-name-generator": "^1.0.0"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
3 changes: 2 additions & 1 deletion src/EventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const fs = require('fs');
const path = require('path');
const decache = require('decache');
const BaseEventHandler = require('./models/BaseEventHandler');

/**
* Describes a CommandHandler for a bot.
Expand Down Expand Up @@ -52,7 +53,7 @@ class EventHandler {
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
const Handler = require(path.join(handlersDir, f));
if (Object.prototype.toString.call(Handler) === '[object Function]') {
if (Handler.prototype instanceof BaseEventHandler) {
const handler = new Handler(this.bot);

this.logger.debug(`Adding ${handler.id}`);
Expand Down
44 changes: 44 additions & 0 deletions src/commands/DynamicChannels/AddTemplateChannel.js
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;
41 changes: 41 additions & 0 deletions src/commands/DynamicChannels/DeleteTemplateChannel.js
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;
45 changes: 45 additions & 0 deletions src/commands/DynamicChannels/ListTemplateChannels.js
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;
2 changes: 1 addition & 1 deletion src/commands/Promocodes/AddPromocode.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class AddPromocode extends Command {

const longestName = codes.map(pool => pool.id)
.reduce((a, b) => (a.length > b.length ? a : b)).length;
const addedCodeLines = codes.map(code => `+ ${rpad(code.id, Number(longestName + 1), ' ')}| ${rpad(String(code.platform.toUpperCase()), 4, ' ')}| ${code.code}`);
const addedCodeLines = codes.map(code => `+ ${rpad(code.id, Number(longestName + 1), '\u2003')}| ${rpad(String(code.platform.toUpperCase()), 4, '\u2003')}| ${code.code}`);
response = await appendIfResponse(message, response, this.messageManager, `\\✅ Importing ${addedCodeLines.length}`);
codes.forEach((code) => {
code.adder = message.author.id; // eslint-disable-line no-param-reassign
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Promocodes/ListPools.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class ListPools extends Command {
color: 0xd30000,
fields: poolGroup.map(group => ({
name: '\u200B',
value: group.map(pool => `\`${rpad(pool.pool_id, longestId.length, ' ')} `
+ `| ${rpad(pool.name, longestName.length, ' ')} | ${pool.len}\``).join('\n'),
value: group.map(pool => `\`${rpad(pool.pool_id, longestId.length, '\u2003')} `
+ `| ${rpad(pool.name, longestName.length, '\u2003')} | ${pool.len}\``).join('\n'),
})),
};
pages.push(embed);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Roles/RoleIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Roles extends Command {
});
const longest = roles.map(role => role.name)
.reduce((a, b) => (a.length > b.length ? a : b));
const roleGroups = createGroupedArray(roles.map(role => `\`${rpad(role.name, longest.length, ' ')} ${role.id}\``), 6);
const roleGroups = createGroupedArray(roles.map(role => `\`${rpad(role.name, longest.length, '\u2003')} ${role.id}\``), 6);
const metaGroups = createGroupedArray(roleGroups, 4);
const embeds = [];
metaGroups.forEach((metaGroup) => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Rooms/Create.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Create extends Command {
if (useable.includes(roomType)) {
const users = getUsersForCall(message);
const name = optName || `${type}-${message.member.displayName}`.toLowerCase();
if (users.length < 11 && !message.guild.channels.find('name', name)) {
if (users.length < 11 && !message.guild.channels.find(channel => channel.name === name)) {
const overwrites = this.createOverwrites({
users,
everyone: message.guild.defaultRole,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Utilities/GetCommandIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class GetCommandIds extends Command {
commands = commands
.filter(command => !command.ownerOnly
|| (message.author.id === this.bot.owner && command.ownerOnly))
.map(command => `${rpad(command.call, longestCall.length, ' ')} `
+ `| ${rpad(command.id, longestId.length, ' ')} | ${command.blacklistable ? '✓' : '✗'}`);
.map(command => `${rpad(command.call, longestCall.length, '\u2003')} `
+ `| ${rpad(command.id, longestId.length, '\u2003')} | ${command.blacklistable ? '✓' : '✗'}`);

const pages = [];
createGroupedArray(commands, 12).forEach((group) => {
Expand Down
2 changes: 1 addition & 1 deletion src/embeds/RolesEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RolesEmbed extends BaseEmbed {
roleGroups.forEach((roleGroup) => {
this.fields.push({
name: '\u200B',
value: `\`\`\`${roleGroup.map(role => `${rpad(role.guildRole.name, Number(longest + 2), ' ')}${rpad(String(role.guildRole.members.size), 4, ' ')} members`).join(' \n')}\`\`\``,
value: `\`\`\`${roleGroup.map(role => `${rpad(role.guildRole.name, Number(longest + 2), '\u2003')}${rpad(String(role.guildRole.members.size), 4, '\u2003')} members`).join(' \n')}\`\`\``,
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/embeds/WhatsinEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class WhatsinEmbed extends BaseEmbed {
const reward = transformedRewards[rewardName];
const qualities = [];
reward.forEach((quality) => {
const wrappedQuality = lpad(`${quality.toFixed(2)}`, 6, ' ').substring(0, 5);
const wrappedQuality = lpad(`${quality.toFixed(2)}`, 6, '\u2003').substring(0, 5);
qualities.push(wrappedQuality);
});
tokens.push(`${rpad(rewardName, longest.length + 1, ' ')} ${qualities.join('/')}%`);
tokens.push(`${rpad(rewardName, longest.length + 1, '\u2003')} ${qualities.join('/')}%`);
});


Expand Down
4 changes: 2 additions & 2 deletions src/embeds/WhereisEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class WhereisEmbed extends BaseEmbed {
this.fields = [];

resultsGroups.forEach((results) => {
const mappedResults = results.map(result => `\`${rpad(result.item, nameWidth, ' ')} `
+ `| ${rpad(result.place, relicWidth, ' ')} | ${result.rarity.charAt(0)}@${parseFloat(result.chance).toFixed(2)}%\``);
const mappedResults = results.map(result => `\`${rpad(result.item, nameWidth, '\u2003')} `
+ `| ${rpad(result.place, relicWidth, '\u2003')} | ${result.rarity.charAt(0)}@${parseFloat(result.chance).toFixed(2)}%\``);
this.fields.push({ name: '\u200B', value: mappedResults.join('\n') });
});

Expand Down
Loading

0 comments on commit 0b433a1

Please sign in to comment.