Skip to content

Commit ce3798a

Browse files
committed
Add /tools screenshot slash command
1 parent 3b5b33b commit ce3798a

File tree

7 files changed

+56
-6
lines changed

7 files changed

+56
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"dependencies": {
1111
"@sentry/node": "^6.4.1",
12-
"detritus-client": "^0.16.4-beta.4",
12+
"detritus-client": "^0.16.4-beta.5",
1313
"emoji-aware": "^3.0.5",
1414
"juration": "^0.1.1",
1515
"moment": "^2.29.1",

src/commands/interactions/slash/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BaseSlashCommand } from '../../basecommand';
22

33
import { ToolsHashCommand } from './hash';
4+
import { ToolsScreenshotCommand } from './screenshot';
45

56

67
export default class ToolsGroupCommand extends BaseSlashCommand {
@@ -11,6 +12,7 @@ export default class ToolsGroupCommand extends BaseSlashCommand {
1112
super({
1213
options: [
1314
new ToolsHashCommand(),
15+
new ToolsScreenshotCommand(),
1416
],
1517
});
1618
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Interaction } from 'detritus-client';
2+
3+
import { Formatter, Parameters } from '../../../../utils';
4+
5+
import { BaseInteractionCommandOption } from '../../basecommand';
6+
7+
8+
export class ToolsScreenshotCommand extends BaseInteractionCommandOption {
9+
description = 'Screenshot a website';
10+
name = 'screenshot';
11+
12+
constructor() {
13+
super({
14+
options: [
15+
{
16+
name: 'url',
17+
description: 'URL to screenshot',
18+
required: true,
19+
value: Parameters.url,
20+
},
21+
],
22+
});
23+
}
24+
25+
async run(context: Interaction.InteractionContext, args: Formatter.Commands.ToolsScreenshot.CommandArgs) {
26+
return Formatter.Commands.ToolsScreenshot.createMessage(context, args);
27+
}
28+
}

src/commands/prefixed/tools/screenshot.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Command, CommandClient } from 'detritus-client';
22

3-
import { utilitiesScreenshot } from '../../../api';
43
import { CommandTypes } from '../../../constants';
5-
import { Parameters, imageReply } from '../../../utils';
4+
import { Formatter, Parameters } from '../../../utils';
65

76
import { BaseCommand } from '../basecommand';
87

@@ -37,7 +36,6 @@ export default class ScreenshotCommand extends BaseCommand<CommandArgs> {
3736
}
3837

3938
async run(context: Command.Context, args: CommandArgs) {
40-
const response = await utilitiesScreenshot(context, args);
41-
return imageReply(context, response);
39+
return Formatter.Commands.ToolsScreenshot.createMessage(context, args);
4240
}
4341
}

src/utils/formatter/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import * as ToolsHash from './tools.hash';
3636
import * as ToolsOCR from './tools.ocr';
3737
import * as ToolsOCRTranslate from './tools.ocrtranslate';
3838
import * as ToolsQrScan from './tools.qr.scan';
39+
import * as ToolsScreenshot from './tools.screenshot';
3940
import * as ToolsTranslate from './tools.translate';
4041

4142
export {
@@ -72,5 +73,6 @@ export {
7273
ToolsOCR,
7374
ToolsOCRTranslate,
7475
ToolsQrScan,
76+
ToolsScreenshot,
7577
ToolsTranslate,
7678
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Command, Interaction } from 'detritus-client';
2+
3+
import { utilitiesScreenshot } from '../../../api';
4+
import { imageReply } from '../../../utils';
5+
6+
7+
export interface CommandArgs {
8+
url: string,
9+
}
10+
11+
export async function createMessage(
12+
context: Command.Context | Interaction.InteractionContext,
13+
args: CommandArgs,
14+
) {
15+
const response = await utilitiesScreenshot(context, args);
16+
return imageReply(context, response);
17+
}

src/utils/parameters/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ export async function imageUrl(
711711
return url;
712712
}
713713
}
714+
return null;
714715
}
715716
}
716717

@@ -841,9 +842,10 @@ export async function lastImageUrls(
841842
const url = findImageUrlInMessages([message]);
842843
if (url) {
843844
urls.add(url);
844-
found = true;
845845
}
846846
}
847+
// ignore this url no matter what
848+
found = true;
847849
}
848850
}
849851

@@ -942,6 +944,7 @@ export async function imageUrlPositional(
942944
return url;
943945
}
944946
}
947+
return null;
945948
}
946949
}
947950

0 commit comments

Comments
 (0)