Skip to content

Commit 9ca9995

Browse files
committed
Add .badmeme
1 parent 1ce2f03 commit 9ca9995

File tree

10 files changed

+116
-33
lines changed

10 files changed

+116
-33
lines changed

src/api/endpoints.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ export const Api = Object.freeze({
215215
'/search/google/images',
216216
SEARCH_GOOGLE_REVERSE_IMAGES:
217217
'/search/google/reverse-images',
218+
SEARCH_IMGUR:
219+
'/search/imgur',
220+
SEARCH_IMGUR_HOME:
221+
'/search/imgur/home',
218222
SEARCH_REDDIT:
219223
'/search/reddit',
220224
SEARCH_RULE34:

src/api/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,14 @@ export async function searchGoogleReverseImages(
987987
}
988988

989989

990+
export async function searchImgur(
991+
context: RequestContext,
992+
options: RestOptions.SearchImgur,
993+
) {
994+
return raw.searchImgur(context, options);
995+
}
996+
997+
990998
export async function searchReddit(
991999
context: RequestContext,
9921000
options: RestOptions.SearchReddit,

src/api/raw.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,23 @@ export async function searchGoogleReverseImages(
20672067
}
20682068

20692069

2070+
export async function searchImgur(
2071+
context: RequestContext,
2072+
options: RestOptions.SearchImgur,
2073+
): Promise<RestResponsesRaw.SearchImgur> {
2074+
const query = {
2075+
query: options.query,
2076+
};
2077+
return request(context, {
2078+
query,
2079+
route: {
2080+
method: HTTPMethods.GET,
2081+
path: Api.SEARCH_IMGUR,
2082+
},
2083+
});
2084+
}
2085+
2086+
20702087
export async function searchReddit(
20712088
context: RequestContext,
20722089
options: RestOptions.SearchReddit,

src/api/types.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ export namespace RestOptions {
377377
url: string,
378378
}
379379

380+
export interface SearchImgur {
381+
query: string,
382+
}
383+
380384
export interface SearchReddit {
381385
maxResults?: number,
382386
query: string,
@@ -1006,6 +1010,19 @@ export namespace RestResponsesRaw {
10061010
urls: Array<{text: string, url: string}>,
10071011
}
10081012

1013+
export interface SearchImgurResult {
1014+
dislikes: number,
1015+
id: string,
1016+
likes: number,
1017+
points: number,
1018+
thumbnail: string,
1019+
type: string,
1020+
url: string,
1021+
views: number,
1022+
}
1023+
1024+
export type SearchImgur = Array<SearchImgurResult>;
1025+
10091026
export type SearchRule34 = Array<SearchRule34Result>;
10101027
export interface SearchRule34Result {
10111028
created_at: string,

src/commands/prefixed/image/badmeme.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Command, CommandClient } from 'detritus-client';
2+
3+
import { CommandCategories } from '../../../constants';
4+
import { Formatter } from '../../../utils';
5+
6+
import { BaseSearchCommand } from '../basecommand';
7+
8+
9+
export const COMMAND_NAME = 'badmeme';
10+
11+
export default class BadMemeCommand extends BaseSearchCommand {
12+
constructor(client: CommandClient) {
13+
super(client, {
14+
name: COMMAND_NAME,
15+
16+
metadata: {
17+
category: CommandCategories.SEARCH,
18+
description: 'Show a Bad Meme',
19+
examples: [
20+
COMMAND_NAME,
21+
],
22+
id: Formatter.Commands.SearchBadMeme.COMMAND_ID,
23+
usage: '',
24+
},
25+
});
26+
}
27+
28+
onBeforeRun(context: Command.Context, args: Formatter.Commands.SearchBadMeme.CommandArgs) {
29+
return true;
30+
}
31+
32+
run(context: Command.Context, args: Formatter.Commands.SearchBadMeme.CommandArgs) {
33+
return Formatter.Commands.SearchBadMeme.createMessage(context, args);
34+
}
35+
}

src/commands/prefixed/search/urban.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class UrbanCommand extends BaseSearchCommand<Formatter.Commands.S
2020
`${COMMAND_NAME} notsobot`,
2121
],
2222
id: Formatter.Commands.SearchUrban.COMMAND_ID,
23-
usage: '<query>',
23+
usage: '?<query>',
2424
},
2525
priority: -1,
2626
});

src/commands/prefixed/settings/prefixes.clear.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class PrefixesClearCommand extends BaseCommand {
2323
COMMAND_NAME,
2424
],
2525
id: Formatter.Commands.PrefixesClear.COMMAND_ID,
26-
usage: `${COMMAND_NAME}`,
26+
usage: '',
2727
},
2828
permissionsClient: [Permissions.EMBED_LINKS],
2929
permissions: [Permissions.MANAGE_GUILD],

src/utils/formatter/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import * as ReminderDelete from './reminder.delete';
7373
import * as ReminderListUser from './reminder.list.user';
7474

7575
import * as Search4Chan from './search.4chan';
76+
import * as SearchBadMeme from './search.badmeme';
7677
import * as SearchDiscordEmojis from './search.discord.emojis';
7778
import * as SearchGoogleImages from './search.google.images';
7879
import * as SearchGoogleWeb from './search.google.web';
@@ -185,6 +186,7 @@ export {
185186
ReminderListUser,
186187

187188
Search4Chan,
189+
SearchBadMeme,
188190
SearchDiscordEmojis,
189191
SearchGoogleImages,
190192
SearchGoogleWeb,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Command, Interaction } from 'detritus-client';
2+
import { Embed, Markup } from 'detritus-client/lib/utils';
3+
import { RequestTypes } from 'detritus-client-rest';
4+
5+
import { searchImgur } from '../../../api';
6+
import { RestResponsesRaw } from '../../../api/types';
7+
import { DiscordEmojis, EmbedBrands, EmbedColors } from '../../../constants';
8+
import { DefaultParameters, Paginator, createUserEmbed, editOrReply, shuffleArray } from '../../../utils';
9+
10+
11+
export const COMMAND_ID = 'search.badmeme';
12+
13+
export interface CommandArgs {
14+
15+
}
16+
17+
export async function createMessage(
18+
context: Command.Context | Interaction.InteractionContext,
19+
args: CommandArgs,
20+
) {
21+
const isFromInteraction = (context instanceof Interaction.InteractionContext);
22+
23+
const results = shuffleArray<RestResponsesRaw.SearchImgurResult>(await searchImgur(context, {query: 'meme'}));
24+
if (results.length) {
25+
const embed = (isFromInteraction) ? new Embed() : createUserEmbed(context.user);
26+
embed.setColor(EmbedColors.DEFAULT);
27+
embed.setThumbnail(results[0].thumbnail);
28+
return editOrReply(context, {embed});
29+
}
30+
return editOrReply(context, 'Couldn\'t find any bad memes');
31+
}

0 commit comments

Comments
 (0)