generated from vexuas/djs-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
53 lines (51 loc) · 1.58 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { APIEmbed, hyperlink, SlashCommandBuilder } from 'discord.js';
import { isEmpty, reduce } from 'lodash';
import { WaifuSchema } from '../../schemas/waifu';
import { getWaifu } from '../../services/adapters';
import { sendErrorLog } from '../../utils/helpers';
import { AppCommand, AppCommandOptions } from '../commands';
export const generateGifEmbed = (data: WaifuSchema): APIEmbed => {
const color = parseInt(data.dominant_color.replace('#', '0x'));
const tags = reduce(
data.tags,
(accumulator, value) => {
return `${accumulator}${isEmpty(accumulator) ? '' : ', '}${value.name}`;
},
''
);
const orientation: 'Portrait' | 'Landscape' = data.width > data.height ? 'Landscape' : 'Portrait';
const embed: APIEmbed = {
color,
description: `${hyperlink('Source', data.source)} | ${hyperlink('Preview', data.preview_url)}`,
image: {
url: data.url,
},
fields: [
{
name: 'Orientation',
value: orientation,
inline: true,
},
{
name: 'Tags',
value: tags,
inline: true,
},
],
};
return embed;
};
export default {
commandType: 'Waifu',
data: new SlashCommandBuilder().setName('gif').setDescription('Shows a random waifu gif'),
async execute({ interaction }: AppCommandOptions) {
try {
await interaction.deferReply();
const data = await getWaifu({ isGif: true });
const embed = generateGifEmbed(data);
await interaction.editReply({ embeds: [embed] });
} catch (error) {
sendErrorLog({ error, interaction });
}
},
} as AppCommand;