@@ -20,6 +20,8 @@ type TrollShieldBot interface {
2020 GetChatMember (telegram.ChatConfigWithUser ) (telegram.ChatMember , error )
2121 KickChatMember (telegram.KickChatMemberConfig ) (telegram.APIResponse , error )
2222 Send (telegram.Chattable ) (telegram.Message , error )
23+ LeaveChat (telegram.ChatConfig ) (telegram.APIResponse , error )
24+ GetUpdatesChan (telegram.UpdateConfig ) (telegram.UpdatesChannel , error )
2325}
2426
2527// blacklist groups, member from that groups will be kicked automatically
@@ -68,7 +70,7 @@ func getUserName(user telegram.User) string {
6870 return username
6971}
7072
71- func getUpdates (bot * telegram. BotAPI ) telegram.UpdatesChannel {
73+ func getUpdates (bot TrollShieldBot ) telegram.UpdatesChannel {
7274 u := telegram .NewUpdate (0 )
7375 u .Timeout = 60
7476 updates , err := bot .GetUpdatesChan (u )
@@ -194,14 +196,14 @@ func setupBot(envVar string) (*telegram.BotAPI, error) {
194196 return bot , nil
195197}
196198
197- func setupBots () (* telegram.BotAPI , * telegram.BotAPI ) {
199+ func setupBots () (* telegram.BotAPI , * telegram.BotAPI , error ) {
198200 var bot , botHidden * telegram.BotAPI
199201 var err error
200202
201203 log .Println ("Setup the main bot" )
202204 bot , err = setupBot ("TELEGRAM_BOT_TOKEN" )
203205 if err != nil {
204- log . Fatalf ( "Bot setup failed: %v" , err )
206+ return nil , nil , err
205207 }
206208
207209 log .Println ("Setup the hidden bot" )
@@ -211,22 +213,25 @@ func setupBots() (*telegram.BotAPI, *telegram.BotAPI) {
211213 botHidden = bot
212214 }
213215
214- return bot , botHidden
216+ return bot , botHidden , nil
215217}
216218
217- func leaveChat (bot * telegram. BotAPI , update * telegram.Update , trollGroup string ) {
219+ func leaveChat (bot TrollShieldBot , update * telegram.Update , trollGroup string ) {
218220 reply (bot , update , "Nesse grupo há trolls. Dou-me a liberdade de ir embora. Adeus." )
219221 r , err := bot .LeaveChat (telegram.ChatConfig {ChatID : update .Message .Chat .ID })
220222 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+ log .Printf ("Bot tried to exit from %v, but failed with: %v" ,
224+ trollGroup , err ,
223225 )
224226 }
225227}
226228
227229func main () {
228230 setupLogging ()
229- bot , botHidden := setupBots ()
231+ bot , botHidden , err := setupBots ()
232+ if err != nil {
233+ log .Fatal (err .Error ())
234+ }
230235
231236 for update := range getUpdates (bot ) {
232237 if messageEvent (& update ) {
0 commit comments