mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Add character to retainer sales
This commit is contained in:
parent
df8c16d2c3
commit
0094ab120e
1 changed files with 35 additions and 17 deletions
|
|
@ -125,18 +125,25 @@ namespace Dalamud.DiscordBot {
|
||||||
public async Task ProcessRetainerSale(int itemId, int amount, bool isHq) {
|
public async Task ProcessRetainerSale(int itemId, int amount, bool isHq) {
|
||||||
if (this.config.RetainerNotificationChannel == null)
|
if (this.config.RetainerNotificationChannel == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var channel = await GetChannel(this.config.RetainerNotificationChannel);
|
var channel = await GetChannel(this.config.RetainerNotificationChannel);
|
||||||
|
|
||||||
dynamic item = XivApi.GetItem(itemId).GetAwaiter().GetResult();
|
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 {
|
var embedBuilder = new EmbedBuilder {
|
||||||
Title = (isHq ? "<:hq:593406013651156994> " : "") + item.Name,
|
Title = (isHq ? "<:hq:593406013651156994> " : "") + item.Name,
|
||||||
Url = "https://www.garlandtools.org/db/#item/" + itemId,
|
Url = "https://www.garlandtools.org/db/#item/" + itemId,
|
||||||
Description = "Sold " + amount,
|
Description = "Sold " + amount,
|
||||||
Timestamp = DateTimeOffset.Now,
|
Timestamp = DateTimeOffset.Now,
|
||||||
Color = new Color(0xd89b0d),
|
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());
|
await channel.SendMessageAsync(embed: embedBuilder.Build());
|
||||||
|
|
@ -180,23 +187,13 @@ namespace Dalamud.DiscordBot {
|
||||||
sender = RemoveAllNonLanguageCharacters(sender);
|
sender = RemoveAllNonLanguageCharacters(sender);
|
||||||
|
|
||||||
var avatarUrl = "";
|
var avatarUrl = "";
|
||||||
var lodestoneId = 0;
|
var lodestoneId = "";
|
||||||
|
|
||||||
if (!this.config.DisableEmbeds) {
|
if (!this.config.DisableEmbeds) {
|
||||||
try
|
var searchResult = await GetCharacterInfo(sender, world);
|
||||||
{
|
|
||||||
dynamic charCandidates = await XivApi.GetCharacterSearch(sender, world);
|
|
||||||
|
|
||||||
if (charCandidates.Results.Count > 0)
|
lodestoneId = searchResult.LodestoneId;
|
||||||
{
|
avatarUrl = searchResult.AvatarUrl;
|
||||||
avatarUrl = charCandidates.Results[0].Avatar;
|
|
||||||
lodestoneId = charCandidates.Results[0].ID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Error(ex, "Could not get XIVAPI character search result.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.Sleep(this.config.ChatDelayMs);
|
Thread.Sleep(this.config.ChatDelayMs);
|
||||||
|
|
@ -215,7 +212,7 @@ namespace Dalamud.DiscordBot {
|
||||||
{
|
{
|
||||||
IconUrl = avatarUrl,
|
IconUrl = avatarUrl,
|
||||||
Name = name,
|
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,
|
Description = message,
|
||||||
Timestamp = DateTimeOffset.Now,
|
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<IMessageChannel> GetChannel(ChannelConfiguration channelConfig) {
|
private async Task<IMessageChannel> GetChannel(ChannelConfiguration channelConfig) {
|
||||||
if (channelConfig.Type == ChannelType.Guild)
|
if (channelConfig.Type == ChannelType.Guild)
|
||||||
return this.socketClient.GetGuild(channelConfig.GuildId).GetTextChannel(channelConfig.ChannelId);
|
return this.socketClient.GetGuild(channelConfig.GuildId).GetTextChannel(channelConfig.ChannelId);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue