private async Task <ClanWarLeagueWar> GetClanCurrentLeagueWar(Clan selectedClan, CurrentWarLeagueGroup currentWarLeagueGroup) { ClanWarLeagueWar currentLeagueWar = null; foreach (InlineModel0 model in currentWarLeagueGroup.Rounds) { foreach (string warTag in model.WarTags) { if (warTag.Contains("#0")) // #0 = Round not started { continue; } ClanWarLeagueWar war = await _clashClient.Clans.GetClanWarLeaguesWarsAsync(warTag); if (war.Clan.Tag == selectedClan.Tag) { if (war.State == State.InWar) { currentLeagueWar = war; break; } } else if (war.Opponent.Tag == selectedClan.Tag) { // If the opponent in the war is the selected clan, we want to switch the opponent and the main clan ClanWarLeagueWarClan tempMainClan = war.Clan; war.Clan = war.Opponent; war.Opponent = tempMainClan; if (war.State == State.InWar) { currentLeagueWar = war; break; } } } } return(currentLeagueWar); }
public async Task SearchClanAsync([Remainder] string clan_tag) { Clan selectedClan = null; try { selectedClan = await _clashClient.Clans.GetAsync(clan_tag); } catch (ClashOfClansException ex) { Console.WriteLine(ex.Error); } if (selectedClan == null) { await ReplyAsync($"Clan with tag {clan_tag} could not be found"); return; } await Context.Channel.SendMessageAsync("Processing info about clan " + selectedClan.Name + "..."); _clanInformation.StoredClan = selectedClan; EmbedBuilder embedBuilder = _clanInformation.CreateClanDescription(); CurrentWarLeagueGroup currentWarLeagueGroup = null; try { currentWarLeagueGroup = await _clashClient.Clans.GetCurrentWarLeagueGroupAsync(selectedClan.Tag); } catch (ClashOfClansException ex) { Console.WriteLine(ex.Error); } if (currentWarLeagueGroup != null) { // Clan in league _clanInformation.StoredClanCurrentLeagueWar = await GetClanCurrentLeagueWar(selectedClan, currentWarLeagueGroup); if (_clanInformation.StoredClanCurrentLeagueWar != null) { // Clan in ongoing league war _clanInformation.StoredClanLeagueOpponent = _clanInformation.StoredClanCurrentLeagueWar.Opponent; embedBuilder.Description += "\n In league war against " + _clanInformation.StoredClanCurrentLeagueWar.Opponent.Name; } } else { CurrentWar selectedClanCurrentWar = null; try { selectedClanCurrentWar = await _clashClient.Clans.GetCurrentWarAsync(selectedClan.Tag); } catch (ClashOfClansException ex) { Console.WriteLine(ex.Error); } if (selectedClanCurrentWar != null) { // Clan in normal war _clanInformation.StoredClanCurrentWar = selectedClanCurrentWar; _clanInformation.StoredClanOpponent = selectedClanCurrentWar.Opponent; embedBuilder.Description += "\n At war with: " + _clanInformation.StoredClanOpponent.Name; } } await Context.Channel.SendMessageAsync("", false, embedBuilder.Build()); }