|
| 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 | +} |
0 commit comments