-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new filters for handling payment-related updates
- Loading branch information
1 parent
e73a363
commit d687362
Showing
6 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package shippingquery | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/PaulSonOfLars/gotgbot/v2" | ||
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers/filters" | ||
) | ||
|
||
func All(_ *gotgbot.PreCheckoutQuery) bool { | ||
return true | ||
} | ||
|
||
func FromUserID(id int64) filters.PreCheckoutQuery { | ||
return func(p *gotgbot.PreCheckoutQuery) bool { | ||
return p.From.Id == id | ||
} | ||
} | ||
|
||
func HasPayloadPrefix(pre string) filters.PreCheckoutQuery { | ||
return func(p *gotgbot.PreCheckoutQuery) bool { | ||
return strings.HasPrefix(p.InvoicePayload, pre) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package shippingquery | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/PaulSonOfLars/gotgbot/v2" | ||
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers/filters" | ||
) | ||
|
||
func All(_ *gotgbot.ShippingQuery) bool { | ||
return true | ||
} | ||
|
||
func FromUserID(id int64) filters.ShippingQuery { | ||
return func(p *gotgbot.ShippingQuery) bool { | ||
return p.From.Id == id | ||
} | ||
} | ||
|
||
func HasPayloadPrefix(pre string) filters.ShippingQuery { | ||
return func(p *gotgbot.ShippingQuery) bool { | ||
return strings.HasPrefix(p.InvoicePayload, pre) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/PaulSonOfLars/gotgbot/v2" | ||
"github.com/PaulSonOfLars/gotgbot/v2/ext" | ||
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers/filters" | ||
) | ||
|
||
type PreCheckoutQuery struct { | ||
Filter filters.PreCheckoutQuery | ||
Response Response | ||
} | ||
|
||
func NewPreCheckoutQuery(f filters.PreCheckoutQuery, r Response) PreCheckoutQuery { | ||
return PreCheckoutQuery{ | ||
Filter: f, | ||
Response: r, | ||
} | ||
} | ||
|
||
func (r PreCheckoutQuery) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool { | ||
if ctx.PollAnswer == nil { | ||
return false | ||
} | ||
return r.Filter == nil || r.Filter(ctx.PreCheckoutQuery) | ||
} | ||
|
||
func (r PreCheckoutQuery) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error { | ||
return r.Response(b, ctx) | ||
} | ||
|
||
func (r PreCheckoutQuery) Name() string { | ||
return fmt.Sprintf("precheckoutquery_%p", r.Response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/PaulSonOfLars/gotgbot/v2" | ||
"github.com/PaulSonOfLars/gotgbot/v2/ext" | ||
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers/filters" | ||
) | ||
|
||
type ShippingQuery struct { | ||
Filter filters.ShippingQuery | ||
Response Response | ||
} | ||
|
||
func NewShippingQuery(f filters.ShippingQuery, r Response) ShippingQuery { | ||
return ShippingQuery{ | ||
Filter: f, | ||
Response: r, | ||
} | ||
} | ||
|
||
func (r ShippingQuery) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool { | ||
if ctx.PollAnswer == nil { | ||
return false | ||
} | ||
return r.Filter == nil || r.Filter(ctx.ShippingQuery) | ||
} | ||
|
||
func (r ShippingQuery) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error { | ||
return r.Response(b, ctx) | ||
} | ||
|
||
func (r ShippingQuery) Name() string { | ||
return fmt.Sprintf("shippingquery_%p", r.Response) | ||
} |