|
1 | 1 | import { Command, CommandClient } from 'detritus-client';
|
2 |
| -import { Markup } from 'detritus-client/lib/utils'; |
3 | 2 |
|
4 |
| -import { imageInformationExif } from '../../../api'; |
5 |
| -import { RestResponsesRaw } from '../../../api/types'; |
6 |
| -import { CommandCategories, EmbedBrands, EmbedColors } from '../../../constants'; |
7 |
| -import { createUserEmbed, editOrReply, formatMemory, splitArray } from '../../../utils'; |
| 3 | +import { CommandCategories } from '../../../constants'; |
| 4 | +import { Formatter } from '../../../utils'; |
8 | 5 |
|
9 | 6 | import { BaseImageCommand } from '../basecommand';
|
10 | 7 |
|
11 | 8 |
|
12 |
| -export interface CommandArgsBefore { |
13 |
| - url?: null | string, |
14 |
| -} |
15 |
| - |
16 |
| -export interface CommandArgs { |
17 |
| - url: string, |
18 |
| -} |
19 |
| - |
20 | 9 | export const COMMAND_NAME = 'exif';
|
21 | 10 |
|
22 |
| -export default class ExifCommand extends BaseImageCommand<CommandArgs> { |
| 11 | +export default class ExifCommand extends BaseImageCommand { |
23 | 12 | constructor(client: CommandClient) {
|
24 | 13 | super(client, {
|
25 | 14 | name: COMMAND_NAME,
|
26 | 15 |
|
27 | 16 | metadata: {
|
| 17 | + category: CommandCategories.TOOLS, |
28 | 18 | description: 'Get exif information from an image',
|
29 | 19 | examples: [
|
30 | 20 | COMMAND_NAME,
|
31 | 21 | `${COMMAND_NAME} https://i.imgur.com/WwiO7Bx.jpg`,
|
32 | 22 | ],
|
33 |
| - category: CommandCategories.IMAGE, |
| 23 | + id: Formatter.Commands.ToolsExif.COMMAND_ID, |
34 | 24 | usage: '?<emoji,user:id|mention|name,url>',
|
35 | 25 | },
|
36 | 26 | });
|
37 | 27 | }
|
38 | 28 |
|
39 |
| - async run(context: Command.Context, args: CommandArgs) { |
40 |
| - const response = await imageInformationExif(context, args); |
41 |
| - const isGif = (response.information.mimetype === 'image/gif'); |
42 |
| - |
43 |
| - const embed = createUserEmbed(context.user); |
44 |
| - embed.setColor(EmbedColors.DEFAULT); |
45 |
| - embed.setFooter('Image Exif Information', EmbedBrands.NOTSOBOT); |
46 |
| - |
47 |
| - { |
48 |
| - const { information, metadata } = response; |
49 |
| - |
50 |
| - const description: Array<string> = []; |
51 |
| - description.push(`**Color Profile**: ${information.interpretation}`); |
52 |
| - description.push(`**Dimensions**: ${information.width}x${information.height}`); |
53 |
| - if (isGif) { |
54 |
| - description.push(`**Frames**: ${information.frames.toLocaleString()}`); |
55 |
| - description.push(`**Frame Delay**: ${information.delay.toLocaleString()}`); |
56 |
| - description.push(`**Loops**: ${(information.loop) ? 'Yes' : 'No'}`); |
57 |
| - } |
58 |
| - description.push(`**Mimetype**: ${information.mimetype}`); |
59 |
| - description.push(`**Size**: ${formatMemory(information.size)}`); |
60 |
| - |
61 |
| - if (metadata['gif-comment']) { |
62 |
| - description.push(''); |
63 |
| - description.push(`**Comment**`); |
64 |
| - description.push(Markup.codeblock(metadata['gif-comment'])) |
65 |
| - } |
66 |
| - |
67 |
| - embed.setDescription(description.join('\n')); |
68 |
| - } |
69 |
| - |
70 |
| - if (response.exif.length) { |
71 |
| - const exif = response.exif.map((field) => { |
72 |
| - field.name = field.name.split('-').pop() as string; |
73 |
| - return field; |
74 |
| - }).sort((x, y) => x.name.localeCompare(y.name)); |
75 |
| - |
76 |
| - const split = splitArray<any>(exif, 3); |
77 |
| - for (let i = 0; i < split.length; i++) { |
78 |
| - const fields = split[i]; |
79 |
| - const description: Array<string> = []; |
80 |
| - |
81 |
| - for (let field of fields) { |
82 |
| - let value: string; |
83 |
| - if (field.description === field.value) { |
84 |
| - value = field.value; |
85 |
| - } else { |
86 |
| - value = `${field.value} (${field.description})`; |
87 |
| - } |
88 |
| - if (value) { |
89 |
| - description.push(`**${field.name.split('-').pop()}**`); |
90 |
| - description.push(`-> ${value}`); |
91 |
| - } |
92 |
| - } |
93 |
| - |
94 |
| - const title = (!i) ? 'Exif Data' : '\u200b'; |
95 |
| - embed.addField(title, description.join('\n') || '\u200b', true); |
96 |
| - } |
97 |
| - if (response.url) { |
98 |
| - embed.setImage(response.url); |
99 |
| - } |
100 |
| - } else { |
101 |
| - if (response.url) { |
102 |
| - embed.setThumbnail(response.url); |
103 |
| - } |
104 |
| - } |
105 |
| - |
106 |
| - return editOrReply(context, {embed}); |
| 29 | + async run(context: Command.Context, args: Formatter.Commands.ToolsExif.CommandArgs) { |
| 30 | + return Formatter.Commands.ToolsExif.createMessage(context, args); |
107 | 31 | }
|
108 | 32 | }
|
0 commit comments