Skip to content

Commit

Permalink
Slack on large change lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Jleagle committed Feb 8, 2019
1 parent 71c8aa4 commit 0e325c1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Steam.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SteamKit2;
using Updater.Consumers;
Expand All @@ -27,6 +31,8 @@ public static class Steam
public static SteamApps steamApps;
public static SteamFriends steamFriends;

private static readonly HttpClient httpClient = new HttpClient();

public static void startSteam(Boolean debug)
{
// Debug
Expand Down Expand Up @@ -100,6 +106,20 @@ private static async void CheckForChanges(Object obj, EventArgs args)
)
);

// Slack
var total = callback.AppChanges.Count + callback.PackageChanges.Count;
if (total >= 100)
{
try
{
await slack(total + " products queued");
}
catch (Exception e)
{
Log.GoogleInfo(e.ToString());
}
}

// Save apps
foreach (var appID in callback.AppChanges.Keys)
{
Expand Down Expand Up @@ -188,6 +208,18 @@ private static void OnLoggedOff(SteamUser.LoggedOffCallback callback)
steamClient.Disconnect();
}
}

private static async Task<String> slack(String text)
{
var values = new Dictionary<String, String>
{
{"text", text}
};

var content = new StringContent(JsonConvert.SerializeObject(values), Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(Config.slackWebhook, content);
return await response.Content.ReadAsStringAsync();
}
}

internal class DebugListener : IDebugListener
Expand All @@ -208,6 +240,7 @@ public class ChangeMessage
[JsonProperty(PropertyName = "id")]
public UInt32 ID;

// ReSharper disable once NotAccessedField.Global
public PICSChangesCallback PICSChanges;

public static BaseMessage create(UInt32 id, PICSChangesCallback pics = null)
Expand Down

0 comments on commit 0e325c1

Please sign in to comment.