private async Task ResetQuests() { _logger.Debug($"MIDNIGHT {DateTime.Now}"); _logger.Debug($"Starting automatic quest messages cleanup..."); Statistics.Instance.WriteOut(); Statistics.Instance.Reset(); if (_whConfig.ShinyStats.Enabled) { var statsChannel = await _client.GetChannelAsync(_whConfig.ShinyStats.ChannelId); if (statsChannel == null) { _logger.Warn($"Failed to get channel id {_whConfig.ShinyStats.ChannelId} to post shiny stats."); } else { if (_whConfig.ShinyStats.ClearMessages) { await _client.DeleteMessages(_whConfig.ShinyStats.ChannelId); } //Subtract an hour to make sure it shows yesterdays date. await statsChannel.SendMessageAsync($"[**Shiny Pokemon stats for {DateTime.Now.Subtract(TimeSpan.FromHours(1)).ToLongDateString()}**]\r\n----------------------------------------------"); var stats = await ShinyStats.GetShinyStats(_whConfig.ConnectionStrings.Scanner); var sorted = stats.Keys.ToList(); sorted.Sort(); foreach (var pokemon in sorted) { if (pokemon == 0) { continue; } if (!Database.Instance.Pokemon.ContainsKey((int)pokemon)) { continue; } var pkmn = Database.Instance.Pokemon[(int)pokemon]; var pkmnStats = stats[pokemon]; var chance = pkmnStats.Shiny == 0 || pkmnStats.Total == 0 ? 0 : Convert.ToInt32(pkmnStats.Total / pkmnStats.Shiny); var chanceMessage = chance == 0 ? null : $" with a **1/{chance}** ratio"; await statsChannel.SendMessageAsync($"**{pkmn.Name} (#{pokemon})** | **{pkmnStats.Shiny.ToString("N0")}** shiny out of **{pkmnStats.Total.ToString("N0")}** total seen in the last 24 hours{chanceMessage}."); } var total = stats[0]; var ratio = total.Shiny == 0 || total.Total == 0 ? null : $" with a **1/{Convert.ToInt32(total.Total / total.Shiny)}** ratio in total"; await statsChannel.SendMessageAsync($"Found **{total.Shiny.ToString("N0")}** total shinies out of **{total.Total.ToString("N0")}** possiblities{ratio}."); } } var channelIds = _dep.WhConfig.Discord.QuestChannelIds; for (var i = 0; i < channelIds.Count; i++) { var item = await _client.DeleteMessages(channelIds[i]); _logger.Debug($"Deleted all {item.Item2.ToString("N0")} quest messages from channel {item.Item1.Name}."); } _logger.Debug($"Finished automatic quest messages cleanup..."); CleanupDepartedMembers(); }
private async Task PostShinyStats(DiscordClient client, ulong guildId, DiscordServerConfig server) { var statsChannel = await client.GetChannelAsync(server.ShinyStats.ChannelId); if (statsChannel == null) { _logger.Warn($"Unable to get channel id {server.ShinyStats.ChannelId} to post shiny stats."); return; } if (server.ShinyStats.ClearMessages) { _logger.Debug($"Deleting previous shiny stats messages in channel {server.ShinyStats.ChannelId}"); await client.DeleteMessages(server.ShinyStats.ChannelId); } //var guildId = server.GuildId; _logger.Debug($"Posting shiny stats for guild {client.Guilds[guildId].Name} ({guildId}) in channel {server.ShinyStats.ChannelId}"); // Subtract an hour to make sure it shows yesterday's date. await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_TITLE").FormatText(DateTime.Now.Subtract(TimeSpan.FromHours(1)).ToLongDateString())); Thread.Sleep(500); await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_NEWLINE")); var stats = await ShinyStats.GetShinyStats(_whConfig.Instance.Database.Scanner.ToString()); if (stats == null) { _logger.Error($"Failed to get list of shiny stats for guild {guildId}, skipping..."); return; } var sorted = stats.Keys.ToList(); sorted.Sort(); foreach (var pokemon in sorted) { if (pokemon == 0) { continue; } if (!MasterFile.Instance.Pokedex.ContainsKey((int)pokemon)) { continue; } var pkmn = MasterFile.Instance.Pokedex[(int)pokemon]; var pkmnStats = stats[pokemon]; var chance = pkmnStats.Shiny == 0 || pkmnStats.Total == 0 ? 0 : Convert.ToInt32(pkmnStats.Total / pkmnStats.Shiny); if (chance == 0) { await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_MESSAGE").FormatText(pkmn.Name, pokemon, pkmnStats.Shiny.ToString("N0"), pkmnStats.Total.ToString("N0"))); } else { await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_MESSAGE_WITH_RATIO").FormatText(pkmn.Name, pokemon, pkmnStats.Shiny.ToString("N0"), pkmnStats.Total.ToString("N0"), chance)); } Thread.Sleep(500); } var total = stats[0]; var totalRatio = total.Shiny == 0 || total.Total == 0 ? 0 : Convert.ToInt32(total.Total / total.Shiny); if (totalRatio == 0) { await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_TOTAL_MESSAGE").FormatText(total.Shiny.ToString("N0"), total.Total.ToString("N0"))); } else { await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_TOTAL_MESSAGE_WITH_RATIO").FormatText(total.Shiny.ToString("N0"), total.Total.ToString("N0"), totalRatio)); } Thread.Sleep(10 * 1000); }