Skip to content

Commit

Permalink
Merge pull request #9 from commonlispbr/feature/remove-not-ban
Browse files Browse the repository at this point in the history
Only remove users instead ban: give a chance
  • Loading branch information
ryukinix authored Aug 11, 2020
2 parents 5931fc6 + 228ec11 commit 8888d72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion troll_shield.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
type TrollShieldBot interface {
GetChatMember(telegram.ChatConfigWithUser) (telegram.ChatMember, error)
KickChatMember(telegram.KickChatMemberConfig) (telegram.APIResponse, error)
UnbanChatMember(telegram.ChatMemberConfig) (telegram.APIResponse, error)
Send(telegram.Chattable) (telegram.Message, error)
LeaveChat(telegram.ChatConfig) (telegram.APIResponse, error)
GetUpdatesChan(telegram.UpdateConfig) (telegram.UpdatesChannel, error)
Expand Down Expand Up @@ -158,6 +159,11 @@ func kickTroll(bot TrollShieldBot, update *telegram.Update, user telegram.User,
telegram.KickChatMemberConfig{ChatMemberConfig: chatMember},
)

if err == nil {
// only kick, don't ban
_, err = bot.UnbanChatMember(chatMember)
}

if !resp.Ok || err != nil {
log.Printf(
"[!] Kicking %q did not work, error code %v: %v",
Expand All @@ -166,7 +172,7 @@ func kickTroll(bot TrollShieldBot, update *telegram.Update, user telegram.User,
} else {
username := getUserName(user)
text := fmt.Sprintf(
"%v foi banido porque é membro do grupo: %v. Adeus.",
"%v foi removido porque é membro do grupo: %v. Para mais informações, acione o nosso SAC 24h: @skhaz.",
username, trollHouse,
)
reply(bot, update, text)
Expand Down
10 changes: 10 additions & 0 deletions troll_shield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ func (bot *BotMockup) KickChatMember(c telegram.KickChatMemberConfig) (telegram.

}

func (bot *BotMockup) UnbanChatMember(c telegram.ChatMemberConfig) (telegram.APIResponse, error) {
switch c.UserID {
case 0:
return telegram.APIResponse{Ok: true}, nil
default:
return telegram.APIResponse{Ok: false}, errors.New("error")
}

}

func (bot *BotMockup) Send(c telegram.Chattable) (telegram.Message, error) {
return telegram.Message{}, nil
}
Expand Down

0 comments on commit 8888d72

Please sign in to comment.