fix: some exception handling in BotManager

This commit is contained in:
goat 2020-07-21 16:07:17 +02:00
parent a9b388f9de
commit 721527dd11

View file

@ -90,6 +90,7 @@ namespace Dalamud.DiscordBot {
if (!this.IsConnected) if (!this.IsConnected)
return; return;
try {
var contentName = cfc.Name; var contentName = cfc.Name;
if (this.config.CfNotificationChannel == null) if (this.config.CfNotificationChannel == null)
@ -107,10 +108,17 @@ namespace Dalamud.DiscordBot {
}; };
await channel.SendMessageAsync(embed: embedBuilder.Build()); await channel.SendMessageAsync(embed: embedBuilder.Build());
} catch (Exception ex) {
Log.Error(ex, "Could not process CF pop.");
}
} }
public async Task ProcessCfPreferredRoleChange(string rouletteName, string prevRoleName, string currentRoleName) public async Task ProcessCfPreferredRoleChange(string rouletteName, string prevRoleName, string currentRoleName)
{ {
if (!this.IsConnected)
return;
try {
if (this.config.CfPreferredRoleChannel == null) if (this.config.CfPreferredRoleChannel == null)
return; return;
@ -125,7 +133,8 @@ namespace Dalamud.DiscordBot {
{ {
Title = "Roulette bonus changed: " + rouletteName, Title = "Roulette bonus changed: " + rouletteName,
Description = $"From {prevRoleName} to {currentRoleName}", Description = $"From {prevRoleName} to {currentRoleName}",
Footer = new EmbedFooterBuilder { Footer = new EmbedFooterBuilder
{
Text = $"On {world} | XIVLauncher" Text = $"On {world} | XIVLauncher"
}, },
Timestamp = DateTimeOffset.Now, Timestamp = DateTimeOffset.Now,
@ -133,9 +142,16 @@ namespace Dalamud.DiscordBot {
}; };
await channel.SendMessageAsync(embed: embedBuilder.Build()); await channel.SendMessageAsync(embed: embedBuilder.Build());
} catch (Exception ex) {
Log.Error(ex, "Could not process preferred role.");
}
} }
public async Task ProcessRetainerSale(uint itemId, int amount, bool isHq) { public async Task ProcessRetainerSale(uint itemId, int amount, bool isHq) {
if (!IsConnected)
return;
try {
if (this.config.RetainerNotificationChannel == null) if (this.config.RetainerNotificationChannel == null)
return; return;
@ -146,20 +162,25 @@ namespace Dalamud.DiscordBot {
var character = this.dalamud.ClientState.LocalPlayer; var character = this.dalamud.ClientState.LocalPlayer;
var characterInfo = await GetCharacterInfo(character.Name, character.HomeWorld.GameData.Name); var characterInfo = await GetCharacterInfo(character.Name, character.HomeWorld.GameData.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 { Footer = new EmbedFooterBuilder
{
Text = $"XIVLauncher | {character.Name}", Text = $"XIVLauncher | {character.Name}",
IconUrl = characterInfo.AvatarUrl IconUrl = characterInfo.AvatarUrl
} }
}; };
await channel.SendMessageAsync(embed: embedBuilder.Build()); await channel.SendMessageAsync(embed: embedBuilder.Build());
} catch (Exception ex) {
Log.Error(ex, "Could not process retainer msg.");
}
} }
public async Task ProcessChatMessage(XivChatType type, SeString message, SeString sender) { public async Task ProcessChatMessage(XivChatType type, SeString message, SeString sender) {