增加渠道信息
This commit is contained in:
+54
-4
@@ -7,7 +7,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var numberPattern = regexp.MustCompile(`[-+]?\d+(?:\.\d+)?`)
|
||||
var (
|
||||
numberPattern = regexp.MustCompile(`[-+]?\d+(?:\.\d+)?`)
|
||||
onlineTimePattern = regexp.MustCompile(`^\D*(\d{1,2})(?:\s*[::点.]\s*(\d{1,2}))?\D+(\d{1,2})(?:\s*[::点.]\s*(\d{1,2}))?\D*$`)
|
||||
)
|
||||
|
||||
func ParseUploadText(text string) (ParsedUpload, error) {
|
||||
values := make(map[string]string)
|
||||
@@ -55,7 +58,7 @@ func ParseUploadText(text string) (ParsedUpload, error) {
|
||||
account.BanRecord = normalizeBanFlag(banRaw)
|
||||
account.CommonRegion = firstValue(values, "常用地区", "常用区域")
|
||||
account.ContactPhone = firstValue(values, "联系电话", "手机号", "电话")
|
||||
account.OwnerOnlineTime = firstValue(values, "号主在线时间", "在线时间")
|
||||
account.OwnerOnlineTime = normalizeOwnerOnlineTime(firstValue(values, "号主在线时间", "在线时间"))
|
||||
account.Remark = composeRemark(firstValue(values, "备注", "说明"), banRaw)
|
||||
|
||||
account.Currency.HafuCoin, err = parseRequiredFloat(values, "哈夫币纯币", "哈夫币")
|
||||
@@ -107,10 +110,14 @@ func ParseUploadText(text string) (ParsedUpload, error) {
|
||||
}
|
||||
|
||||
func splitKeyValue(line string) (string, string, bool) {
|
||||
if idx := strings.Index(line, ":"); idx >= 0 {
|
||||
fullWidthIdx := strings.Index(line, ":")
|
||||
asciiIdx := strings.Index(line, ":")
|
||||
if fullWidthIdx >= 0 && (asciiIdx < 0 || fullWidthIdx < asciiIdx) {
|
||||
idx := fullWidthIdx
|
||||
return line[:idx], line[idx+len(":"):], true
|
||||
}
|
||||
if idx := strings.Index(line, ":"); idx >= 0 {
|
||||
if asciiIdx >= 0 {
|
||||
idx := asciiIdx
|
||||
return line[:idx], line[idx+1:], true
|
||||
}
|
||||
return "", "", false
|
||||
@@ -246,6 +253,49 @@ func parseFloatText(value string, preferLast bool) (float64, error) {
|
||||
return strconv.ParseFloat(pick, 64)
|
||||
}
|
||||
|
||||
func normalizeOwnerOnlineTime(value string) string {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
start, end, ok := parseOwnerOnlineTimeRange(value)
|
||||
if !ok {
|
||||
return value
|
||||
}
|
||||
return start + " 至 " + end
|
||||
}
|
||||
|
||||
func parseOwnerOnlineTimeRange(value string) (string, string, bool) {
|
||||
matches := onlineTimePattern.FindStringSubmatch(strings.TrimSpace(value))
|
||||
if len(matches) != 5 {
|
||||
return "", "", false
|
||||
}
|
||||
start, ok := normalizeTimePart(matches[1], matches[2])
|
||||
if !ok {
|
||||
return "", "", false
|
||||
}
|
||||
end, ok := normalizeTimePart(matches[3], matches[4])
|
||||
if !ok {
|
||||
return "", "", false
|
||||
}
|
||||
return start, end, true
|
||||
}
|
||||
|
||||
func normalizeTimePart(hourText, minuteText string) (string, bool) {
|
||||
hour, err := strconv.Atoi(strings.TrimSpace(hourText))
|
||||
if err != nil || hour < 0 || hour > 23 {
|
||||
return "", false
|
||||
}
|
||||
minute := 0
|
||||
if strings.TrimSpace(minuteText) != "" {
|
||||
minute, err = strconv.Atoi(strings.TrimSpace(minuteText))
|
||||
if err != nil || minute < 0 || minute > 59 {
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%02d:%02d", hour, minute), true
|
||||
}
|
||||
|
||||
func parseSkins(value string) []string {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" || value == "无" || strings.EqualFold(value, "none") {
|
||||
|
||||
Reference in New Issue
Block a user