Skip to content

Commit

Permalink
fix: adjust to docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf committed Dec 30, 2023
1 parent cf01155 commit 6bfadf8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"backport": "deno2node tsconfig.json"
},
"dependencies": {
"@grammyjs/types": "3.4.3",
"@grammyjs/types": "3.4.4",
"abort-controller": "^3.0.0",
"debug": "^4.3.4",
"node-fetch": "^2.7.0"
Expand Down
11 changes: 7 additions & 4 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const checker: StaticHas = {
} else if (reaction.type === "custom_emoji") {
for (const old of old_reaction) {
if (old.type !== "custom_emoji") continue;
if (old.custom_emoji === reaction.custom_emoji) {
if (old.custom_emoji_id === reaction.custom_emoji_id) {
isOld = true;
break;
}
Expand All @@ -239,7 +239,10 @@ const checker: StaticHas = {
} else if (reaction.type === "custom_emoji") {
for (const wanted of normalized) {
if (wanted.type !== "custom_emoji") continue;
if (wanted.custom_emoji === reaction.custom_emoji) {
if (
wanted.custom_emoji_id ===
reaction.custom_emoji_id
) {
return true;
}
}
Expand Down Expand Up @@ -614,15 +617,15 @@ export class Context implements RenamedUpdate {
if (reaction.type === "emoji") {
emoji.push(reaction.emoji);
} else if (reaction.type === "custom_emoji") {
customEmoji.push(reaction.custom_emoji);
customEmoji.push(reaction.custom_emoji_id);
}
}
// temporarily move all old emoji to the *Removed arrays
for (const reaction of old_reaction) {
if (reaction.type === "emoji") {
emojiRemoved.push(reaction.emoji);
} else if (reaction.type === "custom_emoji") {
customEmojiRemoved.push(reaction.custom_emoji);
customEmojiRemoved.push(reaction.custom_emoji_id);
}
}
// temporarily move all new emoji to the *Added arrays
Expand Down
4 changes: 2 additions & 2 deletions src/types.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
type InputMediaVideo as InputMediaVideoF,
type InputSticker as InputStickerF,
type Opts as OptsF,
} from "https://deno.land/x/[email protected].3/mod.ts";
} from "https://deno.land/x/[email protected].4/mod.ts";
import { debug as d, isDeno } from "./platform.deno.ts";

const debug = d("grammy:warn");

// === Export all API types
export * from "https://deno.land/x/[email protected].3/mod.ts";
export * from "https://deno.land/x/[email protected].4/mod.ts";

/** A value, or a potentially async function supplying that value */
type MaybeSupplier<T> = T | (() => T | Promise<T>);
Expand Down
4 changes: 2 additions & 2 deletions src/types.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
type InputMediaVideo as InputMediaVideoF,
type InputSticker as InputStickerF,
type Opts as OptsF,
} from "https://deno.land/x/[email protected].3/mod.ts";
} from "https://deno.land/x/[email protected].4/mod.ts";

// === Export all API types
export * from "https://deno.land/x/[email protected].3/mod.ts";
export * from "https://deno.land/x/[email protected].4/mod.ts";

/** Something that looks like a URL. */
interface URLLike {
Expand Down
27 changes: 15 additions & 12 deletions test/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ describe("Context", () => {
message_id: 2,
old_reaction: [
{ type: "emoji", emoji: "πŸŽ‰" },
{ type: "custom_emoji", custom_emoji: "id" },
{ type: "custom_emoji", custom_emoji_id: "id" },
],
new_reaction: [
{ type: "emoji", emoji: "πŸŽ‰" },
{ type: "custom_emoji", custom_emoji: "id" },
{ type: "custom_emoji", custom_emoji_id: "id" },
{ type: "emoji", emoji: "πŸ‘" },
],
},
Expand All @@ -283,7 +283,10 @@ describe("Context", () => {
assertFalse(Context.has.reaction("πŸ‘Ž")(ctx));
assertFalse(ctx.hasReaction("πŸ‘Ž"));

const added = { type: "custom_emoji" as const, custom_emoji: "id_new" };
const added = {
type: "custom_emoji" as const,
custom_emoji_id: "id_new",
};
up = {
update_id: 0,
message_reaction: {
Expand All @@ -292,11 +295,11 @@ describe("Context", () => {
message_id: 2,
old_reaction: [
{ type: "emoji", emoji: "πŸŽ‰" },
{ type: "custom_emoji", custom_emoji: "id" },
{ type: "custom_emoji", custom_emoji_id: "id" },
],
new_reaction: [
{ type: "emoji", emoji: "πŸŽ‰" },
{ type: "custom_emoji", custom_emoji: "id" },
{ type: "custom_emoji", custom_emoji_id: "id" },
added,
],
},
Expand Down Expand Up @@ -526,9 +529,9 @@ describe("Context", () => {
const ye = { type: "emoji", emoji: "πŸ‘" };
const no = { type: "emoji", emoji: "πŸ‘Ž" };
const ok = { type: "emoji", emoji: "πŸ‘Œ" };
const cye = { type: "custom_emoji", custom_emoji: "id-ye" };
const cno = { type: "custom_emoji", custom_emoji: "id-no" };
const cok = { type: "custom_emoji", custom_emoji: "id-ok" };
const cye = { type: "custom_emoji", custom_emoji_id: "id-ye" };
const cno = { type: "custom_emoji", custom_emoji_id: "id-no" };
const cok = { type: "custom_emoji", custom_emoji_id: "id-ok" };
let up = {
message_reaction: {
old_reaction: [ye, no, cye, cno],
Expand All @@ -550,10 +553,10 @@ describe("Context", () => {
assertEquals(emojiRemoved, [ye.emoji]);
assertEquals(emojiKept, [no.emoji]);
assertEquals(emojiAdded, [ok.emoji]);
assertEquals(customEmoji, [cok.custom_emoji, cno.custom_emoji]);
assertEquals(customEmojiRemoved, [cye.custom_emoji]);
assertEquals(customEmojiKept, [cno.custom_emoji]);
assertEquals(customEmojiAdded, [cok.custom_emoji]);
assertEquals(customEmoji, [cok.custom_emoji_id, cno.custom_emoji_id]);
assertEquals(customEmojiRemoved, [cye.custom_emoji_id]);
assertEquals(customEmojiKept, [cno.custom_emoji_id]);
assertEquals(customEmojiAdded, [cok.custom_emoji_id]);

up = { message: update.message } as Update;
ctx = new Context(up, api, me);
Expand Down

0 comments on commit 6bfadf8

Please sign in to comment.