Skip to content

Commit ca5694b

Browse files
author
Lukas Gundermann
committed
Added Steam Web Api
1 parent 66bfc11 commit ca5694b

File tree

5 files changed

+126
-80
lines changed

5 files changed

+126
-80
lines changed

DiscordModNotifiyer/Apis/SteamApi.cs

+61-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,71 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Text;
3+
using System.Net.Http;
4+
using System.Threading.Tasks;
45

56
namespace DiscordModNotifiyer.Apis
67
{
78
class SteamApi
89
{
10+
private System.Timers.Timer timer;
911

12+
#region Load / Refresh Timer
13+
public SteamApi() => RefreshSettings();
14+
public void RefreshSettings()
15+
{
16+
timer = new System.Timers.Timer(Program.Settings.AutomaticRefreshMin * 1000);
17+
timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
18+
timer.Enabled = Program.Settings.AutomaticRefresh;
19+
}
20+
#endregion
21+
22+
#region Executen Steam Web Api
23+
private async void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e) => await UpdateSteamMods();
24+
public async Task UpdateSteamMods()
25+
{
26+
if (Program.Settings.SteamCollection)
27+
{
28+
var parameters = new List<KeyValuePair<string, string>>();
29+
parameters.Add(new KeyValuePair<string, string>("collectioncount", "1"));
30+
parameters.Add(new KeyValuePair<string, string>("publishedfileids[0]", Program.Settings.SteamCollectionId.ToString()));
31+
Console.WriteLine(Program.STEAM_API_COLLECTION_URL);
32+
Console.WriteLine(Program.Settings.SteamCollectionId.ToString());
33+
var httpClient = new HttpClient();
34+
35+
using (var content = new FormUrlEncodedContent(parameters))
36+
{
37+
content.Headers.Clear();
38+
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
39+
40+
HttpResponseMessage response = await httpClient.PostAsync(Program.STEAM_API_COLLECTION_URL, content);
41+
42+
Console.WriteLine(await response.Content.ReadAsStringAsync());
43+
}
44+
}
45+
else
46+
{
47+
var parameters = new List<KeyValuePair<string, string>>();
48+
parameters.Add(new KeyValuePair<string, string>("itemcount", "1"));
49+
50+
int i = 0;
51+
foreach (var id in Program.Settings.SteamModIds)
52+
{
53+
parameters.Add(new KeyValuePair<string, string>($"publishedfileids[{i++}]", id.ToString()));
54+
}
55+
56+
var httpClient = new HttpClient();
57+
58+
using (var content = new FormUrlEncodedContent(parameters))
59+
{
60+
content.Headers.Clear();
61+
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
62+
63+
HttpResponseMessage response = await httpClient.PostAsync(Program.STEAM_API_MOD_URL, content);
64+
65+
Console.WriteLine(await response.Content.ReadAsStringAsync());
66+
}
67+
}
68+
}
69+
#endregion
1070
}
1171
}

DiscordModNotifiyer/Extensions/ConsoleExtensions.cs

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Reflection;
34
using System.Text.RegularExpressions;
45

@@ -13,7 +14,7 @@ public static void ClearConsole()
1314
{
1415
Console.Clear();
1516

16-
//if (string.IsNullOrEmpty(settings.ProxyIp))
17+
//if (string.IsNullOrEmpty(Settings.ProxyIp))
1718
//{
1819
// WriteColor(@"[//--Warning------------------------------------------------------]", ConsoleColor.Yellow);
1920
// WriteColor($"[// ProxyIp:] Value is not set", ConsoleColor.Yellow);
@@ -38,24 +39,25 @@ public static void ClearConsole()
3839
//WriteColor(@"[//--Exit Codes---------------------------------------------------]", ConsoleColor.DarkGreen);
3940
//WriteColor($"[// 0:] Application successful exited", ConsoleColor.DarkGreen);
4041
//WriteColor($"[// 1:] Supported OS is not given", ConsoleColor.DarkGreen);
41-
//WriteColor($"[// 2:] User has no root permissions", ConsoleColor.DarkGreen);
42-
//WriteColor($"[// 3:] Networksadapters are not set", ConsoleColor.DarkGreen);
43-
//WriteColor(@"[//--Settings-----------------------------------------------------]", ConsoleColor.DarkGreen);
44-
//WriteColor($"[// Call on Networkchange:] {settings.CallOnNetworkchange}", ConsoleColor.DarkGreen);
45-
//WriteColor($"[// Set proxy on Autostart:] {settings.SetProxyOnStartUp}", ConsoleColor.DarkGreen);
46-
//WriteColor($"[// Proxy status:] {status}", ConsoleColor.DarkGreen);
47-
//WriteColor(@"[//--Options------------------------------------------------------]", ConsoleColor.DarkGreen);
48-
//WriteColor($"[// 1:] Toggle \"Call on Networkchange\"", ConsoleColor.DarkGreen);
49-
//WriteColor($"[// 2:] Enable proxy", ConsoleColor.DarkGreen);
50-
//WriteColor($"[// 3:] Disable proxy", ConsoleColor.DarkGreen);
51-
//WriteColor($"[// ESC:] Close application", ConsoleColor.DarkGreen);
42+
WriteColor(@"[//--Settings-----------------------------------------------------]", ConsoleColor.DarkGreen);
43+
WriteColor($"[// Automatic Refresh / Check:] {Program.Settings.AutomaticRefresh}", ConsoleColor.DarkGreen);
44+
WriteColor($"[// Automatic Refresh every (min):] {Program.Settings.AutomaticRefreshMin}", ConsoleColor.DarkGreen);
45+
WriteColor($"[// Check the Collection Id:] {Program.Settings.SteamCollection}", ConsoleColor.DarkGreen);
46+
var steamModIds = Program.Settings.SteamModIds.ToString();
47+
var ids = Program.Settings.SteamCollection ? Program.Settings.SteamCollectionId.ToString() : String.Join(", ", steamModIds);
48+
WriteColor($"[// Collection Id or Mod Ids:] {ids}", ConsoleColor.DarkGreen);
49+
WriteColor(@"[//--Options------------------------------------------------------]", ConsoleColor.DarkGreen);
50+
WriteColor($"[// 1:] Execute Refresh", ConsoleColor.DarkGreen);
51+
WriteColor($"[// 2:] Enable / Disable automatic Refresh", ConsoleColor.DarkGreen);
52+
WriteColor($"[// 3:] Reload settings.json", ConsoleColor.DarkGreen);
53+
WriteColor($"[// ESC:] Close application", ConsoleColor.DarkGreen);
5254
WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.DarkGreen);
5355
Console.WriteLine(Environment.NewLine);
5456

55-
//if (string.IsNullOrEmpty(settings.NetworkChangeAdapters))
57+
//if (string.IsNullOrEmpty(Settings.NetworkChangeAdapters))
5658
//{
5759
// WriteColor(@"[//--No Networkadapters-------------------------------------------]", ConsoleColor.DarkRed);
58-
// WriteColor($"[//:] Please insert Networkadapters (\"NetworkChangeAdapters\") in the settings.json", ConsoleColor.DarkRed);
60+
// WriteColor($"[//:] Please insert Networkadapters (\"NetworkChangeAdapters\") in the Settings.json", ConsoleColor.DarkRed);
5961
// WriteColor(@"[//---------------------------------------------------------------]", ConsoleColor.DarkRed);
6062
// if (!Debugger.IsAttached)
6163
// {

DiscordModNotifiyer/Models/Settings.cs

+6-13
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@ namespace DiscordModNotifiyer.Models
44
{
55
public class Settings
66
{
7-
public bool CallOnNetworkchange { get; set; }
8-
public string NetworkChangeAdapters { get; set; }
9-
public bool SetProxyOnStartUp { get; set; }
7+
public bool AutomaticRefresh { get; set; }
8+
public int AutomaticRefreshMin { get; set; }
109

11-
public string UniquePrefixLine { get; set; }
12-
public string UniqueSuffixLine { get; set; }
10+
public string DiscordWebHook { get; set; }
1311

14-
public string BashPath { get; set; }
15-
public string BashCommandEnable { get; set; }
16-
public string BashCommandDisable { get; set; }
17-
18-
public string ProxyIp { get; set; }
19-
public int Timeout { get; set; }
20-
21-
//public List<FileSettings> Files { get; set; }
12+
public bool SteamCollection { get; set; }
13+
public double SteamCollectionId { get; set; }
14+
public List<double> SteamModIds { get; set; }
2215
}
2316
}

DiscordModNotifiyer/Program.cs

+32-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1-
using DiscordModNotifiyer.Extensions;
1+
using DiscordModNotifiyer.Apis;
2+
using DiscordModNotifiyer.Extensions;
23
using DiscordModNotifiyer.Models;
34
using Newtonsoft.Json;
45
using System;
6+
using System.Collections.Generic;
57
using System.IO;
8+
using System.Net;
9+
using System.Net.Http;
10+
using System.Threading.Tasks;
611

712
namespace DiscordModNotifiyer
813
{
914
class Program
1015
{
1116
/// <summary>
12-
/// Global name of the settings file
17+
/// Global name of the Settings file
1318
/// </summary>
14-
private const string SETTINGS_FILENAME = "settings.json";
19+
private const string SETTINGS_FILENAME = "Settings.json";
20+
21+
/// <summary>
22+
/// Steam Api Link for a Collection id
23+
/// </summary>
24+
public const string STEAM_API_COLLECTION_URL = "https://api.steampowered.com/ISteamRemoteStorage/GetCollectionDetails/v1/?format=json";
25+
26+
/// <summary>
27+
/// Steam Api Link for a Mod id
28+
/// </summary>
29+
public const string STEAM_API_MOD_URL = "https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/?format=json";
1530

1631
/// <summary>
1732
/// Settings json file
1833
/// </summary>
19-
public static Settings settings;
34+
public static Settings Settings;
2035

2136
/// <summary>
2237
/// Constructor
2338
/// </summary>
2439
/// <param name="args"></param>
2540
static void Main(string[] args)
2641
{
27-
settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText(SETTINGS_FILENAME));
42+
Settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText(SETTINGS_FILENAME));
43+
var steamApi = new SteamApi();
44+
2845
ConsoleExtensions.ClearConsole();
2946

3047
ConsoleKeyInfo cki;
@@ -35,25 +52,25 @@ static void Main(string[] args)
3552
switch (cki.KeyChar)
3653
{
3754
case '1':
55+
_ = steamApi.UpdateSteamMods();
56+
break;
57+
case '2':
3858

3959
break;
40-
//case '2':
41-
// Clear();
42-
// EnableProxy();
43-
// break;
44-
//case '3':
45-
// Clear();
46-
// DisableProxy();
47-
// break;
60+
case '3':
61+
ReloadSettings();
62+
ConsoleExtensions.ClearConsole();
63+
steamApi.RefreshSettings();
64+
break;
4865
}
4966
} while (cki.Key != ConsoleKey.Escape);
5067

5168
Environment.Exit(0);
5269
}
5370

5471
/// <summary>
55-
/// Reload settings.json file and save them into the settings object
72+
/// Reload Settings.json file and save them into the Settings object
5673
/// </summary>
57-
public static void ReloadSettings() => settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText(SETTINGS_FILENAME));
74+
public static void ReloadSettings() => Settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText(SETTINGS_FILENAME));
5875
}
5976
}

DiscordModNotifiyer/settings.json

+11-37
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
11
{
2-
"CallOnNetworkchange": false,
3-
"NetworkChangeAdapters": "<NetworkAdapterName(s) seperate with comma>",
4-
"SetProxyOnStartUp": true,
5-
"UniquePrefixLine": "### Created by LinuxProxyChanger",
6-
"UniqueSuffixLine": "### End of LinuxProxyChanger",
7-
"BashPath": "/bin/bash",
8-
"BashCommandEnable": "source /etc/environment",
9-
"BashCommandDisable": "proxy_http=\nproxys_http=\nproxy_ftp=",
10-
"ProxyIp": "10.1.0.0",
11-
"Timeout": 5,
12-
"Files": [
13-
{
14-
"Path": "/etc/environment",
15-
"Proxy": [
16-
"http_proxy=http://<ProxyIP>:<ProxyPort>/",
17-
"http_proxy=https://<ProxyIP>:<ProxyPort>/",
18-
"ftp_proxy=http://<ProxyIP>:<ProxyPort>/",
19-
"no_proxy=<ProxyExceptions>"
20-
]
21-
},
22-
{
23-
"Path": "/etc/systemd/system/docker.service.d/http-proxy.conf",
24-
"Proxy": [
25-
"[Service]",
26-
"Environment=\"HTTP_PROXY=http://<ProxyIP>:<ProxyPort>\"",
27-
"Environment=\"HTTPS_PROXY=http://<ProxyIP>:<ProxyPort>\"",
28-
"Environment=\"ProxyExceptions>\""
29-
]
30-
},
31-
{
32-
"Path": "/etc/apt/apt.conf.d/proxy.conf",
33-
"Proxy": [
34-
"Acquire::http::Proxy \"http://<ProxyIP>:<ProxyPort>/\";",
35-
"Acquire::https::Proxy \"http://<ProxyIP>:<ProxyPort>/\";"
36-
]
37-
}
38-
]
2+
"__General": "General settings",
3+
"AutomaticRefresh": false,
4+
"AutomaticRefreshMin": 10,
5+
6+
"__Discord": "This Area is for discord settings",
7+
"DiscordWebHook": "https://discord.com/api/webhooks/885800670299574282/d4axeqS_qErnk-EKyMEMZcZCrlWH2QFI1PnmcV96aJsDeuisz8EU1t0dYwE4a8p5ZClr",
8+
9+
"__Steam": "This Area is for steam settings",
10+
"SteamCollection": true,
11+
"SteamCollectionId": 2512034643,
12+
"SteamModIds": [ 123, 456 ]
3913
}

0 commit comments

Comments
 (0)