Skip to content

Commit

Permalink
fix: check for webhook insert having invalid values, closes #297
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobiah committed Jan 26, 2020
1 parent 3277b81 commit 4c31912
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion commands.json

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions src/settings/DatabaseQueries/SettingsQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ class SettingsQueries {
}

async setChannelWebhook(channel, webhook) {
const query = SQL`INSERT INTO settings (channel_id, setting, val)
VALUES (${channel.id}, 'webhookId', ${webhook.id}),
(${channel.id}, 'webhookToken', ${webhook.token}),
(${channel.id}, 'webhookName', ${webhook.name}),
(${channel.id}, 'webhookAvatar', ${webhook.avatar})
ON DUPLICATE KEY UPDATE
val = Values(val)`;

return this.db.query(query);
if (webhook.id && webhook.token && webhook.name && webhook.avatar) {
const query = SQL`INSERT INTO settings (channel_id, setting, val)
VALUES (${channel.id}, 'webhookId', ${webhook.id}),
(${channel.id}, 'webhookToken', ${webhook.token}),
(${channel.id}, 'webhookName', ${webhook.name}),
(${channel.id}, 'webhookAvatar', ${webhook.avatar})
ON DUPLICATE KEY UPDATE
val = Values(val)`;

return this.db.query(query);
}
return false;
}

async getChannelWebhook(channel) {
Expand Down
6 changes: 5 additions & 1 deletion src/settings/MessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ class MessaageManager {
.replace('?size=2048', '');

// Make this one query
await this.settings.setChannelWebhook(ctx.channel, webhook);
const success = await this.settings.setChannelWebhook(ctx.channel, webhook);
if (!success) {
this.logger.error(`Could not finish adding webhook for ${ctx.channel}`);
return false;
}
// eslint-disable-next-line no-param-reassign
ctx.webhook = webhook;
return this.webhook(ctx, { text, embed });
Expand Down

0 comments on commit 4c31912

Please sign in to comment.