Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
update blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
aimerneige committed Aug 7, 2022
1 parent f197277 commit 134dfd1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions fortune.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"time"

"github.com/Logiase/MiraiGo-Template/bot"
"github.com/Logiase/MiraiGo-Template/config"
"github.com/Logiase/MiraiGo-Template/utils"
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/message"
)

var instance *fortune
var logger = utils.GetModuleLogger("com.aimerneige.fortune")
var blacklistUser []int64

type fortune struct {
}
Expand All @@ -35,6 +37,10 @@ func (f *fortune) MiraiGoModule() bot.ModuleInfo {
// 在此处可以进行 Module 的初始化配置
// 如配置读取
func (f *fortune) Init() {
blacklistUserSlice := config.GlobalConfig.GetIntSlice("aimerneige.fortune.blacklist")
for _, user := range blacklistUserSlice {
blacklistUser = append(blacklistUser, int64(user))
}
}

// PostInit 第二次初始化
Expand Down Expand Up @@ -87,6 +93,9 @@ func getFortuneReply(msgString string, uin int64) *message.SendingMessage {
return nil
}
fortuneResult := drawAFortuneStick(things, uin)
if inBlacklist(uin) {
fortuneResult = "大凶"
}
replyString := fmt.Sprintf("所求事项\"%s\"的求签结果为: %s", things, fortuneResult)
replyMessage := message.NewSendingMessage().Append(message.NewText(replyString))
return replyMessage
Expand Down Expand Up @@ -147,3 +156,12 @@ func stringHash(s string) uint32 {
h.Write([]byte(s))
return h.Sum32()
}

func inBlacklist(userID int64) bool {
for _, v := range blacklistUser {
if userID == v {
return true
}
}
return false
}

0 comments on commit 134dfd1

Please sign in to comment.