public async Task Update() { Log.Write("Updating lodestone news", "Bot"); if (!ulong.TryParse(Settings.Load().LodestoneChannel, out ulong channelId)) { return; } List <NewsItem> news = await NewsAPI.Feed(); news.Reverse(); foreach (NewsItem item in news) { if (item.Id == null) { continue; } PostedNews entry = await this.newsDb.LoadOrCreate(item.Id); if (!entry.IsPosted) { Log.Write("Posting Lodestone news: " + item.Title, "Bot"); await item.Post(channelId); entry.IsPosted = true; await this.newsDb.Save(entry); // don't flood channel! await Task.Delay(500); } } }
public async Task Update() { Log.Write("Updating lodestone news for all guilds", "Bot"); List <NewsItem> news = await NewsAPI.Feed(); news.Reverse(); foreach (SocketGuild guild in Program.DiscordClient.Guilds) { GuildSettings settings = await SettingsService.GetSettings <GuildSettings>(guild.Id); if (!ulong.TryParse(settings.LodestoneChannel, out ulong channelId)) { return; } foreach (NewsItem item in news) { if (item.Id == null) { continue; } PostedNews entry = await this.newsDb.LoadOrCreate(item.Id); if (!entry.IsPosted) { if (item.Description == null && item.Url != null) { item.Description = await NewsAPI.Detail(item.Url); } Log.Write("Posting Lodestone news: " + item.Title, "Bot"); await item.Post(channelId); entry.IsPosted = true; await this.newsDb.Save(entry); // don't flood channel! await Task.Delay(500); } } } }
public async Task News(CommandMessage message) { Log.Write("Updating lodestone news for guild: " + message.Guild.Name, "Bot"); List <NewsItem> news = await NewsAPI.Feed(); news.Reverse(); GuildSettings settings = await SettingsService.GetSettings <GuildSettings>(message.Guild.Id); if (!ulong.TryParse(settings.LodestoneChannel, out ulong channelId)) { return; } foreach (NewsItem item in news) { if (item.Id == null) { continue; } PostedNews entry = await this.newsDb.LoadOrCreate(item.Id); if (!entry.IsPosted) { Log.Write("Posting Lodestone news: " + item.Title, "Bot"); await item.Post(channelId); entry.IsPosted = true; await this.newsDb.Save(entry); // don't flood channel! await Task.Delay(500); } } }