private async Task PrepareFinishedDiscordMessage(ulong channelId, JsonClasses.Contract contract, string mention, bool isCorp, long characterId, long corpId, string token, ContractNotifyFilter filter) { await PrepareDiscordMessage(channelId, contract, mention, isCorp, characterId, corpId, token, filter); }
private async Task PrepareDiscordMessage(ulong channelId, JsonClasses.Contract contract, string mention, bool isCorp, long characterId, long corpId, string token, ContractNotifyFilter filter) { var image = string.Empty; var typeName = string.Empty; uint color = 0xff0000; switch (contract.status) { //finished case var s when _finishedStatuses.Contains(s): image = Settings.Resources.ImgContractDelete; break; default: image = Settings.Resources.ImgContract; break; } var statusName = string.Empty; switch (contract.status) { case "finished_issuer": case "finished_contractor": case "finished": statusName = "Completed"; color = 0x00ff00; break; case "cancelled": statusName = "Cancelled"; break; case "rejected": statusName = "Rejected"; break; case "failed": statusName = "Failed"; break; case "deleted": statusName = "Deleted"; break; case "reversed": statusName = "Reversed"; break; case "in_progress": statusName = "In Progress"; color = 0xFFFF33; break; case "outstanding": statusName = "Outstanding"; color = 0xFFFF33; break; default: return; } var days = 0; var expire = 0; var endLocation = string.Empty; switch (contract.type) { case "item_exchange": typeName = LM.Get("contractTypeExchange"); break; case "auction": typeName = LM.Get("contractTypeAuction"); break; case "courier": typeName = LM.Get("contractTypeCourier"); days = contract.days_to_complete; expire = (int)(contract.DateExpired - contract.DateIssued).Value.TotalDays; endLocation = (await APIHelper.ESIAPI.GetStructureData(Reason, contract.end_location_id, token))?.name ?? (await APIHelper.ESIAPI.GetStationData(Reason, contract.end_location_id, token))?.name; endLocation = string.IsNullOrEmpty(endLocation) ? LM.Get("contractSomeCitadel") : endLocation; break; default: return; } var subject = $"{typeName} {LM.Get("contractSubject")}"; var title = string.IsNullOrEmpty(contract.title) ? "-" : contract.title; var ch = await APIHelper.ESIAPI.GetCharacterData(Reason, contract.issuer_id); var issuerName = $"[{ch.name}](https://zkillboard.com/character/{contract.issuer_id}/)"; if (contract.for_corporation) { var corp = await APIHelper.ESIAPI.GetCorporationData(Reason, contract.issuer_corporation_id); issuerName = $"[{corp.name}](https://zkillboard.com/corporation/{contract.issuer_corporation_id}/)"; } var ach = await APIHelper.ESIAPI.GetCharacterData(Reason, contract.assignee_id); var asigneeName = "public"; if (ach != null) { asigneeName = $"[{ach.name}](https://zkillboard.com/character/{contract.assignee_id}/)"; } else { var corp = await APIHelper.ESIAPI.GetCorporationData(Reason, contract.assignee_id); if (corp != null) { asigneeName = $"[{corp.name}](https://zkillboard.com/corporation/{contract.assignee_id}/)"; } else { var ally = await APIHelper.ESIAPI.GetAllianceData(Reason, contract.assignee_id); if (ally != null) { asigneeName = $"[{ally.name}](https://zkillboard.com/alliance/{contract.assignee_id}/)"; } } } //location var startLocation = (await APIHelper.ESIAPI.GetStructureData(Reason, contract.start_location_id, token))?.name ?? (await APIHelper.ESIAPI.GetStationData(Reason, contract.start_location_id, token))?.name; startLocation = string.IsNullOrEmpty(startLocation) ? LM.Get("contractSomeCitadel") : startLocation; var locationText = LM.Get("contractMsgIssued"); locationText = string.IsNullOrWhiteSpace(locationText) ? "-" : locationText; var embed = new EmbedBuilder(); if (filter.ShowOnlyBasicDetails) { embed.WithThumbnailUrl(image) .WithColor(color) .AddField(subject, title, true) .AddField(LM.Get("contractMsgIssued"), $"{LM.Get("simpleFrom").FirstLetterToUpper()} {issuerName} {LM.Get("simpleTo")} {asigneeName}", true) .AddField(LM.Get("contractMsgStatus"), $"**{statusName}**", true) .AddField(locationText, startLocation, true); if (contract.type == "courier") { embed.AddField($"{LM.Get("contractMsgCollateral")}/{LM.Get("contractMsgReward")}", $"{contract.collateral:N} / {contract.reward:N}", true); } else { if (contract.price > 0 || contract.reward > 0) { embed.AddField(LM.Get(contract.price > 0 ?"contractMsgPrice": "contractMsgReward"), contract.price > 0 ? $"{contract.price:N}" : $"{contract.reward:N}"); } else if (contract.type == "auction") { embed.AddField(LM.Get("contractMsgBuyout"), $"{contract.buyout:N}"); } } if (contract.volume > 0) { embed.AddField(LM.Get("contractMsgVolume"), $"{contract.volume:N1} m3", true); } if (filter.ShowIngameOpen) { embed.WithDescription($"[{LM.Get("contractOpenIngame")}]({WebServerModule.GetOpenContractURL(contract.contract_id)})"); } } else { var sbNames = new StringBuilder(); var sbValues = new StringBuilder(); sbNames.Append($"{LM.Get("contractMsgType")}: \n{LM.Get("contractMsgIssuedBy")}: \n{LM.Get("contractMsgIssuedTo")}: "); if (contract.acceptor_id > 0) { sbNames.Append($"\n{LM.Get("contractMsgContractor")}: "); } sbNames.Append($"\n{LM.Get("contractMsgStatus")}: "); if (contract.type == "courier") { sbNames.Append( $"\n{LM.Get("contractMsgCollateral")}: \n{LM.Get("contractMsgReward")}: \n{LM.Get("contractMsgCompleteIn")}: \n{LM.Get("contractMsgExpireIn")}: "); } else { if (contract.price > 0) { sbNames.Append($"\n{LM.Get("contractMsgPrice")}: "); } else if (contract.reward > 0) { sbNames.Append($"\n{LM.Get("contractMsgReward2")}: "); } if (contract.type == "auction") { sbNames.Append($"\n{LM.Get("contractMsgBuyout")}: "); } } sbValues.Append($"{typeName}\n{issuerName}\n{asigneeName}"); if (contract.acceptor_id > 0) { ch = await APIHelper.ESIAPI.GetCharacterData(Reason, contract.acceptor_id); sbValues.Append($"\n[{(ch?.name ?? LM.Get("Unknown"))}](https://zkillboard.com/character/{contract.acceptor_id}/)"); } sbValues.Append($"\n**{statusName}**"); if (contract.type == "courier") { sbValues.Append($"\n{contract.collateral:N}\n{contract.reward:N}\n{days} {LM.Get("contractMsgDays")}\n{expire} {LM.Get("contractMsgDays")}"); } else { if (contract.price > 0 || contract.reward > 0) { sbValues.Append(contract.price > 0 ? $"\n{contract.price:N}" : $"\n{contract.reward:N}"); } if (contract.type == "auction") { sbValues.Append($"\n{contract.buyout:N}"); } } var stampIssued = contract.DateIssued?.ToString(Settings.Config.ShortTimeFormat); var stampAccepted = contract.DateAccepted?.ToString(Settings.Config.ShortTimeFormat); var stampCompleted = contract.DateCompleted?.ToString(Settings.Config.ShortTimeFormat); var stampExpired = contract.DateExpired?.ToString(Settings.Config.ShortTimeFormat); var items = isCorp ? await APIHelper.ESIAPI.GetCorpContractItems(Reason, corpId, contract.contract_id, token) : await APIHelper.ESIAPI.GetCharacterContractItems(Reason, characterId, contract.contract_id, token); // var x2 = await APIHelper.ESIAPI.GetPublicContractItems(Reason, contract.contract_id); items = items ?? await APIHelper.ESIAPI.GetCharacterContractItems(Reason, contract.issuer_id, contract.contract_id, token); var sbItemsSubmitted = new StringBuilder(); var sbItemsAsking = new StringBuilder(); if (items != null && items.Count > 0) { foreach (var item in items) { var t = await APIHelper.ESIAPI.GetTypeId(Reason, item.type_id); if (item.is_included) { sbItemsSubmitted.Append($"{t?.name} x{item.quantity}\n"); } else { sbItemsAsking.Append($"{t?.name} x{item.quantity}\n"); } } } if (contract.volume > 0) { sbNames.Append($"\n{LM.Get("contractMsgVolume")}: "); sbValues.Append($"\n{contract.volume:N1} m3"); } var issuedText = $"{LM.Get("contractMsgIssued")}: {stampIssued}"; //EMBED embed.WithThumbnailUrl(image) .WithColor(color) .AddField(subject, title) .AddField(locationText, startLocation); if (filter.ShowIngameOpen) { embed.WithDescription($"[{LM.Get("contractOpenIngame")}]({WebServerModule.GetOpenContractURL(contract.contract_id)})\n"); } if (contract.type == "courier") { embed.AddField(LM.Get("contractMsgDestination"), endLocation); } embed.AddField(LM.Get("contractMsgDetails"), sbNames.ToString(), true) .AddField("-", sbValues.ToString(), true) .WithFooter(issuedText); if (sbItemsSubmitted.Length > 0) { var fields = sbItemsSubmitted.ToString().Split(1023).TakeSmart(5).ToList(); var head = fields.FirstOrDefault(); fields.RemoveAt(0); embed.AddField(LM.Get("contractMsgIncludedItems"), string.IsNullOrWhiteSpace(head) ? "---" : head); foreach (var field in fields) { embed.AddField($"-", string.IsNullOrWhiteSpace(field) ? "---" : field); } } if (sbItemsAsking.Length > 0) { var fields = sbItemsAsking.ToString().Split(1023).TakeSmart(5).ToList(); var head = fields.FirstOrDefault(); fields.RemoveAt(0); embed.AddField(LM.Get("contractMsgAskingItems"), string.IsNullOrWhiteSpace(head) ? "---" : head); foreach (var field in fields) { embed.AddField($"-", string.IsNullOrWhiteSpace(field) ? "---" : field); } } } if (filter.RedirectByIdInDescription && !string.IsNullOrEmpty(contract.title)) { var result = ulong.TryParse(contract.title.Trim(), out var feedId); if (!result) { var arr = contract.title.Split(' '); if (arr.Length > 1) { result = ulong.TryParse(arr[arr.Length - 1].Trim(), out feedId); } } if (result) { var user = APIHelper.DiscordAPI.GetUser(feedId); if (user != null) { await user.SendMessageAsync(">>>\n", false, embed.Build()); if (!filter.PostToChannelIfRedirected) { return; } } } } await APIHelper.DiscordAPI.SendMessageAsync(APIHelper.DiscordAPI.GetChannel(channelId), $"{mention} >>>\n", embed.Build()).ConfigureAwait(false); }
private async Task PrepareAcceptedDiscordMessage(ulong channelId, JsonClasses.Contract contract, string mention, bool isCorp, long characterId, long corpId, string token, bool filterShowIngame) { await PrepareDiscordMessage(channelId, contract, mention, isCorp, characterId, corpId, token, filterShowIngame); }