Skip to content

Commit d9a8242

Browse files
committed
feat(bot): liben can now shift the blame
1 parent d74d68f commit d9a8242

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

bot/blame.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param client {import('discord.js').Client}
3+
* @param channelId {import('discord.js').Message['id']}
4+
*/
5+
const onCommandFail = async (client, channelId) => {
6+
const WHO_TO_BLAME = process.env.WHO_TO_BLAME;
7+
if (!WHO_TO_BLAME) return;
8+
const HEHE_EMOJI = process.env.HEHE_EMOJI || '';
9+
10+
const channel = await client.channels.cache.get(channelId);
11+
if (!channel) return;
12+
await channel.send(`${WHO_TO_BLAME} is to blame ${HEHE_EMOJI}`);
13+
};
14+
15+
module.exports = { onCommandFail };

bot/commands/media/instagram.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fs = require('node:fs');
55
const S3 = require('../../s3');
66
const crypto = require('crypto');
77
const EmbedProxyClient = require('../../embed-proxy-client');
8+
const { onCommandFail } = require('../../blame');
89

910
const S3_BUCKET_NAME = process.env.S3_BUCKET_NAME;
1011
if (!S3_BUCKET_NAME) throw new Error('No bucket name provided');
@@ -62,6 +63,7 @@ module.exports = {
6263
} catch (e) {
6364
console.error(e);
6465
await replyMsg.edit('Error downloading video');
66+
await onCommandFail(interaction.client, interaction.channelId);
6567
return;
6668
}
6769

bot/commands/media/tiktok.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fs = require('node:fs');
55
const S3 = require('../../s3');
66
const crypto = require('crypto');
77
const EmbedProxyClient = require('../../embed-proxy-client');
8+
const { onCommandFail } = require('../../blame');
89

910
const S3_BUCKET_NAME = process.env.S3_BUCKET_NAME;
1011
if (!S3_BUCKET_NAME) throw new Error('No bucket name provided');
@@ -62,6 +63,7 @@ module.exports = {
6263
} catch (e) {
6364
console.error(e);
6465
await replyMsg.edit('Error downloading video');
66+
await onCommandFail(interaction.client, interaction.channelId);
6567
return;
6668
}
6769

bot/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
22
const dotenv = require('dotenv');
33
const path = require('node:path');
44
const fs = require('node:fs');
5+
const { onCommandFail } = require('./blame');
56

67
dotenv.config();
78

@@ -55,6 +56,7 @@ client.on(Events.InteractionCreate, async interaction => {
5556
} else {
5657
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
5758
}
59+
await onCommandFail(client, interaction.channelId);
5860
}
5961
});
6062

@@ -84,14 +86,14 @@ client.on(Events.MessageCreate, async message => {
8486
switch (true) {
8587
case tiktokVideoUrlMatch !== null:
8688
return client.emit(Events.InteractionCreate, {
87-
isChatInputCommand: () => true, client: client, commandName: 'tiktok', options: {
89+
isChatInputCommand: () => true, client: client, channelId: message.channelId, commandName: 'tiktok', options: {
8890
getString: () => tiktokVideoUrlMatch[0],
8991
getBoolean: () => force,
9092
}, reply: message.reply.bind(message),
9193
});
9294
case instagramVideoUrlMatch !== null:
9395
return client.emit(Events.InteractionCreate, {
94-
isChatInputCommand: () => true, client: client, commandName: 'instagram', options: {
96+
isChatInputCommand: () => true, client: client, channelId: message.channelId, commandName: 'instagram', options: {
9597
getString: () => instagramVideoUrlMatch[0],
9698
getBoolean: () => force,
9799
}, reply: message.reply.bind(message),

0 commit comments

Comments
 (0)