Skip to content

Commit

Permalink
feat: support Bot API 7.10 (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf committed Sep 6, 2024
1 parent 6e19926 commit d93e2be
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 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.13.0",
"@grammyjs/types": "3.14.0",
"abort-controller": "^3.0.0",
"debug": "^4.3.4",
"node-fetch": "^2.7.0"
Expand Down
11 changes: 9 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export class Context implements RenamedUpdate {

// UPDATE SHORTCUTS

// Keep in sync with types in `filter.ts`.
/** Alias for `ctx.update.message` */
get message() {
return this.update.message;
Expand Down Expand Up @@ -494,6 +495,10 @@ export class Context implements RenamedUpdate {
get removedChatBoost() {
return this.update.removed_chat_boost;
}
/** Alias for `ctx.update.purchased_paid_media` */
get purchasedPaidMedia() {
return this.update.purchased_paid_media;
}

// AGGREGATION SHORTCUTS

Expand Down Expand Up @@ -549,7 +554,8 @@ export class Context implements RenamedUpdate {
* (this.chatBoost?.boost ?? this.removedChatBoost)?.source)?.user ??
* (this.callbackQuery ?? this.msg ?? this.inlineQuery ??
* this.chosenInlineResult ?? this.shippingQuery ?? this.preCheckoutQuery ??
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest)?.from`.
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest ??
* this.purchasedPaidMedia)?.from`.
*/
get from(): User | undefined {
// Keep in sync with types in `filter.ts`.
Expand All @@ -567,7 +573,8 @@ export class Context implements RenamedUpdate {
this.preCheckoutQuery ??
this.myChatMember ??
this.chatMember ??
this.chatJoinRequest
this.chatJoinRequest ??
this.purchasedPaidMedia
)?.from;
}

Expand Down
18 changes: 13 additions & 5 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ const COMMON_MESSAGE_KEYS = {
animation: {},
audio: {},
document: {},
paid_media: {},
photo: {},
sticker: STICKER_KEYS,
story: {},
Expand All @@ -282,7 +283,6 @@ const COMMON_MESSAGE_KEYS = {
poll: {},
venue: {},
location: {},
paid_media: {},

entities: ENTITY_KEYS,
caption_entities: ENTITY_KEYS,
Expand All @@ -296,9 +296,13 @@ const COMMON_MESSAGE_KEYS = {
delete_chat_photo: {},
message_auto_delete_timer_changed: {},
pinned_message: {},
chat_background_set: {},
invoice: {},
proximity_alert_triggered: {},
chat_background_set: {},
giveaway_created: {},
giveaway: { only_new_members: {}, has_public_winners: {} },
giveaway_winners: { only_new_members: {}, was_refunded: {} },
giveaway_completed: {},
video_chat_scheduled: {},
video_chat_started: {},
video_chat_ended: {},
Expand All @@ -308,8 +312,6 @@ const COMMON_MESSAGE_KEYS = {
const MESSAGE_KEYS = {
...COMMON_MESSAGE_KEYS,

sender_boost_count: {},

new_chat_members: USER_KEYS,
left_chat_member: USER_KEYS,
group_chat_created: {},
Expand All @@ -318,18 +320,20 @@ const MESSAGE_KEYS = {
migrate_from_chat_id: {},
successful_payment: {},
refunded_payment: {},
boost_added: {},
users_shared: {},
chat_shared: {},
connected_website: {},
write_access_allowed: {},
passport_data: {},
boost_added: {},
forum_topic_created: {},
forum_topic_edited: { name: {}, icon_custom_emoji_id: {} },
forum_topic_closed: {},
forum_topic_reopened: {},
general_forum_topic_hidden: {},
general_forum_topic_unhidden: {},

sender_boost_count: {},
} as const;
const CHANNEL_POST_KEYS = {
...COMMON_MESSAGE_KEYS,
Expand Down Expand Up @@ -373,6 +377,7 @@ const UPDATE_KEYS = {
message_reaction_count: MESSAGE_REACTION_COUNT_UPDATED_KEYS,
chat_boost: {},
removed_chat_boost: {},
purchased_paid_media: {},
} as const;

// === Build up all possible filter queries from the above validation structure
Expand Down Expand Up @@ -585,6 +590,9 @@ interface Shortcuts<U extends Update> {
removedChatBoost: [U["removed_chat_boost"]] extends [object]
? U["removed_chat_boost"]
: undefined;
purchasedPaidMedia: [U["purchased_paid_media"]] extends [object]
? U["purchased_paid_media"]
: undefined;
msg: [U["message"]] extends [object] ? U["message"]
: [U["edited_message"]] extends [object] ? U["edited_message"]
: [U["channel_post"]] extends [object] ? U["channel_post"]
Expand Down
4 changes: 2 additions & 2 deletions src/types.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
type InputPaidMediaVideo as InputPaidMediaVideoF,
type InputSticker as InputStickerF,
type Opts as OptsF,
} from "https://deno.land/x/grammy_types@v3.13.0/mod.ts";
} from "https://deno.land/x/grammy_types@v3.14.0/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/grammy_types@v3.13.0/mod.ts";
export * from "https://deno.land/x/grammy_types@v3.14.0/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 @@ -13,10 +13,10 @@ import {
type InputPaidMediaVideo as InputPaidMediaVideoF,
type InputSticker as InputStickerF,
type Opts as OptsF,
} from "https://deno.land/x/grammy_types@v3.13.0/mod.ts";
} from "https://deno.land/x/grammy_types@v3.14.0/mod.ts";

// === Export all API types
export * from "https://deno.land/x/grammy_types@v3.13.0/mod.ts";
export * from "https://deno.land/x/grammy_types@v3.14.0/mod.ts";

/** Something that looks like a URL. */
interface URLLike {
Expand Down

0 comments on commit d93e2be

Please sign in to comment.