Skip to content

Commit

Permalink
feat(bot): liben can now shift the blame
Browse files Browse the repository at this point in the history
  • Loading branch information
lastarc committed May 10, 2024
1 parent d74d68f commit d9a8242
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
15 changes: 15 additions & 0 deletions bot/blame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param client {import('discord.js').Client}
* @param channelId {import('discord.js').Message['id']}
*/
const onCommandFail = async (client, channelId) => {
const WHO_TO_BLAME = process.env.WHO_TO_BLAME;
if (!WHO_TO_BLAME) return;
const HEHE_EMOJI = process.env.HEHE_EMOJI || '';

const channel = await client.channels.cache.get(channelId);
if (!channel) return;
await channel.send(`${WHO_TO_BLAME} is to blame ${HEHE_EMOJI}`);
};

module.exports = { onCommandFail };
2 changes: 2 additions & 0 deletions bot/commands/media/instagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require('node:fs');
const S3 = require('../../s3');
const crypto = require('crypto');
const EmbedProxyClient = require('../../embed-proxy-client');
const { onCommandFail } = require('../../blame');

const S3_BUCKET_NAME = process.env.S3_BUCKET_NAME;
if (!S3_BUCKET_NAME) throw new Error('No bucket name provided');
Expand Down Expand Up @@ -62,6 +63,7 @@ module.exports = {
} catch (e) {
console.error(e);
await replyMsg.edit('Error downloading video');
await onCommandFail(interaction.client, interaction.channelId);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions bot/commands/media/tiktok.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require('node:fs');
const S3 = require('../../s3');
const crypto = require('crypto');
const EmbedProxyClient = require('../../embed-proxy-client');
const { onCommandFail } = require('../../blame');

const S3_BUCKET_NAME = process.env.S3_BUCKET_NAME;
if (!S3_BUCKET_NAME) throw new Error('No bucket name provided');
Expand Down Expand Up @@ -62,6 +63,7 @@ module.exports = {
} catch (e) {
console.error(e);
await replyMsg.edit('Error downloading video');
await onCommandFail(interaction.client, interaction.channelId);
return;
}

Expand Down
6 changes: 4 additions & 2 deletions bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const dotenv = require('dotenv');
const path = require('node:path');
const fs = require('node:fs');
const { onCommandFail } = require('./blame');

dotenv.config();

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

Expand Down Expand Up @@ -84,14 +86,14 @@ client.on(Events.MessageCreate, async message => {
switch (true) {
case tiktokVideoUrlMatch !== null:
return client.emit(Events.InteractionCreate, {
isChatInputCommand: () => true, client: client, commandName: 'tiktok', options: {
isChatInputCommand: () => true, client: client, channelId: message.channelId, commandName: 'tiktok', options: {
getString: () => tiktokVideoUrlMatch[0],
getBoolean: () => force,
}, reply: message.reply.bind(message),
});
case instagramVideoUrlMatch !== null:
return client.emit(Events.InteractionCreate, {
isChatInputCommand: () => true, client: client, commandName: 'instagram', options: {
isChatInputCommand: () => true, client: client, channelId: message.channelId, commandName: 'instagram', options: {
getString: () => instagramVideoUrlMatch[0],
getBoolean: () => force,
}, reply: message.reply.bind(message),
Expand Down

0 comments on commit d9a8242

Please sign in to comment.