Skip to content

Commit

Permalink
fix nests list
Browse files Browse the repository at this point in the history
  • Loading branch information
versx committed Nov 6, 2020
1 parent ebd27c1 commit cf9d951
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Commands/Nests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public async Task PostNestsAsync(CommandContext ctx,
Description = string.Empty,
Color = DiscordColor.Green
};
var message = string.Empty;
foreach (var nest in groupedNests[key])
{
if (nest.Average < server.NestsMinimumPerHour)
Expand All @@ -98,11 +99,11 @@ public async Task PostNestsAsync(CommandContext ctx,
var pkmnName = Translator.Instance.GetPokemonName(pkmn.PokedexId);
var gmapsLink = string.Format(Strings.GoogleMaps, nest.Latitude, nest.Longitude);
// TODO: Check if possible shiny
eb.Description += $"[**{nest.Name}**]({gmapsLink}): {pkmnName} (#{nest.PokemonId}) {nest.Average:N0} per hour\r\n";
if (eb.Description.Length >= 2048)
message += $"[**{nest.Name}**]({gmapsLink}): {pkmnName} (#{nest.PokemonId}) {nest.Average:N0} per hour\r\n";
if (message.Length >= 2048)
{
var message = eb.Description.Substring(0, Math.Min(eb.Description.Length, 2048));
eb.Description = message;
eb.Description = message.Substring(0, Math.Min(message.Length, 2048));
message = string.Empty;
await channel.SendMessageAsync(embed: eb);
eb = new DiscordEmbedBuilder
{
Expand All @@ -112,8 +113,10 @@ public async Task PostNestsAsync(CommandContext ctx,
};
}
}
if (eb.Description.Length > 0)
if (message.Length > 0)
{
eb.Description = message;
message = string.Empty;
await channel.SendMessageAsync(embed: eb);
}
Thread.Sleep(1000);
Expand Down Expand Up @@ -146,7 +149,7 @@ public async Task PostNestsAsync(CommandContext ctx,
continue;

await channel.SendMessageAsync(embed: eb);
System.Threading.Thread.Sleep(200);
Thread.Sleep(200);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -265,20 +268,21 @@ private Dictionary<string, List<Nest>> GroupNests(ulong guildId, IEnumerable<Nes
_logger.Warn($"Failed to find geofence for nest {nest.Name}.");
continue;
}
var geofenceName = geofence.Name;
var server = _dep.WhConfig.Servers[guildId];
var cities = server.CityRoles.Select(x => x.ToLower());
if (!cities.Contains(geofence.Name.ToLower()))
if (!cities.Contains(geofenceName.ToLower()))
continue;

if (dict.ContainsKey(geofence.Name))
if (dict.ContainsKey(geofenceName))
{
dict[geofence.Name].Add(nest);
dict[geofenceName].Add(nest);
}
else
{
dict.Add(geofence.Name, new List<Nest> { nest });
dict.Add(geofenceName, new List<Nest> { nest });
}
dict[geofence.Name].Sort((x, y) => x.Name.CompareTo(y.Name));
dict[geofenceName].Sort((x, y) => x.Name.CompareTo(y.Name));
}
return dict;
}
Expand Down

0 comments on commit cf9d951

Please sign in to comment.