Skip to content

Commit

Permalink
Build n. 41
Browse files Browse the repository at this point in the history
  • Loading branch information
Plenyx committed Jun 6, 2019
1 parent 35d37ae commit 29994e9
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 32 deletions.
12 changes: 12 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@
<setting name="FirstUpdate" serializeAs="String">
<value>True</value>
</setting>
<setting name="SessionName" serializeAs="String">
<value>Log session</value>
</setting>
<setting name="SessionSuppressWebhooks" serializeAs="String">
<value>True</value>
</setting>
<setting name="SessionOnlySuccess" serializeAs="String">
<value>True</value>
</setting>
<setting name="SessionMessage" serializeAs="String">
<value />
</setting>
</PlenBotLogUploader.Properties.Settings>
</userSettings>
</configuration>
2 changes: 1 addition & 1 deletion DPSReport/Bosses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static string GetWingName(int wingNumber)
case 6:
return "Mythwright Gambit";
case 7:
return "The Key of Ahdashim";
return "Key of Ahdashim";
default:
return "Unknown wing";
}
Expand Down
1 change: 1 addition & 0 deletions DPSReport/DPSReportJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class DPSReportJSON
public DPSReportJSONEvtc Evtc { get; set; }
public DPSReportJSONEncounter Encounter { get; set; }
public Dictionary<string, DPSReportJSONPlayers> Players { get; set; } = new Dictionary<string, DPSReportJSONPlayers>();
public DPSReportJSONExtraJSON ExtraJSON { get; set; }

public string GetUrlId() => Permalink.Substring(Permalink.IndexOf("dps.report/") + 11);
}
Expand Down
9 changes: 9 additions & 0 deletions DPSReport/DPSReportJSONExtraJSON.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace PlenBotLogUploader.DPSReport
{
public class DPSReportJSONExtraJSON
{
public string EliteInsightsVersion { get; set; }
public string RecordedBy { get; set; }
public string Duration { get; set; }
}
}
27 changes: 18 additions & 9 deletions Forms/FormDiscordWebhooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public void AddWebhook(DiscordWebhookData data)
public async Task ExecuteAllActiveWebhooksAsync(DPSReportJSON reportJSON, Dictionary<int, BossData> allBosses)
{
string bossName = reportJSON.Encounter.Boss;
string successString = (reportJSON.Encounter.Success ?? false) ? "success" : "fail";
string successString = (reportJSON.Encounter.Success ?? false) ? ":white_check_mark:" : "";
string extraJSON = (reportJSON.ExtraJSON == null) ? "" : $"Recorded by: {reportJSON.ExtraJSON.RecordedBy}\nDuration: {reportJSON.ExtraJSON.Duration}\nElite Insights version: {reportJSON.ExtraJSON.EliteInsightsVersion}\n";
string icon = "";
var bossDataRef = allBosses
.Where(anon => anon.Value.BossId.Equals(reportJSON.Encounter.BossId))
Expand All @@ -119,7 +120,7 @@ public async Task ExecuteAllActiveWebhooksAsync(DPSReportJSON reportJSON, Dictio
{
Title = bossName,
Url = reportJSON.Permalink,
Description = $"Result: {successString}\narcdps version: {reportJSON.Evtc.Type}{reportJSON.Evtc.Version}",
Description = $"{extraJSON}Result: {successString}\narcdps version: {reportJSON.Evtc.Type}{reportJSON.Evtc.Version}",
Color = color,
Thumbnail = discordContentEmbedThumbnail
};
Expand All @@ -131,7 +132,7 @@ public async Task ExecuteAllActiveWebhooksAsync(DPSReportJSON reportJSON, Dictio
{
Title = bossName,
Url = reportJSON.Permalink,
Description = $"Result: {successString}\narcdps version: {reportJSON.Evtc.Type}{reportJSON.Evtc.Version}",
Description = $"{extraJSON}Result: {successString}\narcdps version: {reportJSON.Evtc.Type}{reportJSON.Evtc.Version}",
Color = color,
Thumbnail = discordContentEmbedThumbnail
};
Expand Down Expand Up @@ -188,7 +189,7 @@ public async Task ExecuteAllActiveWebhooksAsync(DPSReportJSON reportJSON, Dictio
}
}

public async Task ExecuteSessionAllActiveWebhooksAsync(List<DPSReportJSON> reportsJSON, Dictionary<int, BossData> allBosses, bool showSuccess)
public async Task ExecuteSessionAllActiveWebhooksAsync(List<DPSReportJSON> reportsJSON, Dictionary<int, BossData> allBosses, string sessionName, string contentText, bool showSuccess, string elapsedTime)
{
var RaidLogs = reportsJSON
.Where(anon => Bosses.GetWingForBoss(anon.Evtc.BossId) > 0)
Expand All @@ -207,6 +208,7 @@ public async Task ExecuteSessionAllActiveWebhooksAsync(List<DPSReportJSON> repor
.Where(anon => Bosses.IsWvW(anon.Evtc.BossId))
.ToList();
StringBuilder builder = new StringBuilder();
builder.Append($"Session duration: {elapsedTime}\n\n");
if (RaidLogs.Count > 0)
{
builder.Append("***Raid logs:***\n");
Expand All @@ -226,8 +228,9 @@ public async Task ExecuteSessionAllActiveWebhooksAsync(List<DPSReportJSON> repor
{
bossName = bossDataRef.First().Name;
}
string successText = (showSuccess) ? ((data.LogData.Encounter.Success ?? false) ? " (kill)" : "") : "";
builder.Append($"[{bossName}]({data.LogData.Permalink}){successText}\n");
string duration = (data.LogData.ExtraJSON == null) ? "" : $" {data.LogData.ExtraJSON.Duration}";
string successText = (showSuccess) ? ((data.LogData.Encounter.Success ?? false) ? " :white_check_mark:" : "") : "";
builder.Append($"[{bossName}]({data.LogData.Permalink}){duration}{successText}\n");
}
}
if (FractalLogs.Count > 0)
Expand Down Expand Up @@ -280,20 +283,21 @@ public async Task ExecuteSessionAllActiveWebhooksAsync(List<DPSReportJSON> repor
};
var discordContentEmbed = new DiscordAPIJSONContentEmbed()
{
Title = "Log session",
Title = sessionName,
Description = builder.ToString(),
Color = 32768,
Thumbnail = discordContentEmbedThumbnail
};
var discordContent = new DiscordAPIJSONContent()
{
Content = contentText,
Embeds = new List<DiscordAPIJSONContentEmbed>() { discordContentEmbed }
};
try
{
var serialiser = new JavaScriptSerializer();
serialiser.RegisterConverters(new[] { new DiscordAPIJSONContentConverter() });
string jsonContentWithoutPlayers = serialiser.Serialize(discordContent);
string jsonContent = serialiser.Serialize(discordContent);
foreach (var key in AllWebhooks.Keys)
{
var webhook = AllWebhooks[key];
Expand All @@ -302,7 +306,7 @@ public async Task ExecuteSessionAllActiveWebhooksAsync(List<DPSReportJSON> repor
continue;
}
var uri = new Uri(webhook.URL);
using (var content = new StringContent(jsonContentWithoutPlayers, Encoding.UTF8, "application/json"))
using (var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"))
{
using (await mainLink.HttpClientController.MainHttpClient.PostAsync(uri, content)) { }
}
Expand All @@ -316,6 +320,11 @@ public async Task ExecuteSessionAllActiveWebhooksAsync(List<DPSReportJSON> repor
{
mainLink.AddToText(">:> Unable to execute active webhooks with finished log session.");
}
RaidLogs = null;
FractalLogs = null;
WvWLogs = null;
GolemLogs = null;
discordContent = null;
}

private void toolStripMenuItemAdd_Click(object sender, EventArgs e)
Expand Down
74 changes: 66 additions & 8 deletions Forms/FormLogSession.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion Forms/FormLogSession.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace PlenBotLogUploader
Expand All @@ -12,6 +13,7 @@ public partial class FormLogSession : Form
// fields
private FormMain mainLink;
private bool sessionPaused = false;
private readonly Stopwatch stopWatch = new Stopwatch();
#endregion

public FormLogSession(FormMain mainLink)
Expand All @@ -25,6 +27,8 @@ private void FormLogSession_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
Hide();
Properties.Settings.Default.SessionName = textBoxSessionName.Text;
Properties.Settings.Default.SessionMessage = textBoxSessionContent.Text;
}

private async void ButtonSessionStarter_Click(object sender, EventArgs e)
Expand All @@ -36,7 +40,19 @@ private async void ButtonSessionStarter_Click(object sender, EventArgs e)
buttonUnPauseSession.Enabled = false;
SessionRunning = false;
sessionPaused = false;
await mainLink.ExecuteSessionLogWebhooksAsync(!checkBoxOnlySuccess.Checked);
groupBoxSessionSettings.Enabled = true;
stopWatch.Stop();
var elapsed = stopWatch.Elapsed;
string elapsedTime = $"{elapsed.Seconds}s";
if (elapsed.Hours > 0 || elapsed.Days > 0)
{
elapsedTime = $"{elapsed.Days * 24 + elapsed.Hours}h {elapsed.Minutes}m {elapsed.Seconds}s";
}
else if (elapsed.Minutes > 0)
{
elapsedTime = $"{elapsed.Minutes}m {elapsed.Seconds}s";
}
await mainLink.ExecuteSessionLogWebhooksAsync(textBoxSessionName.Text, textBoxSessionContent.Text, !checkBoxOnlySuccess.Checked, elapsedTime);
mainLink.SessionLogs.Clear();
}
else
Expand All @@ -46,6 +62,8 @@ private async void ButtonSessionStarter_Click(object sender, EventArgs e)
buttonUnPauseSession.Enabled = true;
SessionRunning = true;
sessionPaused = false;
groupBoxSessionSettings.Enabled = false;
stopWatch.Start();
}
}

Expand All @@ -64,5 +82,9 @@ private void ButtonUnPauseSession_Click(object sender, EventArgs e)
buttonUnPauseSession.Text = "Pause session";
}
}

public void CheckBoxSupressWebhooks_CheckedChanged(object sender, EventArgs e) => Properties.Settings.Default.SessionSuppressWebhooks = checkBoxSupressWebhooks.Checked;

public void CheckBoxOnlySuccess_CheckedChanged(object sender, EventArgs e) => Properties.Settings.Default.SessionOnlySuccess = checkBoxOnlySuccess.Checked;
}
}
2 changes: 1 addition & 1 deletion Forms/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 29994e9

Please sign in to comment.