Skip to content

Commit b391998

Browse files
committed
Added retro command
1 parent bc9dcc1 commit b391998

File tree

8 files changed

+118
-18
lines changed

8 files changed

+118
-18
lines changed

src/api/endpoints.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export const Api = Object.freeze({
6161
'/image/create/:height:x:width:/colors/:hex:.:format:',
6262
IMAGE_CREATE_COLOR_RGB:
6363
'/image/create/:height:x:width:/colors/:red:.:green:.:blue:.:format:',
64+
IMAGE_CREATE_RETROWAVE:
65+
'/image/create/retrowave',
6466
IMAGE_CREATE_TOMBSTONE:
6567
'/image/create/tombstone',
6668
IMAGE_CREATE_WORDCLOUD:

src/api/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ export async function googleTranslate(
400400
}
401401

402402

403+
export async function imageCreateRetrowave(
404+
context: RequestContext,
405+
options: RestOptions.ImageCreateRetrowave,
406+
) {
407+
return raw.imageCreateRetrowave(context, options);
408+
}
409+
410+
403411
export async function imageCreateTombstone(
404412
context: RequestContext,
405413
options: RestOptions.ImageCreateTombstone,

src/api/raw.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,28 @@ export async function googleTranslate(
711711
}
712712

713713

714+
export async function imageCreateRetrowave(
715+
context: RequestContext,
716+
options: RestOptions.ImageCreateRetrowave,
717+
): Promise<Response> {
718+
const query = {
719+
background: options.background,
720+
line_1: options.line1,
721+
line_2: options.line2,
722+
line_3: options.line3,
723+
text_style: options.textStyle,
724+
};
725+
return request(context, {
726+
dataOnly: false,
727+
query,
728+
route: {
729+
method: HTTPMethods.POST,
730+
path: Api.IMAGE_CREATE_RETROWAVE,
731+
},
732+
});
733+
}
734+
735+
714736
export async function imageCreateTombstone(
715737
context: RequestContext,
716738
options: RestOptions.ImageCreateTombstone,

src/api/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ export namespace RestOptions {
177177
model?: string,
178178
}
179179

180+
export interface ImageCreateRetrowave {
181+
background?: number,
182+
line1?: string,
183+
line2?: string,
184+
line3?: string,
185+
textStyle?: number,
186+
}
187+
180188
export interface ImageCreateTombstone {
181189
line1?: string,
182190
line2?: string,

src/commands/prefixed/image/meme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class MemeCommand extends BaseImageCommand<Formatter.Commands.Ima
2020

2121
metadata: {
2222
category: CommandCategories.IMAGE,
23+
description: 'Add Meme Text to an Image',
2324
examples: [
2425
COMMAND_NAME,
2526
`${COMMAND_NAME} notsobot what an idiot`,
Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
11
import { Command, CommandClient } from 'detritus-client';
22

33
import { CommandCategories } from '../../../constants';
4+
import { Formatter } from '../../../utils';
45

5-
import { BaseImageCommand } from '../basecommand';
6+
import { BaseCommand } from '../basecommand';
67

78

8-
export interface CommandArgsBefore {
9-
type?: string,
10-
url?: null | string,
11-
}
12-
13-
export interface CommandArgs {
14-
type?: string,
15-
url: string,
16-
}
17-
189
export const COMMAND_NAME = 'retro';
1910

20-
export default class RetroCommand extends BaseImageCommand<CommandArgs> {
11+
export default class RetroCommand extends BaseCommand {
2112
constructor(client: CommandClient) {
2213
super(client, {
2314
name: COMMAND_NAME,
2415

2516
args: [
26-
{name: 'type'},
17+
{name: 'type', label: 'background'},
2718
],
19+
label: 'text',
2820
metadata: {
21+
category: CommandCategories.IMAGE,
2922
examples: [
3023
COMMAND_NAME,
3124
`${COMMAND_NAME} notsobot`,
32-
`${COMMAND_NAME} notsobot -type 2`,
25+
`${COMMAND_NAME} line1 | line2 | line3 -type 2`,
3326
],
34-
category: CommandCategories.IMAGE,
35-
usage: '?<emoji,user:id|mention|name,url> (-type <retro-type>)',
27+
id: Formatter.Commands.ImageCreateRetrowave.COMMAND_ID,
28+
usage: '?<text> (-type <retro-type>)',
3629
},
3730
});
3831
}
3932

40-
async run(context: Command.Context, args: CommandArgs) {
41-
33+
async run(context: Command.Context, args: Formatter.Commands.ImageCreateRetrowave.CommandArgs) {
34+
return Formatter.Commands.ImageCreateRetrowave.createMessage(context, args);
4235
}
4336
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Command, Interaction, Structures } from 'detritus-client';
2+
3+
import { imageCreateRetrowave } from '../../../api';
4+
import { RestOptions } from '../../../api/types';
5+
import { imageReply } from '../../../utils';
6+
7+
8+
export const COMMAND_ID = 'image.create.retrowave';
9+
10+
export interface CommandArgs {
11+
background?: number,
12+
text: string,
13+
textStyle?: number,
14+
}
15+
16+
export async function createMessage(
17+
context: Command.Context | Interaction.InteractionContext,
18+
args: CommandArgs,
19+
) {
20+
let parts: Array<string>;
21+
if (args.text.includes('|')) {
22+
parts = args.text.split('|');
23+
} else {
24+
if (15 <= args.text.length) {
25+
parts = [];
26+
for (let i = 0; i < args.text.length; i += 15) {
27+
parts.push(args.text.slice(i, i + 15));
28+
}
29+
} else {
30+
const split = args.text.split(' ');
31+
if (split.length === 1) {
32+
parts = ['', split[0]];
33+
} else if (1 < split.length && split.length <= 3) {
34+
parts = split;
35+
} else {
36+
parts = args.text.split('');
37+
if (parts.length === 4) {
38+
parts[2] = parts[2] + parts.pop()!;
39+
}
40+
}
41+
}
42+
}
43+
44+
if (context instanceof Command.Context) {
45+
for (let i in parts) {
46+
parts[i] = Structures.messageSystemContent(context.message, parts[i]!);
47+
}
48+
}
49+
50+
const query: RestOptions.ImageCreateRetrowave = {
51+
background: args.background,
52+
line1: '',
53+
line2: '',
54+
line3: '',
55+
textStyle: args.textStyle,
56+
};
57+
58+
for (let i = 0; i < Math.min(parts.length, 3); i++) {
59+
(query as any)[`line${i + 1}`] = parts[i];
60+
}
61+
62+
const response = await imageCreateRetrowave(context, query);
63+
return imageReply(context, response);
64+
}

src/utils/formatter/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as ImageBackgroundRemove from './image.background.remove';
1313
import * as ImageBlur from './image.blur';
1414
import * as ImageBlurple from './image.blurple';
1515
import * as ImageCircle from './image.circle';
16+
import * as ImageCreateRetrowave from './image.create.retrowave';
1617
import * as ImageDeepfry from './image.deepfry';
1718
import * as ImageExplode from './image.explode';
1819
import * as ImageFlip from './image.flip';
@@ -115,6 +116,7 @@ export {
115116
ImageBlur,
116117
ImageBlurple,
117118
ImageCircle,
119+
ImageCreateRetrowave,
118120
ImageDeepfry,
119121
ImageExplode,
120122
ImageFlip,

0 commit comments

Comments
 (0)