Skip to content

Commit 7dc844c

Browse files
committed
🎨 优化lint
1 parent 534d646 commit 7dc844c

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

plugin/chatcount/model.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const (
2121
var (
2222
// ctdb 聊天时长数据库全局变量
2323
ctdb *chattimedb
24-
// leveler 水群提醒时间提醒段,单位分钟
25-
leveler = NewLeveler([]int{60, 120, 180, 240, 300})
24+
// l 水群提醒时间提醒段,单位分钟
25+
l = newLeveler(60, 120, 180, 240, 300)
2626
)
2727

2828
// chattimedb 聊天时长数据库结构体
@@ -92,11 +92,14 @@ func (ctdb *chattimedb) updateChatTime(gid, uid int64) (remindTime int64, remind
9292
ts, ok := ctdb.userTimestampMap.Load(keyword)
9393
if !ok {
9494
ctdb.userTimestampMap.Store(keyword, now.Unix())
95+
ctdb.userTodayMessageMap.Store(keyword, 1)
9596
return
9697
}
9798
lastTime := time.Unix(ts, 0)
9899
todayTime, _ := ctdb.userTodayTimeMap.Load(keyword)
99100
totayMessage, _ := ctdb.userTodayMessageMap.Load(keyword)
101+
//这个消息数是必须统计的
102+
ctdb.userTodayMessageMap.Store(keyword, totayMessage+1)
100103
st := chatTime{
101104
GroupID: gid,
102105
UserID: uid,
@@ -127,9 +130,8 @@ func (ctdb *chattimedb) updateChatTime(gid, uid int64) (remindTime int64, remind
127130
// 当聊天时间在一定范围内的话,则计入时长
128131
if userChatTime < chatInterval {
129132
ctdb.userTodayTimeMap.Store(keyword, todayTime+userChatTime)
130-
ctdb.userTodayMessageMap.Store(keyword, totayMessage+1)
131133
remindTime = (todayTime + userChatTime) / 60
132-
remindFlag = leveler.Level(int((todayTime+userChatTime)/60)) > leveler.Level(int(todayTime/60))
134+
remindFlag = l.level(int((todayTime+userChatTime)/60)) > l.level(int(todayTime/60))
133135
}
134136
ctdb.userTimestampMap.Store(keyword, now.Unix())
135137
return
@@ -175,24 +177,24 @@ func (ctdb *chattimedb) getChatRank(gid int64) (chatTimeList []chatTime) {
175177
TodayMessage: todayMessage,
176178
})
177179
}
178-
sort.Sort(ByTotalTimeDescMessageDesc(chatTimeList))
180+
sort.Sort(sortChatTime(chatTimeList))
179181
return
180182
}
181183

182-
// Leveler 结构体,包含一个 levelArray 字段
183-
type Leveler struct {
184+
// leveler 结构体,包含一个 levelArray 字段
185+
type leveler struct {
184186
levelArray []int
185187
}
186188

187-
// NewLeveler 构造函数,用于创建 Leveler 实例
188-
func NewLeveler(levels []int) *Leveler {
189-
return &Leveler{
189+
// newLeveler 构造函数,用于创建 Leveler 实例
190+
func newLeveler(levels ...int) *leveler {
191+
return &leveler{
190192
levelArray: levels,
191193
}
192194
}
193195

194-
// Level 方法,封装了 getLevel 函数的逻辑
195-
func (l *Leveler) Level(t int) int {
196+
// level 方法,封装了 getLevel 函数的逻辑
197+
func (l *leveler) level(t int) int {
196198
for i := len(l.levelArray) - 1; i >= 0; i-- {
197199
if t >= l.levelArray[i] {
198200
return i + 1
@@ -201,23 +203,23 @@ func (l *Leveler) Level(t int) int {
201203
return 0
202204
}
203205

204-
// ByTotalTimeDescMessageDesc chatTime排序数组
205-
type ByTotalTimeDescMessageDesc []chatTime
206+
// sortChatTime chatTime排序数组
207+
type sortChatTime []chatTime
206208

207209
// Len 实现 sort.Interface
208-
func (a ByTotalTimeDescMessageDesc) Len() int {
210+
func (a sortChatTime) Len() int {
209211
return len(a)
210212
}
211213

212214
// Less 实现 sort.Interface,按 TodayTime 降序,TodayMessage 降序
213-
func (a ByTotalTimeDescMessageDesc) Less(i, j int) bool {
215+
func (a sortChatTime) Less(i, j int) bool {
214216
if a[i].TodayTime == a[j].TodayTime {
215217
return a[i].TodayMessage > a[j].TodayMessage
216218
}
217219
return a[i].TodayTime > a[j].TodayTime
218220
}
219221

220222
// Swap 实现 sort.Interface
221-
func (a ByTotalTimeDescMessageDesc) Swap(i, j int) {
223+
func (a sortChatTime) Swap(i, j int) {
222224
a[i], a[j] = a[j], a[i]
223225
}

0 commit comments

Comments
 (0)