sm-plugins/Discord_UNLOZE/scripting/live_chat_stoat.sp
2026-02-22 23:35:39 +01:00

196 lines
4.6 KiB
SourcePawn

#pragma semicolon 1
#include <ripext>
#include <basecomm>
#include <multicolors>
#include <sourcemod>
#include <Discord_UNLOZE>
#define API_URL ""
#define BOT_TOKEN ""
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)
{
int i_port = GetConVarInt(FindConVar("hostport"));
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()
{
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]);
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) {
}
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 (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));
}