-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
146 lines (124 loc) · 5.27 KB
/
Program.cs
File metadata and controls
146 lines (124 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using DiscordRPC.Message;
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using DiscordRPC.Logging;
using DiscordRPC;
using System.Timers;
using System.Net.Http;
using System.Net.Http.Headers;
using Discord_Rpc.App;
using Discord_Rpc.Parsers;
using Discord_Rpc.Version;
namespace Discord_Rpc
{
internal class Program
{
private static void Main(string[] args)
{
// == Check if the user is running the latest version
if (!VerionManager.isLatestVersion())
{
Console.WriteLine("You are not running the latest version of Discord RPC!");
Console.WriteLine($"Please update to the latest version at https://github.com/0xhylia/Discord-Rpc/releases/tag/{VerionManager.getLatestVersion()}");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
Environment.Exit(0);
}
// == Create the client
var client = new DiscordRpcClient(ConfigParser.GetConfigValue("client_id"));
// == Subscribe to some events
client.OnReady += (sender, msg) =>
{
//Create some events so we know things are happening
Console.WriteLine("Connected to discord with user {0}", msg.User.Username);
};
// == Initialize
client.Initialize();
// == Set the presence
client.SetPresence(new RichPresence()
{
Details = "At Her Desktop",
State = $"Just Chilling",
Timestamps = Timestamps.Now,
Assets = new Assets()
{
LargeImageKey = "pfp",
LargeImageText = "Hylia",
},
Buttons = new Button[]
{
new Button() { Label = "Website", Url = "https://hylia.dev/" },
new Button() { Label = "Discord Bot", Url = "https://bot.hylia.dev" }
}
});
while (true)
{
Thread.Sleep(5000);
LogActiveAppDetails(client);
}
}
// Define a global variable to store the previous app name
private static string prevApp = "";
public static void LogActiveAppDetails(DiscordRpcClient client)
{
string app = App.AppManager.getActiveApp(); // This is the app name (e.g. "Code")
string windowName = App.AppManager.GetActiveAppWindowName(app); // This is the window name (e.g. "Program.cs")
string imageKey = App.AppManager.getActiveAppImage(app); // This is the image key (e.g. "visual-studio-code")
string details = App.AppManager.getAppDetails(app); // This is the app detail (e.g. "Writing Code")
string[] detailsArray = App.AppManager.getAppDetailsArray(app); // This is an array of the app details (e.g. "Writing Code")
string fullAppName = detailsArray[3]; // This is the full app name (e.g. "Visual Studio Code")
// check if the app name has changed before calling updatePresence
if (app != prevApp)
{
var newPresence = updatePresence(client, app, windowName, imageKey, details, fullAppName);
client.SetPresence(newPresence);
}
// Store the current app name as the previous app name for the next time the method is called
prevApp = app;
}
public static RichPresence updatePresence(DiscordRpcClient client, string app, string windowName, string imageKey, string details, string fullAppName)
{
if (app == "None")
{
return new RichPresence()
{
Details = "At Her Desktop",
State = $"Just Chilling",
Timestamps = Timestamps.Now,
Assets = new Assets()
{
LargeImageKey = "pfp",
LargeImageText = "Hylia",
},
Buttons = new Button[]
{
new Button() { Label = "Website", Url = "https://hylia.dev/" },
new Button() { Label = "Discord Bot", Url = "https://bot.hylia.dev" }
}
};
}
var richPresence = new RichPresence()
{
Details = "Using " + fullAppName,
State = details,
Timestamps = Timestamps.Now,
Assets = new Assets()
{
LargeImageKey = "pfp",
LargeImageText = "Hylia",
SmallImageKey = imageKey,
SmallImageText = $"Playing {app}",
},
Buttons = new Button[]
{
new Button() { Label = "Website", Url = "https://hylia.dev/" },
new Button() { Label = "Discord Bot", Url = "https://bot.hylia.dev" }
}
};
return richPresence;
}
}
}