internal async Task HandleFlashSaleUpdate(FlashSaleMessage flashSaleMessage) { // Check if setting is turned on if (bool.TryParse(await _settingManager.GetSettingValue("GUILDCONFIG_FLASHSALE_ANNNEWITEM", Guild), out var shouldAnnounce) && shouldAnnounce) { // Get the channel to announce item in ISocketMessageChannel annChannel = null; var annChannelId = await _settingManager.GetSettingValue("GUILDCONFIG_ANN_CHANNEL", Guild); if (annChannelId != null) { annChannel = Guild.GetChannel(ulong.Parse(annChannelId)) as ISocketMessageChannel; } if (annChannel != null) { var embed = await ItemHandler.CreateItemEmbed(flashSaleMessage.Item, Guild, _settingManager, true); embed.Embed.Title = "New flash sale found! - " + embed.Embed.Title; embed.Embed.Color = new global::Discord.Color(243, 181, 144); await annChannel.SendFilesAsync(embed.Files, embed : embed.Embed.Build()); } } }
internal async Task HandleNewItemUpdate(NewItemMessage newItemMessage) { // Check if setting is turned on if (bool.TryParse(await _settingManager.GetSettingValue("GUILDCONFIG_ITEMDB_ANNNEWITEM", Guild), out var shouldAnnounce) && shouldAnnounce) { // Check if item is in list of announceables var settingValue = await _settingManager.GetSettingValue("GUILDCONFIG_ITEMDB_NEWITEMTYPES", Guild); try { var itemTypesToAnnounce = (settingValue ?? "") .Split(',') .Select(x => { FRItemCategory?cat = null; if (Enum.TryParse <FRItemCategory>(x, out var category)) { cat = category; } return(cat); }) .Where(x => x != null) .Select(x => x.Value) .ToList(); if (itemTypesToAnnounce.Contains(newItemMessage.Item.ItemCategory)) { // Get the channel to announce item in ISocketMessageChannel annChannel = null; if (bool.TryParse(await _settingManager.GetSettingValue("GUILDCONFIG_ITEMDB_USEANNCHANNEL", Guild), out var useGeneralAnnChannel) && useGeneralAnnChannel) { var annChannelId = await _settingManager.GetSettingValue("GUILDCONFIG_ANN_CHANNEL", Guild); if (annChannelId != null) { annChannel = Guild.GetChannel(ulong.Parse(annChannelId)) as ISocketMessageChannel; } } else { var annNewItemChannelId = await _settingManager.GetSettingValue("GUILDCONFIG_ITEMDB_ANN_CHANNEL", Guild); if (annNewItemChannelId != null) { annChannel = Guild.GetChannel(ulong.Parse(annNewItemChannelId)) as ISocketMessageChannel; } } if (annChannel != null) { var embed = await ItemHandler.CreateItemEmbed(newItemMessage.Item, Guild, _settingManager); embed.Embed.Title = "New item found! - " + embed.Embed.Title; await annChannel.SendFilesAsync(embed.Files, embed : embed.Embed.Build()); } } } catch (Exception ex) { Console.WriteLine($"Failed to parse GUILDCONFIG_ITEMDB_NEWITEMTYPES for guild {Guild.Id}, setting had value '{settingValue}'"); Console.WriteLine(ex.ToString()); throw; } } }