Skip to content

Commit

Permalink
fix: some helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Divkix committed Jul 29, 2024
1 parent 98c0eff commit 70c7013
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions alita/utils/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,17 +669,30 @@ func GetWelcomeType(msg *gotgbot.Message, greetingType string) (text string, dat
errorMsg = fmt.Sprintf("You need to give me some content to %s users!", greetingType)
var (
rawText string
args = strings.Fields(msg.Text)[1:]
args []string
)
_buttons := make([]tgmd2html.ButtonV2, 0)
replyMsg := msg.ReplyToMessage

// Split msg.Text into fields and ensure there are enough fields
fields := strings.Fields(msg.Text)
if len(fields) > 1 {
args = fields[1:]
} else {
log.Printf("Message text has insufficient fields: %v", fields)
}

// set rawText from helper function
setRawText(msg, args, &rawText)

if len(args) >= 1 && msg.ReplyToMessage == nil {
fileid = ""
text, _buttons = tgmd2html.MD2HTMLButtonsV2(strings.SplitN(rawText, " ", 2)[1])
splitRawText := strings.SplitN(rawText, " ", 2)
if len(splitRawText) > 1 {
text, _buttons = tgmd2html.MD2HTMLButtonsV2(splitRawText[1])
} else {
text, _buttons = tgmd2html.MD2HTMLButtonsV2("")
}
dataType = db.TEXT
} else if msg.ReplyToMessage != nil {
if replyMsg.ReplyMarkup == nil {
Expand Down Expand Up @@ -1301,22 +1314,43 @@ func preFixes(buttons []tgmd2html.ButtonV2, defaultNameButton string, text *stri
}
}

// function used to get rawtext from gotgbot.Message
// function used to get rawText from gotgbot.Message
func setRawText(msg *gotgbot.Message, args []string, rawText *string) {
replyMsg := msg.ReplyToMessage

if replyMsg == nil {
if msg.Text == "" && msg.Caption != "" {
*rawText = strings.SplitN(msg.OriginalCaptionMDV2(), " ", 2)[1] // using [1] to remove the command
splitText := strings.SplitN(msg.OriginalCaptionMDV2(), " ", 2)
if len(splitText) > 1 {
*rawText = splitText[1] // using [1] to remove the command
} else {
log.Println("Insufficient split elements for OriginalCaptionMDV2")
*rawText = ""
}
} else if msg.Text != "" && msg.Caption == "" {
*rawText = strings.SplitN(msg.OriginalMDV2(), " ", 2)[1] // using [1] to remove the command
splitText := strings.SplitN(msg.OriginalMDV2(), " ", 2)
if len(splitText) > 1 {
*rawText = splitText[1] // using [1] to remove the command
} else {
log.Println("Insufficient split elements for OriginalMDV2")
*rawText = ""
}
}
} else {
if replyMsg.Text == "" && replyMsg.Caption != "" {
*rawText = replyMsg.OriginalCaptionMDV2()
} else if replyMsg.Caption == "" && len(args) >= 2 {
*rawText = strings.SplitN(msg.OriginalMDV2(), " ", 3)[2] // using [1] to remove the command
splitText := strings.SplitN(msg.OriginalMDV2(), " ", 3)
if len(splitText) > 2 {
*rawText = splitText[2] // using [2] to remove the command
} else {
log.Println("Insufficient split elements for OriginalMDV2 with args")
*rawText = ""
}
} else {
*rawText = replyMsg.OriginalMDV2()
}
}

log.Printf("setRawText: msg.Text = %s, args = %v, rawText = %s\n", msg.Text, args, *rawText)
}

0 comments on commit 70c7013

Please sign in to comment.