Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhooks #131

Merged
merged 9 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ process.on('unhandledRejection', (err) => {
const nexusOptions = {
user_key: process.env.NEXUSSTATS_USER_KEY || undefined,
user_secret: process.env.NEXUSSTATS_USER_SECRET || undefined,
api_url: process.env.NEXUS_API_OVERRIDE || undefined,
auth_url: process.env.NEXUS_AUTH_OVERRIDE || undefined,
ignore_limiter: true,
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"pad-left": "^2.1.0",
"ping": "^0.2.2",
"raven": "^2.1.2",
"request-promise": "^4.2.1",
"request-promise": "^4.2.2",
"right-pad": "^1.0.1",
"sql-template-strings": "^2.2.2",
"warframe-location-query": "0.0.3",
Expand All @@ -53,7 +53,7 @@
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.6.0",
"ink-docstrap": "^1.3.0",
"jsdoc": "^3.5.4",
"jsdoc": "^3.5.5",
"mocha": "^3.5.3",
"rewire": "^2.5.2",
"sinon": "^1.17.6",
Expand Down
28 changes: 14 additions & 14 deletions src/CommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CommandHandler {
return null;
}
})
.filter(c => c !== null);
.filter(c => c !== null);

this.commands = commands.filter(c => !c.isInline);

Expand All @@ -94,16 +94,16 @@ class CommandHandler {
async handleCommand(message) {
let content = message.content;
const botping = `@${message.guild ?
message.guild.members.get(this.bot.client.user.id).displayName :
this.bot.client.user.username}`;
message.guild.members.get(this.bot.client.user.id).displayName :
this.bot.client.user.username}`;
const botPingId = `<@${this.bot.client.user.id}>`;
const { prefix, allowCustom, allowInline } = await this.bot.settings
const ctx = await this.bot.settings
.getCommandContext(message.channel);
let checkOnlyInlines = false;
const notStartWithPrefix = !content.startsWith(prefix)
const notStartWithPrefix = !content.startsWith(ctx.prefix)
&& !content.startsWith(botping) && !content.startsWith(botPingId);
if (notStartWithPrefix) {
if (allowInline && this.inlineCommands.length > 0) {
if (ctx.allowInline && this.inlineCommands.length > 0) {
checkOnlyInlines = true;
} else {
return;
Expand All @@ -113,14 +113,14 @@ class CommandHandler {
let commands = [];
if (checkOnlyInlines) {
commands = this.inlineCommands;
} else if (allowCustom) {
} else if (ctx.allowCustom) {
commands = this.commands.concat(this.customCommands);
} else {
commands = this.commands;
}

if (content.startsWith(prefix)) {
content = content.replace(prefix, '');
if (content.startsWith(ctx.prefix)) {
content = content.replace(ctx.prefix, '');
}
if (content.startsWith(botping)) {
content = content.replace(new RegExp(`${botping}\\s+`, 'i'), '');
Expand All @@ -135,13 +135,14 @@ class CommandHandler {
commands.forEach(async (command) => {
if (command.regex.test(content) && !done) {
const canAct = await this.checkCanAct(command, messageWithStrippedContent,
allowCustom, allowInline);
ctx.allowCustom, ctx.allowInline);
if (canAct) {
this.logger.debug(`Matched ${command.id}`);
const status = await command.run(messageWithStrippedContent);
const canReact = message && (message.channel.type === 'dm' ||
ctx.message = messageWithStrippedContent;
const status = await command.run(messageWithStrippedContent, ctx);
const canReact = (message.channel.type === 'dm' ||
(message.channel.permissionsFor(this.bot.client.user.id)
.has(['ADD_REACTIONS', 'VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS']))) && !command.isInline;
.has(['ADD_REACTIONS', 'VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS']))) && !command.isInline;
switch (status) {
case this.statuses.SUCCESS:
if (canReact) {
Expand All @@ -156,7 +157,6 @@ class CommandHandler {
case this.statuses.NO_ACCESS:
default:
break;

}
done = true;
}
Expand Down
40 changes: 20 additions & 20 deletions src/Tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
const request = require('request-promise');

const config = {
updateInterval: process.env.TRACKERS_UPDATE_INTERVAL || 3660000,
carbon: {
token: process.env.DISCORD_CARBON_TOKEN,
},
botsDiscordPw: {
token: process.env.DISCORD_BOTS_WEB_TOKEN,
id: process.env.DISCORD_BOTS_WEB_USER,
},
cachet: {
metricId: process.env.CACHET_BOT_METRIC_ID,
host: process.env.CACHET_HOST,
token: process.env.CACHET_TOKEN,
heartbeat: process.env.CACHET_HEARTBEAT || 600000,
},
botsDiscordOrg: {
token: process.env.DISCORD_BOTS_ORG_TOKEN,
id: process.env.DISCORD_BOTS_ORG_ID
},
updateInterval: process.env.TRACKERS_UPDATE_INTERVAL || 3660000,
carbon: {
token: process.env.DISCORD_CARBON_TOKEN,
},
botsDiscordPw: {
token: process.env.DISCORD_BOTS_WEB_TOKEN,
id: process.env.DISCORD_BOTS_WEB_USER,
},
cachet: {
metricId: process.env.CACHET_BOT_METRIC_ID,
host: process.env.CACHET_HOST,
token: process.env.CACHET_TOKEN,
heartbeat: process.env.CACHET_HEARTBEAT || 600000,
},
botsDiscordOrg: {
token: process.env.DISCORD_BOTS_ORG_TOKEN,
id: process.env.DISCORD_BOTS_ORG_ID,
},
};

/**
Expand Down Expand Up @@ -116,8 +116,8 @@ class Tracker {
this.logger.error(`Error updating bots.discord.pw. Token: ${config.botsDiscordPw.token} | User: ${config.botsDiscordPw.id} | Error Code: ${err.statusCode}`);
}
}
}
}

/**
* Updates discordbots.org if the corresponding token is provided
* @param {number} guildsLen number of guilds that this bot is present on
Expand Down
8 changes: 7 additions & 1 deletion src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ class Genesis {

this.channelTimeout = 300000;

/**
* Discord.js API
* @type {Discord}
*/
this.discord = Discord;

/**
* The logger object
* @type {Logger}
Expand Down Expand Up @@ -375,7 +381,7 @@ class Genesis {
.replace(/\$username/ig, guildMember.displayName)
.replace(/\$usermention/ig, guildMember)
.replace(/\$timestamp/ig, new Date().toLocaleString()),
false, false);
false, false);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Builds/AddBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AddBuild extends Command {
const matches = message.strippedContent.match(this.regex)[1];
const params = (matches || '').split('|');
if (params.length < 1) {
// let them know there's not enough params
// let them know there's not enough params
return this.messageManager.statuses.FAILURE;
}
// save params based on order
Expand Down
16 changes: 8 additions & 8 deletions src/commands/Builds/SetField.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ class AddBuild extends Command {
let image;
if (build && (build.owner_id === message.author.id || message.author.id === this.bot.owner)) {
if (type === 'all') {
title = params[1];
body = params[2];
image = params[3];
[, title, body, image] = params;
} else if (type === 'title') {
title = params[1];
[, title] = params;
} else if (type === 'body') {
body = params[1];
[, body] = params;
} else if (type === 'image') {
image = params[1];
[, image] = params;
} else {
return this.failure(message, buildId);
}
Expand All @@ -55,8 +53,10 @@ class AddBuild extends Command {
// save params based on order
const status = await this.bot.settings.setBuildFields(buildId, { title, body, image });
if (status) {
this.messageManager.embed(message, new BuildEmbed(this.bot,
await this.bot.settings.getBuild(buildId)), true, true);
this.messageManager.embed(message, new BuildEmbed(
this.bot,
await this.bot.settings.getBuild(buildId),
), true, true);
return this.messageManager.statuses.SUCCESS;
}
return this.failure(message, buildId);
Expand Down
56 changes: 28 additions & 28 deletions src/commands/Core/Help.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Help extends Command {
this.sendCoreEmbed(message, prefix);
if (message.channel.type === 'dm' ||
message.channel
.permissionsFor(message.author)
.has('MANAGE_ROLES_OR_PERMISSIONS')) {
.permissionsFor(message.author)
.has('MANAGE_ROLES_OR_PERMISSIONS')) {
this.sendSettingsEmbed(message, prefix);
}
this.sendWorldStateEmbed(message, prefix);
Expand All @@ -52,56 +52,56 @@ class Help extends Command {

sendHelpEmbed(message, prefix) {
const commands = this.commandHandler.commands.filter(c =>
!c.ownerOnly &&
!c.ownerOnly &&
!/core/ig.test(c.id) &&
!(/warframe/ig.test(c.id)) &&
!/settings/ig.test(c.id))
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
}
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
}
)));
this.sendEmbedForCommands(message, commands, 'Help!', 0x00ff00);
}

sendOwnerOnlyEmbed(message, prefix) {
const ownerCommands = this.commandHandler.commands.filter(c => c.ownerOnly)
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
})));
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
})));
this.sendEmbedForCommands(message, ownerCommands, 'Owner Only', 0xff0000);
}

sendCoreEmbed(message, prefix) {
const commands = this.commandHandler.commands.filter(c => !c.ownerOnly && /core/ig.test(c.id))
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
})));
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
})));
this.sendEmbedForCommands(message, commands, 'Core Commands', 0x000000);
}

sendWorldStateEmbed(message, prefix) {
const commands = this.commandHandler.commands.filter(c => !c.ownerOnly && /warframe.worldstate/ig.test(c.id))
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
})));
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
})));
this.sendEmbedForCommands(message, commands, 'Warframe Commands - Worldstate', 0x4068BD);
}

sendWarframeEmbed(message, prefix) {
const commands = this.commandHandler.commands.filter(c => !c.ownerOnly && /warframe.(?!worldstate)/ig.test(c.id))
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
})));
.map(c => c.usages.map(u => ({
name: `${prefix}${c.call} ${u.parameters.map(p => `<${p}>`).join(u.separator ? u.separator : ' ')}`,
value: u.description,
inline: false,
})));
this.sendEmbedForCommands(message, commands, 'Warframe Commands - Utility', 0x4068BD);
}

Expand Down
3 changes: 2 additions & 1 deletion src/commands/Core/Ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class Ping extends Command {
title: 'PONG',
type: 'rich',
fields: [
{ name: `Response time (shard ${this.bot.shardId + 1} of ${this.bot.shardCount})`,
{
name: `Response time (shard ${this.bot.shardId + 1} of ${this.bot.shardCount})`,
value: `${afterSend - now}ms`,
},
...results,
Expand Down
6 changes: 4 additions & 2 deletions src/commands/Ondemand/Armor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class Armor extends Command {
armorString = this.armorSimple(parseInt(armor, 10));
} else {
this.logger.debug('Entered 3-param armor');
armorString = this.armorFull(parseFloat(armor), parseFloat(baseLevel),
parseFloat(currentLevel));
armorString = this.armorFull(
parseFloat(armor), parseFloat(baseLevel),
parseFloat(currentLevel),
);
}

const embed = {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/Ondemand/EarthCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class EarthCycle extends Command {
* @returns {string} success status
*/
async run(message) {
const ws = await this.bot.caches.pc.getDataJson()
await this.messageManager.embed(message, new EarthCycleEmbed(this.bot, ws.earthCycle), true, true);
const ws = await this.bot.caches.pc.getDataJson();
const embed = new EarthCycleEmbed(this.bot, ws.earthCycle);
await this.messageManager.embed(message, embed, true, true);
return this.messageManager.statuses.SUCCESS;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/commands/Ondemand/Efficiency.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ class Efficiency extends Command {
* @returns {string} success status
*/
async run(message) {
this.messageManager.sendFile(message,
`Operator ${message.author.toString()}, the efficiency table, at your request.`,
this.efficiencyChart, 'efficiency.png', true);
this.messageManager.sendFile(
message,
`Operator ${message.author.toString()}, the efficiency table, at your request.`,
this.efficiencyChart, 'efficiency.png', true,
);
return this.messageManager.statuses.SUCCESS;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/Mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Mod extends Command {
return this.messageManager.statuses.FAILURE;
}
const searchJson = await warframe.getSearchList({ query, limit: 1 });
const id = searchJson.items[0].id;
const { item: { id } } = searchJson.items;
const detailsJson = await warframe.getArticleDetails({ ids: [id] });
let thumbUrl = detailsJson.items[`${id}`].thumbnail;
thumbUrl = thumbUrl ? thumbUrl.replace(/\/revision\/.*/, '') : 'https://i.imgur.com/11VCxbq.jpg';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/Pricecheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PriceCheck extends Command {
const sentMessage = await message.channel.send('', { embed: inProgressEmbed });
const result = await this.bot.nexusQuerier.priceCheckQueryAttachment(item);
const embed = new PriceCheckEmbed(this.bot, result, item);
sentMessage.edit('', { embed });
sentMessage.edit('', { embed });
return embed.color === 0xff55ff ?
this.messageManager.statuses.FAILURE : this.messageManager.statuses.SUCCESS;
} catch (error) {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/Ondemand/Raid.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ class Raid extends Command {
const platform = await this.bot.settings.getChannelSetting(message.channel, 'platform');
const url = encodeURI(`https://api.trials.wf/api/player/${platform.toLowerCase()}/${query}/completed`);
const data = await (new Fetcher(url)).httpGet();
this.messageManager.embed(message, new RaidEmbed(this.bot,
data, query, platform.toLowerCase()), true, true);
this.messageManager.embed(message, new RaidEmbed(
this.bot,
data, query, platform.toLowerCase(),
), true, true);
return this.messageManager.statuses.SUCCESS;
}
}
Expand Down
Loading