From 0e325c1ac44cd58c42a1fa33761e00683381df27 Mon Sep 17 00:00:00 2001 From: James Eagle Date: Fri, 8 Feb 2019 21:14:36 +0000 Subject: [PATCH] Slack on large change lists --- Steam.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Steam.cs b/Steam.cs index cee4b86..206705f 100644 --- a/Steam.cs +++ b/Steam.cs @@ -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; @@ -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 @@ -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) { @@ -188,6 +208,18 @@ private static void OnLoggedOff(SteamUser.LoggedOffCallback callback) steamClient.Disconnect(); } } + + private static async Task slack(String text) + { + var values = new Dictionary + { + {"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 @@ -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)