From 0094ab120e9ebee56bf143ec22bec25d09c6bbe8 Mon Sep 17 00:00:00 2001 From: goat Date: Tue, 26 Nov 2019 00:09:19 +0900 Subject: [PATCH] Add character to retainer sales --- Dalamud/DiscordBot/DiscordBotManager.cs | 52 +++++++++++++++++-------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/Dalamud/DiscordBot/DiscordBotManager.cs b/Dalamud/DiscordBot/DiscordBotManager.cs index 8fcfcd643..74a66b195 100644 --- a/Dalamud/DiscordBot/DiscordBotManager.cs +++ b/Dalamud/DiscordBot/DiscordBotManager.cs @@ -125,18 +125,25 @@ namespace Dalamud.DiscordBot { public async Task ProcessRetainerSale(int itemId, int amount, bool isHq) { if (this.config.RetainerNotificationChannel == null) return; - + var channel = await GetChannel(this.config.RetainerNotificationChannel); dynamic item = XivApi.GetItem(itemId).GetAwaiter().GetResult(); + var character = this.dalamud.ClientState.LocalPlayer; + var characterInfo = await GetCharacterInfo(character.Name, character.HomeWorld.Name); + var embedBuilder = new EmbedBuilder { Title = (isHq ? "<:hq:593406013651156994> " : "") + item.Name, Url = "https://www.garlandtools.org/db/#item/" + itemId, Description = "Sold " + amount, Timestamp = DateTimeOffset.Now, Color = new Color(0xd89b0d), - ThumbnailUrl = "https://xivapi.com" + item.Icon + ThumbnailUrl = "https://xivapi.com" + item.Icon, + Footer = new EmbedFooterBuilder { + Text = $"XIVLauncher | {character.Name}", + IconUrl = characterInfo.AvatarUrl + } }; await channel.SendMessageAsync(embed: embedBuilder.Build()); @@ -180,23 +187,13 @@ namespace Dalamud.DiscordBot { sender = RemoveAllNonLanguageCharacters(sender); var avatarUrl = ""; - var lodestoneId = 0; + var lodestoneId = ""; if (!this.config.DisableEmbeds) { - try - { - dynamic charCandidates = await XivApi.GetCharacterSearch(sender, world); + var searchResult = await GetCharacterInfo(sender, world); - if (charCandidates.Results.Count > 0) - { - avatarUrl = charCandidates.Results[0].Avatar; - lodestoneId = charCandidates.Results[0].ID; - } - } - catch (Exception ex) - { - Log.Error(ex, "Could not get XIVAPI character search result."); - } + lodestoneId = searchResult.LodestoneId; + avatarUrl = searchResult.AvatarUrl; } Thread.Sleep(this.config.ChatDelayMs); @@ -215,7 +212,7 @@ namespace Dalamud.DiscordBot { { IconUrl = avatarUrl, Name = name, - Url = lodestoneId != 0 ? "https://eu.finalfantasyxiv.com/lodestone/character/" + lodestoneId : null + Url = !string.IsNullOrEmpty(lodestoneId) ? "https://eu.finalfantasyxiv.com/lodestone/character/" + lodestoneId : null }, Description = message, Timestamp = DateTimeOffset.Now, @@ -267,6 +264,27 @@ namespace Dalamud.DiscordBot { } } + private async Task<(string LodestoneId, string AvatarUrl)> GetCharacterInfo(string name, string worldName) { + try + { + dynamic charCandidates = await XivApi.GetCharacterSearch(name, worldName); + + if (charCandidates.Results.Count > 0) + { + var avatarUrl = charCandidates.Results[0].Avatar; + var lodestoneId = charCandidates.Results[0].ID; + + return (lodestoneId, avatarUrl); + } + } + catch (Exception ex) + { + Log.Error(ex, "Could not get XIVAPI character search result."); + } + + return (null, null); + } + private async Task GetChannel(ChannelConfiguration channelConfig) { if (channelConfig.Type == ChannelType.Guild) return this.socketClient.GetGuild(channelConfig.GuildId).GetTextChannel(channelConfig.ChannelId);