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

Commit

Permalink
disallowed group
Browse files Browse the repository at this point in the history
  • Loading branch information
aimerneige committed Aug 10, 2022
1 parent 134dfd1 commit f247ae1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ imports (
// ...
```

在全局配置文件中写入配置

```yaml
aimerneige:
fortune:
blacklist: # 黑名单用户
- 1781924496
- 2802340025
disallowed: # 关闭功能的群
- 546362685
```
## LICENSE
<a href="https://www.gnu.org/licenses/agpl-3.0.en.html">
Expand Down
17 changes: 17 additions & 0 deletions fortune.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
var instance *fortune
var logger = utils.GetModuleLogger("com.aimerneige.fortune")
var blacklistUser []int64
var disallowedList []int64

type fortune struct {
}
Expand All @@ -41,6 +42,10 @@ func (f *fortune) Init() {
for _, user := range blacklistUserSlice {
blacklistUser = append(blacklistUser, int64(user))
}
disallowedSlice := config.GlobalConfig.GetIntSlice("aimerneige.fortune.disallowed")
for _, groupCode := range disallowedList {
disallowedSlice = append(disallowedSlice, int(groupCode))
}
}

// PostInit 第二次初始化
Expand All @@ -52,6 +57,9 @@ func (f *fortune) PostInit() {
// Serve 注册服务函数部分
func (f *fortune) Serve(b *bot.Bot) {
b.OnGroupMessage(func(c *client.QQClient, msg *message.GroupMessage) {
if isDisallowed(msg.GroupCode) {
return
}
reply := getFortuneReply(msg.ToString(), msg.Sender.Uin)
c.SendGroupMessage(msg.GroupCode, reply)
})
Expand Down Expand Up @@ -165,3 +173,12 @@ func inBlacklist(userID int64) bool {
}
return false
}

func isDisallowed(groupCode int64) bool {
for _, v := range disallowedList {
if groupCode == v {
return true
}
}
return false
}

0 comments on commit f247ae1

Please sign in to comment.