Skip to content

Commit a1d451e

Browse files
committed
Add leaveChat events when troll-shield is on trollGroups
1 parent cfb6140 commit a1d451e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

troll_shield.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ func setupBots() (*telegram.BotAPI, *telegram.BotAPI) {
213213

214214
return bot, botHidden
215215
}
216+
217+
func leaveChat(bot *telegram.BotAPI, update *telegram.Update, trollGroup string) {
218+
reply(bot, update, "Nesse grupo há trolls. Dou-me a liberdade de ir embora. Adeus.")
219+
r, err := bot.LeaveChat(telegram.ChatConfig{ChatID: update.Message.Chat.ID})
220+
if !r.Ok || err != nil {
221+
log.Printf("%v tried to exit from %v, but failed with: %v",
222+
bot.Self.UserName, trollGroup, err,
223+
)
224+
}
216225
}
217226

218227
func main() {
@@ -224,6 +233,13 @@ func main() {
224233
if update.Message.Text == "/lelerax" {
225234
reply(bot, &update, "Estou vivo.")
226235
}
236+
237+
// Exit automatically from group after the bot receive a message from it
238+
for _, trollGroup := range trollGroups {
239+
if fromChatEvent(&update, strings.TrimLeft(trollGroup, "@")) {
240+
leaveChat(bot, &update, trollGroup)
241+
}
242+
}
227243
}
228244

229245
if newChatMemberEvent(&update) {
@@ -233,6 +249,14 @@ func main() {
233249
} else if fromChatEvent(&update, "commonlispbr") && !member.IsBot {
234250
welcomeMessage(bot, &update, member)
235251
}
252+
253+
// Exit automatically from groups when I'm joining it
254+
for _, trollGroup := range trollGroups {
255+
if fromChatEvent(&update, strings.TrimLeft(trollGroup, "@")) && member.UserName == bot.Self.UserName {
256+
leaveChat(bot, &update, trollGroup)
257+
}
258+
}
259+
236260
}
237261
}
238262
}

0 commit comments

Comments
 (0)