Skip to content

Commit 05bbafa

Browse files
authored
Merge pull request #1 from noillt/init
Init
2 parents 023e520 + d8351c4 commit 05bbafa

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# sm-gcdr
2-
Game Chat to Discord Relay SourceMod plugin
1+
# Game Chat to Discord Relay
2+
Relay game chat in your source dedicated server to a discord chat.
3+
4+
## Dependencies
5+
6+
This plugin requires [sm-ripext](https://github.com/ErikMinekus/sm-ripext) extension.
7+
1. Download latest `sm-ripext` from their [Releases](https://github.com/ErikMinekus/sm-ripext/releases)
8+
2. Extract to `/path/to/cstrike/`
9+
3. Within server run `sm exts load rip` or restart server
10+
11+
# Setup
12+
13+
1. Download latest version from [Releases](https://github.com/noillt/sm-gcdr/releases)
14+
2. Extract to `/path/to/cstrike/`
15+
3. Configure Webhook and Enable plugin in `/path/to/cstrike/cfg/sourcemod/gcdr.cfg`
16+
4. Within server run `sm plugins load gcdr`
17+
18+
## Discord Webhook
19+
20+
1. Open the Discord channel you want to receive GitLab event notifications.
21+
2. From the channel menu, select Edit channel.
22+
3. Select Integrations.
23+
4. If there are no existing webhooks, select Create Webhook. Otherwise, select View Webhooks then New Webhook.
24+
5. Enter the name of the bot to post the message.
25+
6. Optional. Edit the avatar.
26+
7. Copy the URL from the WEBHOOK URL field.

addons/sourcemod/plugins/gcdr.smx

4.03 KB
Binary file not shown.

addons/sourcemod/scripting/gcdr.sp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <sourcemod>
2+
#include <basecomm>
3+
#include <ripext>
4+
5+
public Plugin myinfo =
6+
{
7+
name = "gcdr",
8+
author = "noil.lt",
9+
description = "Game Chat to Discord Relay.",
10+
version = "0.3",
11+
url = "https://noil.lt/"
12+
};
13+
14+
ConVar g_cvEnable;
15+
ConVar g_cvWebhook;
16+
17+
public void OnPluginStart()
18+
{
19+
g_cvEnable = CreateConVar("gcdr_enable", "0", "Toggle whether plugin is enabled. 1 = Enabled, 0 = Disabled");
20+
g_cvWebhook = CreateConVar("gcdr_discord_webhook_url", "", "Discord webhook full URL", FCVAR_PROTECTED);
21+
22+
AutoExecConfig(true, "gcdr");
23+
}
24+
25+
void OnRequestFinished(HTTPResponse response, any value, const char[] error)
26+
{
27+
if (response.Status != HTTPStatus_NoContent) {
28+
LogMessage("Could not send message. Response Code: %d, Error: %s", response.Status, error);
29+
}
30+
}
31+
32+
public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
33+
{
34+
// Do not run if either: Plugin Disabled, Player Gagged, Chat Trigger, Is Console
35+
if (!g_cvEnable.BoolValue) return;
36+
if (BaseComm_IsClientMuted(client) || IsChatTrigger()) return;
37+
if (client <= 0) return;
38+
39+
char WebhookUrl[1024], msgContent[512], clientName[128], steamID[64];
40+
GetConVarString(g_cvWebhook, WebhookUrl, sizeof(WebhookUrl));
41+
GetClientName(client, clientName, sizeof(clientName));
42+
GetClientAuthId(client, AuthId_Steam2, steamID, sizeof(steamID));
43+
44+
HTTPRequest request = new HTTPRequest(WebhookUrl);
45+
JSONObject payload = new JSONObject();
46+
47+
ReplaceString(clientName, sizeof(clientName), "@", "", false);
48+
ReplaceString(clientName, sizeof(clientName), "\\", "", false);
49+
ReplaceString(clientName, sizeof(clientName), "\\\\", "", false);
50+
ReplaceString(clientName, sizeof(clientName), "`", "", false);
51+
52+
FormatEx(clientName, sizeof(clientName), "%s (%s)", clientName, steamID);
53+
FormatEx(msgContent, sizeof(msgContent), "%s", sArgs);
54+
55+
payload.SetString("username", clientName);
56+
payload.SetString("content", msgContent);
57+
58+
request.Post(view_as<JSON>(payload), OnRequestFinished);
59+
delete payload;
60+
}

cfg/sourcemod/gcdr.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file was auto-generated by SourceMod (v1.11.0.6964)
2+
// ConVars for plugin "gcdr.smx"
3+
4+
5+
// Discord webhook full URL
6+
// -
7+
// Default: ""
8+
gcdr_discord_webhook_url ""
9+
10+
// Toggle whether plugin is enabled. 1 = Enabled, 0 = Disabled
11+
// -
12+
// Default: "0"
13+
gcdr_enable "0"

0 commit comments

Comments
 (0)