private async Task updateConfigIfRequired(IGuildConfig Cfg) { if (!String.IsNullOrEmpty(Cfg.BotVersion) && Double.TryParse(Cfg.BotVersion, out double CurrentVersion)) { if (CurrentVersion == CurrentUpdate.Version) { //The bot is up to date, nothing to do. return; } else { foreach (IBotUpdate update in Updates.Where(o => o.Version > CurrentVersion).OrderBy(o => o.Version)) { //Apply the update. update.Apply(Cfg); //Determine if we should send an update to the guild. If so, send the update. bool updateWasSent = false; if (Cfg.GetGuildChannel(WarBotChannelType.WARBOT_UPDATES).IsNotNull(out var CH) //Validate this update, should sent a message out. && update.SendUpdateToGuild //Validate the guild is opt-in to receive update messages. && Cfg[Setting_Key.WARBOT_UPDATES].Enabled //Validate I have permissions to send to this channel. && Cfg.CurrentUser.GetPermissions(CH).SendMessages) { updateWasSent = true; var eb = new EmbedBuilder() .WithTitle($"WarBot updated to version {update.Version}") .WithDescription($"I have been updated to version {update.Version} 👏") .WithFooter("To view my patch notes, click this embed.") .WithUrl(update.ReleaseNotesURL); await CH.SendMessageAsync(embed : eb.Build()); } await bot.Log.GuildUpdated(Cfg.Guild.Name, CurrentVersion, update.Version, updateWasSent); //Update the local current version. CurrentVersion = update.Version; } Cfg.BotVersion = CurrentUpdate.Version.ToString(); } } else //Unable to parse the version. Assume no updates are required. { Cfg.BotVersion = CurrentUpdate.Version.ToString(); } //Save the changes. await Cfg.SaveConfig(); }