Fixes for discord webhook (not finished yet)

This commit is contained in:
Vortrex
2022-04-06 16:36:50 -05:00
parent 5d762ac09e
commit 1752a1a659
5 changed files with 29 additions and 18 deletions

View File

@@ -123,13 +123,12 @@ class ServerData {
this.introMusicURL = dbAssoc["svr_intro_music"]; this.introMusicURL = dbAssoc["svr_intro_music"];
this.realTimeZone = dbAssoc["svr_time_realtime_timezone"]; this.realTimeZone = dbAssoc["svr_time_realtime_timezone"];
this.discordConfig = { this.discord = {
eventChannelWebHookURL: dbAssoc["svr_discord_event_webhook"], logChannelWebhookURL: dbAssoc["svr_discord_event_webhook"],
chatChannelWebHookURL: dbAssoc["svr_discord_chat_webhook"],
adminChannelWebHookURL: dbAssoc["svr_discord_admin_webhook"], adminChannelWebHookURL: dbAssoc["svr_discord_admin_webhook"],
sendEvents: true, sendEvents: true,
sendChat: true, sendChat: true,
sendAdminEvents: true, sendAdmin: true,
}; };
} }
} }

View File

@@ -112,6 +112,7 @@ function loadGlobalConfig() {
getGlobalConfig().economy = loadEconomyConfig(); getGlobalConfig().economy = loadEconomyConfig();
getGlobalConfig().locale = loadLocaleConfig(); getGlobalConfig().locale = loadLocaleConfig();
getGlobalConfig().accents = loadAccentConfig(); getGlobalConfig().accents = loadAccentConfig();
getGlobalConfig().discord = loadDiscordConfig();
} }
// =========================================================================== // ===========================================================================
@@ -746,6 +747,15 @@ function loadAccentConfig() {
// =========================================================================== // ===========================================================================
function loadDiscordConfig() {
let discordConfig = JSON.parse(loadTextFile(`config/discord.json`));
if(discordConfig != null) {
return discordConfig;
}
}
// ===========================================================================
function doesServerHaveGUIEnabled() { function doesServerHaveGUIEnabled() {
return getServerConfig().useGUI; return getServerConfig().useGUI;
} }

View File

@@ -89,34 +89,34 @@ function getDiscordUserData(discordUserId) {
// =========================================================================== // ===========================================================================
function messageDiscordChatChannel(messageString) { function messageDiscordChatChannel(messageString) {
if(!getServerConfig().discordConfig.sendChat) { if(!getServerConfig().discord.sendChat) {
return false; return false;
} }
messageString = removeColoursInMessage(messageString); messageString = removeColoursInMessage(messageString);
triggerWebHook(getServerConfig().discord.logWebHookURL, JSON.stringify(messageString)); triggerWebHook(encodeURI(getServerConfig().discord.logChannelWebhookURL), encodeURI(messageString));
} }
// =========================================================================== // ===========================================================================
function messageDiscordAdminChannel(messageString) { function messageDiscordAdminChannel(messageString) {
if(!getServerConfig().discordConfig.sendAdmin) { if(!getServerConfig().discord.sendAdmin) {
return false; return false;
} }
messageString = removeColoursInMessage(messageString); messageString = removeColoursInMessage(messageString);
triggerWebHook(getServerConfig().discord.adminWebHookURL, JSON.stringify(messageString)); triggerWebHook(encodeURI(getServerConfig().discord.adminChannelWebhookURL), encodeURI(messageString));
} }
// =========================================================================== // ===========================================================================
function messageDiscordEventChannel(messageString) { function messageDiscordEventChannel(messageString) {
if(!getServerConfig().discordConfig.sendEvents) { if(!getServerConfig().discord.sendEvents) {
return false; return false;
} }
messageString = removeColoursInMessage(messageString); messageString = removeColoursInMessage(messageString);
triggerWebHook(getServerConfig().discord.logWebHookURL, JSON.stringify(messageString)); triggerWebHook(encodeURI(getServerConfig().discord.logChannelWebhookURL), encodeURI(messageString));
} }
// =========================================================================== // ===========================================================================

View File

@@ -52,7 +52,7 @@ function messagePlayerNormal(client, messageText, colour = COLOUR_WHITE) {
// =========================================================================== // ===========================================================================
function messageAdmins(messageText, colour = getColourByName("softRed")) { function messageAdmins(messageText, colour = getColourByName("softRed")) {
//let plainMessage = removeColoursInMessage(messageText); //
//console.warn(`🛡️ ${plainMessage}`); //console.warn(`🛡️ ${plainMessage}`);
let clients = getClients(); let clients = getClients();
@@ -62,9 +62,8 @@ function messageAdmins(messageText, colour = getColourByName("softRed")) {
} }
} }
//if(getServerConfig().discordConfig.sendAdminEvents) { let plainMessage = removeColoursInMessage(messageText);
// messageDiscordAdminChannel(plainMessage); messageDiscordAdminChannel(plainMessage);
//}
} }
// =========================================================================== // ===========================================================================

View File

@@ -395,12 +395,15 @@ function getClientFromSyncerId(syncerId) {
// =========================================================================== // ===========================================================================
async function triggerWebHook(webHookURL, payloadData) { async function triggerWebHook(webHookURL, messageString) {
return new Promise(resolve => { return new Promise(resolve => {
//console.warn(webHookURL); let tempURL = getGlobalConfig().discord.webhook.baseURL;
tempURL = tempURL.replace("{0}", messageString);
tempURL = tempURL.replace("{1}", webHookURL);
httpGet( httpGet(
webHookURL, tempURL,
`data=${payloadData}`, "",
function(data) { function(data) {
//console.warn(JSON.parse(data)); //console.warn(JSON.parse(data));
}, },