From c08ded2a66557f9c597f77fef67f01c848cc0540 Mon Sep 17 00:00:00 2001 From: David Haukeness Date: Tue, 31 Mar 2020 15:16:12 +0000 Subject: [PATCH] moved payments to commands --- commands.go | 16 ++++++++++++++++ handlers.go | 15 ++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/commands.go b/commands.go index 23b943e..b152243 100644 --- a/commands.go +++ b/commands.go @@ -9,6 +9,22 @@ import ( "samhofi.us/x/keybase/types/chat1" ) +func (b *bot) handlePayment(m chat1.MsgSummary) { + // there can be multiple payments on each message, iterate them + for _, payment := range m.Content.Text.Payments { + if strings.Contains(payment.PaymentText, b.k.Username) { + // if the payment is successful put log the payment for wallet closure + if payment.Result.ResultTyp__ == 0 && payment.Result.Error__ == nil { + var replyInfo = botReply{convID: m.ConvID, msgID: m.Id} + b.payments[*payment.Result.Sent__] = replyInfo + } else { + // if the payment fails, be sad + b.k.ReactByConvID(m.ConvID, m.Id, ":cry:") + } + } + } +} + func (b *bot) setupMeeting(convid chat1.ConvIDStr, sender string, args []string, membersType string) { b.debug("command recieved in conversation %s", convid) meeting, err := newJitsiMeetingSimple() diff --git a/handlers.go b/handlers.go index 7d4405c..6baa9e5 100644 --- a/handlers.go +++ b/handlers.go @@ -32,19 +32,8 @@ func (b *bot) chatHandler(m chat1.MsgSummary) { } // if this chat message is a payment, add it to the bot payments if m.Content.Text.Payments != nil { - // there can be multiple payments on each message, iterate them - for _, payment := range m.Content.Text.Payments { - if strings.Contains(payment.PaymentText, b.k.Username) { - // if the payment is successful put log the payment for wallet closure - if payment.Result.ResultTyp__ == 0 && payment.Result.Error__ == nil { - var replyInfo = botReply{convID: m.ConvID, msgID: m.Id} - b.payments[*payment.Result.Sent__] = replyInfo - } else { - // if the payment fails, be sad - b.k.ReactByConvID(m.ConvID, m.Id, ":cry:") - } - } - } + b.handlePayment(m) + return } // Determine first if this is a command if strings.HasPrefix(m.Content.Text.Body, "!") || strings.HasPrefix(m.Content.Text.Body, "@") {