Skip to content

Commit

Permalink
拦截广告用户
Browse files Browse the repository at this point in the history
  • Loading branch information
IJNKAWAKAZE committed Oct 29, 2024
1 parent ef50d6c commit 9126a41
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/config/read_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var RecruitMissing map[string]string

var RecruitTagMap map[string]string

var ADWords []string

func init() {
// 设置配置文件的名字
viper.SetConfigName("arknights")
Expand Down Expand Up @@ -51,6 +53,7 @@ func initData() {
recruitTags := viper.GetString("recruit.tags")
RecruitMissing = make(map[string]string)
RecruitTagMap = make(map[string]string)
ADWords = viper.GetStringSlice("ad")
for _, missing := range strings.Split(jpMissing, "/") {
RecruitMissing[missing] = missing
}
Expand Down
7 changes: 3 additions & 4 deletions src/core/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ func Serve() {
b := bot.Arknights.AddHandle()
b.NewProcessor(
func(update tgbotapi.Update) bool {
if update.Message != nil {
if update.Message != nil && update.Message.ViaBot != nil {
return update.Message.ViaBot.ID == 273234066 //PostBot Id
}
return false
},
func(update tgbotapi.Update) error {
msg := tgbotapi.NewDeleteMessage(update.FromChat().ID, update.Message.MessageID)
_, err := bot.Arknights.Send(msg)
return err
update.Message.Delete()
return nil
},
)
b.NewMemberProcessor(gatekeeper.NewMemberHandle)
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/gatekeeper/new_member_handle.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package gatekeeper

import (
bot "arknights_bot/config"
"arknights_bot/utils"
tgbotapi "github.com/ijnkawakaze/telegram-bot-api"
"github.com/spf13/viper"
"strings"
)

func NewMemberHandle(update tgbotapi.Update) error {
message := update.Message
for _, member := range message.NewChatMembers {
if member.ID == message.From.ID { // 自己加入群组
chat, err := bot.Arknights.GetChat(tgbotapi.ChatInfoConfig{ChatConfig: tgbotapi.ChatConfig{ChatID: member.ID}})
if err != nil {
return err
}
for _, word := range bot.ADWords {
if strings.Contains(chat.Bio, word) {
message.Delete()
bot.Arknights.BanChatMember(message.Chat.ID, member.ID)
return nil
}
}
go VerifyMember(message)
continue
}
Expand Down
9 changes: 1 addition & 8 deletions src/plugins/system/callback_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ func Report(callBack tgbotapi.Update) error {

if d[1] == "BAN" {
fmt.Printf("在群组 %s 用户 %s 封禁了 %d", callbackQuery.Message.Chat.Title, callbackQuery.From.FullName(), target)
banChatMemberConfig := tgbotapi.BanChatMemberConfig{
ChatMemberConfig: tgbotapi.ChatMemberConfig{
ChatID: chatId,
UserID: target,
},
RevokeMessages: true,
}
bot.Arknights.Send(banChatMemberConfig)
bot.Arknights.BanChatMember(chatId, target)
delMsg := tgbotapi.NewDeleteMessage(chatId, targetMessageId)
bot.Arknights.Send(delMsg)

Expand Down

0 comments on commit 9126a41

Please sign in to comment.