Feat(Initial): Initial Go codebase
All checks were successful
Webhook-Everything/Webhook-Everything/pipeline/head This commit looks good
All checks were successful
Webhook-Everything/Webhook-Everything/pipeline/head This commit looks good
This commit is contained in:
35
backend/internal/telegrampackage/parsetwitterbotcommand.go
Normal file
35
backend/internal/telegrampackage/parsetwitterbotcommand.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package telegrampackage
|
||||
|
||||
import "strings"
|
||||
|
||||
func ParseTelegramBotCommand(fullCmd string) []string {
|
||||
var results []string
|
||||
currentInsideQuote := false
|
||||
splitted := strings.Split(fullCmd, " ")
|
||||
for _, currSplit := range splitted {
|
||||
if !currentInsideQuote {
|
||||
if strings.HasPrefix(currSplit, "\"") {
|
||||
if len(currSplit) >= 2 && !strings.HasSuffix(currSplit, "\\\"") && strings.HasSuffix(currSplit, "\"") {
|
||||
currSplit = strings.ReplaceAll(currSplit, "\\\"", "\"")
|
||||
results = append(results, currSplit[1:len(currSplit)-1])
|
||||
} else {
|
||||
currentInsideQuote = true
|
||||
currSplit = strings.ReplaceAll(currSplit, "\\\"", "\"")
|
||||
results = append(results, currSplit[1:])
|
||||
}
|
||||
} else {
|
||||
results = append(results, currSplit)
|
||||
}
|
||||
} else {
|
||||
if !strings.HasSuffix(currSplit, "\\\"") && strings.HasSuffix(currSplit, "\"") {
|
||||
currentInsideQuote = false
|
||||
currSplit = strings.ReplaceAll(currSplit, "\\\"", "\"")
|
||||
results[len(results)-1] = results[len(results)-1] + " " + currSplit[:len(currSplit)-1]
|
||||
} else {
|
||||
currSplit = strings.ReplaceAll(currSplit, "\\\"", "\"")
|
||||
results[len(results)-1] = results[len(results)-1] + " " + currSplit
|
||||
}
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
Reference in New Issue
Block a user