-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscordUtilities.cpp
More file actions
170 lines (132 loc) · 4.16 KB
/
DiscordUtilities.cpp
File metadata and controls
170 lines (132 loc) · 4.16 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#pragma once
#include "DiscordUtilities.h"
#include "DiscordUtilitiesConfig.h"
#include "DiscordUtilitiesHooks.h"
#include <ArkApiUtils.h>
#include <macros.h>
void PostToDiscord(const std::wstring log)
{
if (!discord_enabled || discord_webhook_url.IsEmpty())
return;
const auto& tagNotifierConfig = PluginConfig["TagNotifier"];
const auto& discordRoles = tagNotifierConfig["DiscordRole"];
FString roleMentions;
for (const auto& discordRole : discordRoles)
{
if (discordRole.is_string()) {
const std::string roleValue = discordRole.get<std::string>();
roleMentions += L"<@&" + FString(roleValue.c_str()) + L"> ";
}
}
FString msg = L"{{\"content\":\"" + roleMentions + L"```stylus\\n{}```\",\"username\":\"{}\",\"avatar_url\":null}}";
FString output = FString::Format(*msg, log, discord_sender_name);
static_cast<AShooterGameState*>(ArkApi::GetApiUtils().GetWorld()->GameStateField())->HTTPPostRequest(discord_webhook_url, output);
}
void DiscordInvMessage(AShooterPlayerController* player)
{
if (!Tag_enabled)
return;
try
{
std::wstring msg = ArkApi::Tools::Utf8Decode(PluginConfig["DiscordInvite"]["InviteMsg"]);
auto config_color = PluginConfig["DiscordInvite"]["MsgColor"];
const FLinearColor color{ config_color[0], config_color[1], config_color[2], config_color[3] };
ArkApi::GetApiUtils().SendServerMessage(player, color, msg.c_str());
//Debug
//std::cout << "DiscordInvMSG" << player << std::endl;
}
catch (const std::exception& error)
{
AShooterPlayerController* shooterController = static_cast<AShooterPlayerController*>(player);
ArkApi::GetApiUtils().SendServerMessage(shooterController, FColorList::Red, "Failed to send DiscordInvMSG");
Log::GetLog()->error(error.what());
return;
}
}
void _cdecl Hook_AShooterPlayerController_ServerSendChatMessage_Impl(AShooterPlayerController* _this, FString* Message, EChatSendMode::Type Mode)
{
if (_this && Mode == EChatSendMode::Type::GlobalChat && !Message->IsEmpty())
{
//scan message for Tag word
if (DiscordPing.Num() > 0)
{
const auto& MatchingPings = DiscordPing.FindByPredicate([Message](const DiscordsPing& DiscordPing) -> bool {
return Message->Contains(DiscordPing.Tag);
});
if (MatchingPings)
{
FString playerName = *ArkApi::IApiUtils::GetSteamName(_this);
FString playerMessage = *Message;
const std::wstring log = fmt::format(TEXT("({}): {}"), *playerName, *playerMessage);
PostToDiscord(log);
}
}
//Scan message for invite word
if (DiscordInvite.Num() > 0);
{
const auto& MatchingInvite = DiscordInvite.FindByPredicate([Message](const DiscordsInvite& DiscordInvite) -> bool {
return Message->Contains(DiscordInvite.Word);
});
if (MatchingInvite)
{
DiscordInvMessage(_this);
}
}
}
AShooterPlayerController_ServerSendChatMessage_Impl_original(_this, Message, Mode);
}
void ReloadConfigCMD(APlayerController* player_controller, FString* /*unused*/, bool /*unused*/)
{
auto* shooter_controller = static_cast<AShooterPlayerController*>(player_controller);
if (player_controller->PlayerStateField() && player_controller->bIsAdmin()())
try
{
LoadConfig();
ArkApi::GetApiUtils().SendServerMessage(shooter_controller, FColorList::Green, "Reloaded DiscordUtilities config");
}
catch (const std::exception& error)
{
ArkApi::GetApiUtils().SendServerMessage(shooter_controller, FColorList::Red, "Failed to reload config");
Log::GetLog()->error(error.what());
return;
}
else
return;
}
BOOL Load()
{
Log::Get().Init("DiscordUtilities");
try
{
LoadConfig();
}
catch (const std::exception& error)
{
Log::GetLog()->error(error.what());
throw;
}
COMMANDS.AddChatCommand("/DiscordUtilitiesReload", &ReloadConfigCMD);
COMMANDS.AddConsoleCommand("DiscordUtilities.Reload", &ReloadConfigCMD);
InitHooks();
return TRUE;
}
BOOL Unload()
{
COMMANDS.RemoveChatCommand("/DiscordUtilitiesReload");
COMMANDS.RemoveConsoleCommand("DiscordUtilities.Reload");
RemoveHooks();
return TRUE;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Load();
break;
case DLL_PROCESS_DETACH:
Unload();
break;
}
return TRUE;
}