From 1ff26006f718bc0d0398b92b744394db73381485 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Sat, 9 May 2026 18:20:00 +0100 Subject: [PATCH] chore(examples): use api.Ptr for optional pointer fields Replace the throwaway-local-var-then-take-address pattern with api.Ptr in the polls and moderation examples. Net effect: 14 lines gone, the pointer wrangling no longer steals visual focus from the actual API call. --- examples/moderation/main.go | 25 +++++++++++-------------- examples/polls/main.go | 3 +-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/moderation/main.go b/examples/moderation/main.go index 5f28386..ab107ae 100644 --- a/examples/moderation/main.go +++ b/examples/moderation/main.go @@ -96,11 +96,10 @@ func kickHandler(c *dispatch.Context, m *api.Message) error { }); err != nil { return handleAdminErr(c, m.Chat.ID, err) } - truVal := true if _, err := api.UnbanChatMember(c.Ctx, c.Bot, &api.UnbanChatMemberParams{ ChatID: api.ChatIDFromInt(m.Chat.ID), UserID: target, - OnlyIfBanned: &truVal, + OnlyIfBanned: api.Ptr(true), }); err != nil { log.Printf("unban after kick: %v", err) } @@ -130,23 +129,21 @@ func muteHandler(c *dispatch.Context, m *api.Message) error { reply(c, m.Chat.ID, "Reply to a user's message with /mute to silence them for 1 hour.") return nil } - until := time.Now().Add(time.Hour).Unix() - falseVal := false if _, err := api.RestrictChatMember(c.Ctx, c.Bot, &api.RestrictChatMemberParams{ ChatID: api.ChatIDFromInt(m.Chat.ID), UserID: target, Permissions: api.ChatPermissions{ - CanSendMessages: &falseVal, - CanSendAudios: &falseVal, - CanSendDocuments: &falseVal, - CanSendPhotos: &falseVal, - CanSendVideos: &falseVal, - CanSendVideoNotes: &falseVal, - CanSendVoiceNotes: &falseVal, - CanSendPolls: &falseVal, - CanSendOtherMessages: &falseVal, + CanSendMessages: api.Ptr(false), + CanSendAudios: api.Ptr(false), + CanSendDocuments: api.Ptr(false), + CanSendPhotos: api.Ptr(false), + CanSendVideos: api.Ptr(false), + CanSendVideoNotes: api.Ptr(false), + CanSendVoiceNotes: api.Ptr(false), + CanSendPolls: api.Ptr(false), + CanSendOtherMessages: api.Ptr(false), }, - UntilDate: &until, + UntilDate: api.Ptr(time.Now().Add(time.Hour).Unix()), }); err != nil { return handleAdminErr(c, m.Chat.ID, err) } diff --git a/examples/polls/main.go b/examples/polls/main.go index e58fb6a..baf7d99 100644 --- a/examples/polls/main.go +++ b/examples/polls/main.go @@ -94,12 +94,11 @@ func main() { }) return nil } - isAnon := false msg, err := api.SendPoll(c.Ctx, c.Bot, &api.SendPollParams{ ChatID: api.ChatIDFromInt(m.Chat.ID), Question: question, Options: pollOptions, - IsAnonymous: &isAnon, + IsAnonymous: api.Ptr(false), }) if err != nil { return err