moved payments to commands

This commit is contained in:
2020-03-31 15:16:12 +00:00
parent 9ea12ab5f5
commit c08ded2a66
2 changed files with 18 additions and 13 deletions

View File

@ -9,6 +9,22 @@ import (
"samhofi.us/x/keybase/types/chat1" "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) { func (b *bot) setupMeeting(convid chat1.ConvIDStr, sender string, args []string, membersType string) {
b.debug("command recieved in conversation %s", convid) b.debug("command recieved in conversation %s", convid)
meeting, err := newJitsiMeetingSimple() meeting, err := newJitsiMeetingSimple()

View File

@ -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 this chat message is a payment, add it to the bot payments
if m.Content.Text.Payments != nil { if m.Content.Text.Payments != nil {
// there can be multiple payments on each message, iterate them b.handlePayment(m)
for _, payment := range m.Content.Text.Payments { return
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:")
}
}
}
} }
// Determine first if this is a command // Determine first if this is a command
if strings.HasPrefix(m.Content.Text.Body, "!") || strings.HasPrefix(m.Content.Text.Body, "@") { if strings.HasPrefix(m.Content.Text.Body, "!") || strings.HasPrefix(m.Content.Text.Body, "@") {