-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiscord.cpp
More file actions
56 lines (40 loc) · 1.44 KB
/
Copy pathdiscord.cpp
File metadata and controls
56 lines (40 loc) · 1.44 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
#include "Discord.h"
#include <time.h>
#include <cstring>
#include <cstdio>
#include <chrono> // To calculate elapsed time
static const char* APPLICATION_ID = "1469448659916816548";
static int64_t StartTime;
void Discord::Initialize() {
DiscordEventHandlers handlers;
memset(&handlers, 0, sizeof(handlers));
Discord_Initialize(APPLICATION_ID, &handlers, 1, NULL);
StartTime = time(0);
}
void Discord::Update(bool isEnabled) {
Discord_RunCallbacks();
static bool wasEnabled = true;
if (!isEnabled) {
if (wasEnabled) {
Discord_ClearPresence();
wasEnabled = false;
}
return;
}
wasEnabled = true;
// 2. Time For Disocrd RPC
static auto lastUpdate = std::chrono::steady_clock::now();
auto now = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - lastUpdate).count();
if (elapsed < 2) return; // if less than 2 seconds, skip update
lastUpdate = now; // Reset time
//Discord Rich Presence stuff
DiscordRichPresence discordPresence;
memset(&discordPresence, 0, sizeof(discordPresence));
discordPresence.state = "Running Automation";
discordPresence.details = "Farming Wheat";
discordPresence.startTimestamp = StartTime;
discordPresence.largeImageKey = "rpc_logo";
discordPresence.largeImageText = "NXRTH Hay Day Bot";
Discord_UpdatePresence(&discordPresence);
}