Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* add `/series` as alias to `/search`

* indicate party members in `/coll`
  • Loading branch information
ker0olos authored Jul 31, 2023
1 parent fd521bb commit 415e187
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 216 deletions.
42 changes: 42 additions & 0 deletions __snapshots__/update_commands.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,48 @@ snapshot[`commands 1`] = `
],
type: undefined,
},
{
default_member_permissions: undefined,
description: "Search for a specific media",
dm_permission: false,
name: "series",
options: [
{
autocomplete: true,
choices: undefined,
description: "The title of the media",
max_value: undefined,
min_value: undefined,
name: "title",
options: undefined,
required: true,
type: 3,
},
{
autocomplete: undefined,
choices: undefined,
description: "Display the nerdy stuff",
max_value: undefined,
min_value: undefined,
name: "debug",
options: undefined,
required: false,
type: 5,
},
{
autocomplete: undefined,
choices: undefined,
description: "View the characters from the media",
max_value: undefined,
min_value: undefined,
name: "characters",
options: undefined,
required: false,
type: 5,
},
],
type: undefined,
},
{
default_member_permissions: undefined,
description: "Search for a specific character",
Expand Down
35 changes: 27 additions & 8 deletions assets/embeds.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const emotes = {
add: '<:add:1099004747123523644>',
all: '<:all:1107511909999181824>',
liked: '<:liked:1110491720375873567>',
member: '<:partymember:1135706921312206921>',
alive: '<:alive:1128724907245711452>',
outOfHP: '<:outofhp:1131872032456446053>',
outOfSta: '<:outofstamina:1128724910609551481>',
Expand Down
4 changes: 2 additions & 2 deletions src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function pages(
new discord.Embed()
.setAuthor({ name: 'Roadmap' })
.setDescription([
'__**Releasing in the near future (5 days ~ 2 months)**__',
'__**Releasing in the near future (~3 months)**__',
'',
'**[Battles](https://github.com/ker0olos/fable/issues/74)**',
'',
Expand All @@ -187,7 +187,7 @@ function pages(
'- `/pull` `/guaranteed`: _use the guaranteed pulls you have_',
'',
'- `/now` `/vote` `/tu`: _check what you can do right now_',
'- `/search` `/anime` `/manga`: _search for specific media_',
'- `/search` `/anime` `/manga` `/series`: _search for specific media_',
'- `/character` `/char`: _search for a specific character_',
'',
'- `/merge` `/synthesize`: _merge characters together to pull a new character_',
Expand Down
4 changes: 3 additions & 1 deletion src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const handler = async (r: Request) => {
'anime',
'manga',
'media',
'series',
'found',
'owned',
'likeall',
Expand Down Expand Up @@ -276,7 +277,8 @@ export const handler = async (r: Request) => {
case 'search':
case 'anime':
case 'manga':
case 'media': {
case 'media':
case 'series': {
const title = options['title'] as string;

if (options['characters']) {
Expand Down
17 changes: 12 additions & 5 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,19 @@ function list({
nick?: boolean;
}): discord.Message {
user.getUserCharacters({ userId, guildId })
.then(async ({ characters, likes }) => {
.then(async ({ characters, party, likes }) => {
const embed = new discord.Embed();

const message = new discord.Message();

const members = [
party?.member1?.id,
party?.member2?.id,
party?.member3?.id,
party?.member4?.id,
party?.member5?.id,
];

let media: Media[] = [];

if (rating) {
Expand Down Expand Up @@ -1076,10 +1084,9 @@ function list({
: undefined;

const name = `${existing.rating}${discord.emotes.smolStar}${
likes?.some((like) =>
like.characterId === existing.id ||
like.mediaId === existing.mediaId
)
members?.some((member) => member === existing.id)
? discord.emotes.member
: likes?.some((like) => like.characterId === existing.id)
? `${discord.emotes.liked}`
: ''
} ${existing.nickname ?? utils.wrap(packs.aliasToArray(char.name)[0])}`;
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/help.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ snapshot[`/help 6`] = `
author: {
name: "Roadmap",
},
description: "__**Releasing in the near future (5 days ~ 2 months)**__
description: "__**Releasing in the near future (~3 months)**__
" +
"
" +
Expand Down Expand Up @@ -540,7 +540,7 @@ snapshot[`/help 7`] = `
" +
"- \`/now\` \`/vote\` \`/tu\`: _check what you can do right now_
" +
"- \`/search\` \`/anime\` \`/manga\`: _search for specific media_
"- \`/search\` \`/anime\` \`/manga\` \`/series\`: _search for specific media_
" +
"- \`/character\` \`/char\`: _search for a specific character_
" +
Expand Down
81 changes: 81 additions & 0 deletions tests/handler.commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,87 @@ Deno.test('search command handlers', async (test) => {
}
});

await test.step('series', async () => {
const body = JSON.stringify({
id: 'id',
token: 'token',
type: discord.InteractionType.Command,
guild_id: 'guild_id',

data: {
name: 'series',
options: [{
name: 'title',
value: 'title',
}],
},
});

const validateStub = stub(utils, 'validateRequest', () => ({} as any));

const signatureStub = stub(utils, 'verifySignature', ({ body }) => ({
valid: true,
body,
} as any));

const searchStub = stub(search, 'media', () => ({
send: () => true,
} as any));

config.publicKey = 'publicKey';

try {
const request = new Request('http://localhost:8000', {
body,
method: 'POST',
headers: {
'X-Signature-Ed25519': 'ed25519',
'X-Signature-Timestamp': 'timestamp',
},
});

const response = await handler(request);

assertSpyCall(validateStub, 0, {
args: [
request,
{
POST: {
headers: ['X-Signature-Ed25519', 'X-Signature-Timestamp'],
},
},
],
});

assertSpyCall(signatureStub, 0, {
args: [{
body,
signature: 'ed25519',
timestamp: 'timestamp',
publicKey: 'publicKey',
}],
});

assertSpyCall(searchStub, 0, {
args: [{
token: 'token',
guildId: 'guild_id',
search: 'title',
debug: false,
id: undefined,
}],
});

assertEquals(response, true as any);
} finally {
delete config.publicKey;

searchStub.restore();
validateStub.restore();
signatureStub.restore();
}
});

await test.step('debug', async () => {
const body = JSON.stringify({
id: 'id',
Expand Down
Loading

0 comments on commit 415e187

Please sign in to comment.