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,76 +90,97 @@ namespace Dalamud.DiscordBot {
if (!this.IsConnected) if (!this.IsConnected)
return; return;
var contentName = cfc.Name; try {
var contentName = cfc.Name;
if (this.config.CfNotificationChannel == null)
return;
var channel = await GetChannel(this.config.CfNotificationChannel); if (this.config.CfNotificationChannel == null)
return;
var iconFolder = (cfc.Image / 1000) * 1000; var channel = await GetChannel(this.config.CfNotificationChannel);
var embedBuilder = new EmbedBuilder { var iconFolder = (cfc.Image / 1000) * 1000;
Title = "Duty is ready: " + contentName,
Timestamp = DateTimeOffset.Now,
Color = new Color(0x297c00),
ImageUrl = "https://xivapi.com" + $"/i/{iconFolder}/{cfc.Image}.png"
};
await channel.SendMessageAsync(embed: embedBuilder.Build()); var embedBuilder = new EmbedBuilder {
Title = "Duty is ready: " + contentName,
Timestamp = DateTimeOffset.Now,
Color = new Color(0x297c00),
ImageUrl = "https://xivapi.com" + $"/i/{iconFolder}/{cfc.Image}.png"
};
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.config.CfPreferredRoleChannel == null) if (!this.IsConnected)
return; return;
var channel = await GetChannel(this.config.CfPreferredRoleChannel); try {
if (this.config.CfPreferredRoleChannel == null)
return;
var world = string.Empty; var channel = await GetChannel(this.config.CfPreferredRoleChannel);
if (this.dalamud.ClientState.Actors.Length > 0) var world = string.Empty;
world = this.dalamud.ClientState.LocalPlayer.CurrentWorld.GameData.Name;
var embedBuilder = new EmbedBuilder if (this.dalamud.ClientState.Actors.Length > 0)
{ world = this.dalamud.ClientState.LocalPlayer.CurrentWorld.GameData.Name;
Title = "Roulette bonus changed: " + rouletteName,
Description = $"From {prevRoleName} to {currentRoleName}",
Footer = new EmbedFooterBuilder {
Text = $"On {world} | XIVLauncher"
},
Timestamp = DateTimeOffset.Now,
Color = new Color(0xf5aa42),
};
await channel.SendMessageAsync(embed: embedBuilder.Build()); var embedBuilder = new EmbedBuilder
{
Title = "Roulette bonus changed: " + rouletteName,
Description = $"From {prevRoleName} to {currentRoleName}",
Footer = new EmbedFooterBuilder
{
Text = $"On {world} | XIVLauncher"
},
Timestamp = DateTimeOffset.Now,
Color = new Color(0xf5aa42),
};
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 (this.config.RetainerNotificationChannel == null) if (!IsConnected)
return; return;
var channel = await GetChannel(this.config.RetainerNotificationChannel);
dynamic item = XivApi.GetItem(itemId).GetAwaiter().GetResult(); try {
if (this.config.RetainerNotificationChannel == null)
return;
var character = this.dalamud.ClientState.LocalPlayer; var channel = await GetChannel(this.config.RetainerNotificationChannel);
var characterInfo = await GetCharacterInfo(character.Name, character.HomeWorld.GameData.Name);
var embedBuilder = new EmbedBuilder { dynamic item = XivApi.GetItem(itemId).GetAwaiter().GetResult();
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,
Footer = new EmbedFooterBuilder {
Text = $"XIVLauncher | {character.Name}",
IconUrl = characterInfo.AvatarUrl
}
};
await channel.SendMessageAsync(embed: embedBuilder.Build()); var character = this.dalamud.ClientState.LocalPlayer;
var characterInfo = await GetCharacterInfo(character.Name, character.HomeWorld.GameData.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,
Footer = new EmbedFooterBuilder
{
Text = $"XIVLauncher | {character.Name}",
IconUrl = characterInfo.AvatarUrl
}
};
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) {