<commit_before>package command

import (
	"regexp"
	"strings"

	log "github.com/Sirupsen/logrus"
	boardproto "github.com/liam-lai/ptt-alertor/models/ptt/board"
	"github.com/liam-lai/ptt-alertor/models/subscription"
	user "github.com/liam-lai/ptt-alertor/models/user/redis"
)

var Commands = map[string]map[string]string{
	"一般": {
		"指令": "可使用的指令清單",
		"清單": "設定的看板、關鍵字、作者",
	},
	"關鍵字相關": {
		"新增 看板 關鍵字": "新增看板關鍵字。",
		"刪除 看板 關鍵字": "刪除看板關鍵字。",
	},
	"作者相關": {
		"新增作者 看板 作者": "新增看板作者。",
		"刪除作者 看板 作者": "刪除看板作者。",
	},
	"範例": {
		"新增": "新增 nba,lol 樂透,情報",
		"刪除": "刪除 nba 樂透",
		"作者": "新增作者 gossiping ffaarr,obov",
	},
}

func HandleCommand(text string, userID string) string {
	command := strings.Fields(strings.TrimSpace(text))[0]
	log.WithFields(log.Fields{
		"account": userID,
		"command": command,
	}).Info("Command Request")
	switch command {
	case "清單":
		var rspText string
		subs := new(user.User).Find(userID).Subscribes
		if len(subs) == 0 {
			rspText = "尚未建立清單。請打「指令」查看新增方法。"
		} else {
			rspText = new(user.User).Find(userID).Subscribes.String()
		}
		return rspText
	case "指令":
		return stringCommands()
	case "新增", "刪除", "新增作者", "刪除作者":
		re := regexp.MustCompile("^(新增|新增作者|刪除|刪除作者)\\s+([^,，][\\w\\d-_,，]+[^,，])\\s+(.+)")
		matched := re.MatchString(text)
		if !matched {
			if strings.Contains(command, "作者") {
				return "指令格式錯誤。\n1.板名欄位開頭與結尾不可有逗號\n2.板名欄位間不允許空白字元。\n正確範例：" + command + " gossiping,lol ffaarr,obov"
			}
			return "指令格式錯誤。\n1.板名欄位開頭與結尾不可有逗號\n2.板名欄位間不允許空白字元。\n正確範例：" + command + " gossiping,lol 問卦,爆卦"
		}
		args := re.FindStringSubmatch(text)
		boardNames := splitParamString(args[2])
		keywords := splitParamString(args[3])
		var err error
		if command == "新增" || command == "新增作者" {
			if command == "新增" {
				err = update(userID, boardNames, keywords, addKeywords)
			} else if command == "新增作者" {
				err = update(userID, boardNames, keywords, addAuthors)
			}
			if bErr, ok := err.(boardproto.BoardNotExistError); ok {
				return "版名錯誤，請確認拼字。可能版名：\n" + bErr.Suggestion
			}
			if err != nil {
				return "新增失敗，請等待修復。"
			}
			return "新增成功"
		}
		if command == "刪除" || command == "刪除作者" {
			if command == "刪除" {
				err = update(userID, boardNames, keywords, removeKeywords)
			} else if command == "刪除作者" {
				err = update(userID, boardNames, keywords, removeAuthors)
			}
			if bErr, ok := err.(boardproto.BoardNotExistError); ok {
				return "版名錯誤，請確認拼字。可能版名：\n" + bErr.Suggestion
			}
			if err != nil {
				return "刪除失敗，請等待修復。"
			}
		}
		return "刪除成功"
	}
	return "無此指令，請打「指令」查看指令清單"
}
<commit_msg>correct variable name<commit_after>package command

import (
	"regexp"
	"strings"

	log "github.com/Sirupsen/logrus"
	boardproto "github.com/liam-lai/ptt-alertor/models/ptt/board"
	"github.com/liam-lai/ptt-alertor/models/subscription"
	user "github.com/liam-lai/ptt-alertor/models/user/redis"
)

var Commands = map[string]map[string]string{
	"一般": {
		"指令": "可使用的指令清單",
		"清單": "設定的看板、關鍵字、作者",
	},
	"關鍵字相關": {
		"新增 看板 關鍵字": "新增看板關鍵字。",
		"刪除 看板 關鍵字": "刪除看板關鍵字。",
	},
	"作者相關": {
		"新增作者 看板 作者": "新增看板作者。",
		"刪除作者 看板 作者": "刪除看板作者。",
	},
	"範例": {
		"新增": "新增 nba,lol 樂透,情報",
		"刪除": "刪除 nba 樂透",
		"作者": "新增作者 gossiping ffaarr,obov",
	},
}

func HandleCommand(text string, userID string) string {
	command := strings.Fields(strings.TrimSpace(text))[0]
	log.WithFields(log.Fields{
		"account": userID,
		"command": command,
	}).Info("Command Request")
	switch command {
	case "清單":
		var rspText string
		subs := new(user.User).Find(userID).Subscribes
		if len(subs) == 0 {
			rspText = "尚未建立清單。請打「指令」查看新增方法。"
		} else {
			rspText = new(user.User).Find(userID).Subscribes.String()
		}
		return rspText
	case "指令":
		return stringCommands()
	case "新增", "刪除", "新增作者", "刪除作者":
		re := regexp.MustCompile("^(新增|新增作者|刪除|刪除作者)\\s+([^,，][\\w\\d-_,，]+[^,，])\\s+(.+)")
		matched := re.MatchString(text)
		if !matched {
			if strings.Contains(command, "作者") {
				return "指令格式錯誤。\n1.板名欄位開頭與結尾不可有逗號\n2.板名欄位間不允許空白字元。\n正確範例：" + command + " gossiping,lol ffaarr,obov"
			}
			return "指令格式錯誤。\n1.板名欄位開頭與結尾不可有逗號\n2.板名欄位間不允許空白字元。\n正確範例：" + command + " gossiping,lol 問卦,爆卦"
		}
		args := re.FindStringSubmatch(text)
		boardNames := splitParamString(args[2])
		inputs := splitParamString(args[3])
		var err error
		if command == "新增" || command == "新增作者" {
			if command == "新增" {
				err = update(userID, boardNames, inputs, addKeywords)
			} else if command == "新增作者" {
				err = update(userID, boardNames, inputs, addAuthors)
			}
			if bErr, ok := err.(boardproto.BoardNotExistError); ok {
				return "版名錯誤，請確認拼字。可能版名：\n" + bErr.Suggestion
			}
			if err != nil {
				return "新增失敗，請等待修復。"
			}
			return "新增成功"
		}
		if command == "刪除" || command == "刪除作者" {
			if command == "刪除" {
				err = update(userID, boardNames, inputs, removeKeywords)
			} else if command == "刪除作者" {
				err = update(userID, boardNames, inputs, removeAuthors)
			}
			if bErr, ok := err.(boardproto.BoardNotExistError); ok {
				return "版名錯誤，請確認拼字。可能版名：\n" + bErr.Suggestion
			}
			if err != nil {
				return "刪除失敗，請等待修復。"
			}
		}
		return "刪除成功"
	}
	return "無此指令，請打「指令」查看指令清單"
}

{'fraction_non_alphanumeric': 0.18514150943396226, 'fraction_numerical': 0.0031446540880503146, 'mean_word_length': 3.7605238540692234, 'pattern_counts': {'":': 36, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2925510', 'n_tokens_mistral': 2736, 'n_tokens_neox': 2790, 'n_words': 398}