Skip to content

Commit 014a0a8

Browse files
committed
lint fix
1 parent 07f411f commit 014a0a8

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

plugin/crypter/handlers.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import (
1414

1515
var faceTagRe = regexp.MustCompile(`\{\{face:(\d+)\}\}`)
1616

17+
func parseID(v interface{}) int64 {
18+
n, _ := strconv.ParseInt(fmt.Sprintf("%v", v), 10, 64)
19+
return n
20+
}
21+
1722
func serializeMsg(segs message.Message) string {
1823
var sb strings.Builder
1924
for _, seg := range segs {
@@ -57,9 +62,7 @@ func getInput(ctx *zero.Ctx, cmds ...string) string {
5762
func getReplyContent(ctx *zero.Ctx) string {
5863
for _, seg := range ctx.Event.Message {
5964
if seg.Type == "reply" {
60-
var msgID int64
61-
fmt.Sscanf(fmt.Sprintf("%v", seg.Data["id"]), "%d", &msgID)
62-
if msgID > 0 {
65+
if msgID := parseID(seg.Data["id"]); msgID > 0 {
6366
if msg := ctx.GetMessage(msgID); msg.Elements != nil {
6467
return serializeMsg(msg.Elements)
6568
}
@@ -72,9 +75,7 @@ func getReplyContent(ctx *zero.Ctx) string {
7275
func getReplyFaceIDs(ctx *zero.Ctx) []int {
7376
for _, seg := range ctx.Event.Message {
7477
if seg.Type == "reply" {
75-
var msgID int64
76-
fmt.Sscanf(fmt.Sprintf("%v", seg.Data["id"]), "%d", &msgID)
77-
if msgID > 0 {
78+
if msgID := parseID(seg.Data["id"]); msgID > 0 {
7879
return extractFaceIDs(ctx.GetMessage(msgID).Elements)
7980
}
8081
}
@@ -86,9 +87,7 @@ func extractFaceIDs(segs message.Message) []int {
8687
var ids []int
8788
for _, seg := range segs {
8889
if seg.Type == "face" {
89-
var id int
90-
fmt.Sscanf(fmt.Sprintf("%v", seg.Data["id"]), "%d", &id)
91-
if id > 0 {
90+
if id := int(parseID(seg.Data["id"])); id > 0 {
9291
ids = append(ids, id)
9392
}
9493
}

0 commit comments

Comments
 (0)