diff --git a/config.properties.template b/config.properties.template index c0548d923..fc0a8ed65 100644 --- a/config.properties.template +++ b/config.properties.template @@ -249,6 +249,8 @@ bot_timeout_after_catching_pokemon=-1 # Set if you want the bot to stop after visiting certain amount of pokestops, -1 skips it bot_timeout_after_visiting_pokestops=-1 +# Auto join team at level 5 or more. Can be NEUTRAL, RED, BLUE or YELLOW +auto_team=NEUTRAL # List of pokemon names #MISSINGNO diff --git a/json-template.json b/json-template.json index 426693d98..3f26dc756 100644 --- a/json-template.json +++ b/json-template.json @@ -83,6 +83,7 @@ "waitTimeMax" : 0, "botTimeoutAfterMinutes" : -1, "botTimeoutAfterCatchingPokemon" : -1, - "botTimeoutAfterVisitingPokestops" : -1 + "botTimeoutAfterVisitingPokestops" : -1, + "autoTeam" : "NEUTRAL" } diff --git a/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt b/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt index 484fdba67..dd916b6b9 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt @@ -149,7 +149,9 @@ class SettingsParser(val properties: Properties) { botTimeoutAfterMinutes = getPropertyIfSet("Bot times out after X minutes and waits", "bot_timeout_after_minutes", defaults.botTimeoutAfterMinutes, String::toInt), botTimeoutAfterCatchingPokemon = getPropertyIfSet("Bot times out after X minutes and waits", "bot_timeout_after_catching_pokemon", defaults.botTimeoutAfterCatchingPokemon, String::toInt), - botTimeoutAfterVisitingPokestops = getPropertyIfSet("Bot times out after X minutes and waits", "bot_timeout_after_visiting_pokestops", defaults.botTimeoutAfterVisitingPokestops, String::toInt) + botTimeoutAfterVisitingPokestops = getPropertyIfSet("Bot times out after X minutes and waits", "bot_timeout_after_visiting_pokestops", defaults.botTimeoutAfterVisitingPokestops, String::toInt), + + autoTeam = getPropertyIfSet("Auto team", "auto_team", defaults.autoTeam, String::toString) ) } @@ -297,7 +299,9 @@ data class Settings( val botTimeoutAfterMinutes: Int = -1, val botTimeoutAfterCatchingPokemon:Int = -1, - val botTimeoutAfterVisitingPokestops:Int = -1 + val botTimeoutAfterVisitingPokestops:Int = -1, + + val autoTeam: String = "NEUTRAL" ) { fun withName(name: String): Settings { this.name = name diff --git a/src/main/kotlin/ink/abb/pogo/scraper/tasks/UpdateProfile.kt b/src/main/kotlin/ink/abb/pogo/scraper/tasks/UpdateProfile.kt index ce6ada8ec..c49474271 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/tasks/UpdateProfile.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/tasks/UpdateProfile.kt @@ -19,6 +19,12 @@ import java.text.NumberFormat import java.time.LocalDateTime import java.time.temporal.ChronoUnit import java.util.* +import kotlin.reflect.jvm.internal.impl.protobuf.InvalidProtocolBufferException +import POGOProtos.Enums.TeamColorOuterClass.TeamColor +import POGOProtos.Networking.Requests.Messages.SetPlayerTeamMessageOuterClass.SetPlayerTeamMessage +import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType +import com.pokegoapi.main.ServerRequest +import POGOProtos.Networking.Responses.SetPlayerTeamResponseOuterClass class UpdateProfile : Task { var lastLevelCheck: Int = 1 @@ -111,5 +117,25 @@ class UpdateProfile : Task { } catch (e: Exception) { Log.red("Failed to update profile and inventories") } + if (ctx.api.playerProfile.playerData.team==TeamColor.NEUTRAL && ctx.api.playerProfile.stats.level>=5) { + if (settings.autoTeam.toUpperCase().equals("RED") || settings.autoTeam.toUpperCase().equals("BLUE") || settings.autoTeam.toUpperCase().equals("YELLOW")) { + val msg = SetPlayerTeamMessage.newBuilder().setTeam(TeamColor.valueOf(settings.autoTeam.toUpperCase())).build() + val req = ServerRequest(RequestType.SET_PLAYER_TEAM, msg) + ctx.api.getRequestHandler().sendServerRequests(req) + try { + val response = SetPlayerTeamResponseOuterClass.SetPlayerTeamResponse.parseFrom(req.data) + if (response.status == SetPlayerTeamResponseOuterClass.SetPlayerTeamResponse.Status.SUCCESS) { + Log.green("You are now in the ${settings.autoTeam.toUpperCase()} team!") + } + else { + Log.red("An error occured when trying to set your team") + } + } catch (e : InvalidProtocolBufferException) { + } + } + else if(!settings.autoTeam.toUpperCase().equals("NEUTRAL")) { + Log.red("Unknow team in the config file!") + } + } } }