package moon import ( "time" "github.com/NicoNex/echotron/v3" ) // TODO: refactor to return bool, error // squash bans given chat member. func squash(chatid, userid int64) { banUntilDate := time.Now().Unix() + 10 if timestamp := FindSquashedMember(chatid, userid); timestamp != 0 { Log.Infof("Skip banning user %d, already banned") return } if res, err := Tg.BanChatMember( chatid, userid, &echotron.BanOptions{ UntilDate: int(banUntilDate), }, ); err != nil { Log.Errorf( "Unable to ban user with id %d in chat %s: %s", userid, chatid, res.Description, ) } else { if !res.Ok { Log.Errorf( "Unable to ban user with id %d in chat %s: %s", userid, chatid, res.Description, ) } else { Log.Infof( "Banned user with id %d in chat %d.", userid, chatid, ) AddSquashedMember(chatid, userid) } } }