Skip to content

Commit

Permalink
score command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sora233 committed Sep 22, 2021
1 parent 087c33b commit 59ddb3d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lsp/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "github.com/Sora233/sliceutil"
const (
RollCommand = "roll"
CheckinCommand = "签到"
ScoreCommand = "查询积分"
GrantCommand = "grant"
LspCommand = "lsp"
WatchCommand = "watch"
Expand Down Expand Up @@ -42,7 +43,7 @@ var allGroupCommand = [...]string{
ListCommand, SetuCommand, HuangtuCommand,
EnableCommand, DisableCommand, ImageContentCommand,
FaceCommand, ReverseCommand, ConfigCommand,
HelpCommand,
HelpCommand, ScoreCommand,
}

var allPrivateOperate = [...]string{
Expand Down
33 changes: 33 additions & 0 deletions lsp/groupCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (lgc *LspGroupCommand) Execute() {
if lgc.requireNotDisable(CheckinCommand) {
lgc.CheckinCommand()
}
case "/查询积分":
if lgc.requireNotDisable(ScoreCommand) {
lgc.ScoreCommand()
}
case "/roll":
if lgc.requireNotDisable(RollCommand) {
lgc.RollCommand()
Expand Down Expand Up @@ -552,6 +556,35 @@ func (lgc *LspGroupCommand) CheckinCommand() {
}
}

func (lgc *LspGroupCommand) ScoreCommand() {
log := lgc.DefaultLoggerWithCommand(ScoreCommand)
log.Infof("run score command")
defer func() { log.Info("score command end") }()

var scoreCmd struct{}
_, output := lgc.parseCommandSyntax(&scoreCmd, ScoreCommand)
if output != "" {
lgc.textReply(output)
}
if lgc.exit {
return
}

var scoreS string

localdb.RCoverTx(func(tx *buntdb.Tx) error {
key := localdb.Key("Score", lgc.groupCode(), lgc.uin())
scoreS, _ = tx.Get(key)
return nil
})

if len(scoreS) == 0 {
scoreS = "0"
}
score, _ := strconv.ParseInt(scoreS, 0, 64)
lgc.textReplyF("当前积分为%v", score)
}

func (lgc *LspGroupCommand) EnableCommand(disable bool) {
groupCode := lgc.groupCode()
log := lgc.DefaultLoggerWithCommand(EnableCommand).WithField("disable", disable)
Expand Down

0 comments on commit 59ddb3d

Please sign in to comment.