#pragma semicolon 1 #include #include #include #include #include #define API_URL "" #define BOT_TOKEN "" int i_port = 0; public Plugin myinfo = { name = "livechat stoat", author = "jenz", description = "", version = "1.1.0", url = "www.unloze.com" } public void OnMapStart() { CreateTimer(5.0, SendMapNotificationToStoat); } public Action SendMapNotificationToStoat(Handle timer) { if (i_port == 27015) { char sText[1024]; char sCurrentmap[64]; GetCurrentMap(sCurrentmap, sizeof(sCurrentmap)); int NumPlayers = GetClientCount(false); char serverIp[32]; ConVar ip_cvar = FindConVar("ip"); ip_cvar.GetString(serverIp, sizeof(serverIp)); Format(sText, sizeof(sText), "Map changed to: %s\nPlayerCount: %i/65\nQuick Join: %s:%i", sCurrentmap, NumPlayers, serverIp, i_port); SendToMapNotifications_endpoint(sText); } return Plugin_Handled; } void SendToMapNotifications_endpoint(const char[] msg) { HTTPRequest request = new HTTPRequest(""); request.SetHeader("Content-Type", "application/json"); char content[1024]; Format(content, sizeof(content), "**%s**", msg); JSONObject data = new JSONObject(); data.SetString("content", content); request.Post(data, OnHTTPResponse); delete data; } public void OnPluginStart() { i_port = GetConVarInt(FindConVar("hostport")); AddCommandListener(CommandListener_SmChat_stoat, "say"); RegServerCmd("sm_printtoallchat_stoat", Command_PrintToAllChat_stoat, "Stoat Integration"); RegServerCmd("sm_printtoadminchat_stoat", Command_PrintToAdminChat_stoat, "Stoat Integration"); } public Action CommandListener_SmChat_stoat(int client, const char[] sCommand, int argc) { if (client <= 0) return Plugin_Continue; char sText[256]; char sUsername[32]; GetCmdArgString(sText, sizeof(sText)); GetClientName(client, sUsername, sizeof(sUsername)); if (FindCharInString(sText, '!') > 0) { return Plugin_Continue; } if (FindCharInString(sText, '/') > 0) { return Plugin_Continue; } if (sText[0] == '/') { return Plugin_Continue; } if (sText[0] == '!') { return Plugin_Continue; } //LogMessage("sText: %s. sText[0]: %c", sText, sText[0]); if (i_port == 27015) { SendToStoat(sUsername, sText, ""); } else if (i_port == 27017) { SendToStoat(sUsername, sText, ""); } return Plugin_Continue; } void SendToStoat(const char[] name, const char[] msg, const char[] channel_id) { char formatted_api[1024]; Format(formatted_api, sizeof(formatted_api), "%s%s%s", API_URL, channel_id, "/messages"); HTTPRequest request = new HTTPRequest(formatted_api); request.SetHeader("x-bot-token", BOT_TOKEN); request.SetHeader("Content-Type", "application/json"); char content[1024]; Format(content, sizeof(content), "**%s**: %s", name, msg); JSONObject data = new JSONObject(); data.SetString("content", content); request.Post(data, OnHTTPResponse); delete data; } void OnHTTPResponse(HTTPResponse response, any value, const char[] error) { /* if (strlen(error) > 0) { LogError("HTTP request failed: %s", error); return; } int status = response.Status; if (status != HTTPStatus_OK && status != HTTPStatus_Created) { LogError("Unexpected HTTP status: %d", status); // Optionally log the response body to see what the server returned JSONObject body = view_as(response.Data); if (body != null) { char bodyStr[1024]; body.ToString(bodyStr, sizeof(bodyStr)); LogError("Response body: %s", bodyStr); } } else { LogMessage("Message sent successfully, status: %d", status); } */ } public Action Command_PrintToAllChat_stoat(int args) { char sArgs[1024]; char sArgs2[1024]; GetCmdArg(1, sArgs, sizeof(sArgs)); GetCmdArg(2, sArgs2, sizeof(sArgs2)); CPrintToChatAll("{azure}[Stoat] (ALL) %s: {white}%s", sArgs, sArgs2); return Plugin_Handled; } public Action Command_PrintToAdminChat_stoat(int args) { char sArgs[1024]; char sArgs2[1024]; GetCmdArg(1, sArgs, sizeof(sArgs)); GetCmdArg(2, sArgs2, sizeof(sArgs2)); for(int i = 0; i < MAXPLAYERS; i++) { if (IsValidClient(i)) { bool bAdmin = CheckCommandAccess(i, "", ADMFLAG_GENERIC, true); if (bAdmin) CPrintToChat(i, "{green}(Stoat ADMINS) %s: {yellow}%s", sArgs, sArgs2); } } return Plugin_Handled; } public void GetDiscordToStoat(const char[] username, const char[] message, int type) { //type = 1. ADMINLOGS //type = 2. ADMIN LOGS BHOPPING ZE //type = 3. AMDIN LOGS entwatch //type = 4. admin logs ze ban evasion //type = 5. Calladmin //type = 6. admin chat ze if (i_port == 27017) { if (type == 1) { SendToStoat(username, message, ""); } else if (type == 2) { SendToStoat(username, message, ""); } return; } if (type == 1) { SendToStoat(username, message, ""); } else if (type == 2) { SendToStoat(username, message, ""); } else if (type == 3) { SendToStoat(username, message, ""); } else if (type == 4) { SendToStoat(username, message, ""); } else if (type == 5) { SendToStoat(username, message, ""); } else if(type == 6) { SendToStoat(username, message, ""); } } stock bool IsValidClient(int client) { return (client > 0 && client <= MaxClients && IsClientInGame(client)); }