Skip to content

Commit 95e872d

Browse files
committed
NeedSystem v1.1.2
- Added a configuration option that allows the plugin to get the hostname automatically from server.cfg and display it in the embed title. - Added a configuration option that allows the plugin to obtain IP:PORT automatically.
1 parent 4c583c4 commit 95e872d

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

NeedSystem.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ public class BaseConfigs : BasePluginConfig
7171
[JsonPropertyName("EmbedThumbnailImage")]
7272
public string EmbedThumbnailImage { get; set; } = "https://avatars.githubusercontent.com/u/61034981?v=4";
7373

74+
[JsonPropertyName("UseHostname")]
75+
public bool UseHostname { get; set; } = true;
76+
77+
[JsonPropertyName("GetIPandPORTautomatic")]
78+
public bool GetIPandPORTautomatic { get; set; } = true;
79+
7480
}
7581

7682
public class NeedSystemBase : BasePlugin, IPluginConfig<BaseConfigs>
@@ -80,7 +86,7 @@ public class NeedSystemBase : BasePlugin, IPluginConfig<BaseConfigs>
8086
private Translator _translator;
8187

8288
public override string ModuleName => "NeedSystem";
83-
public override string ModuleVersion => "1.1.1";
89+
public override string ModuleVersion => "1.1.2";
8490
public override string ModuleAuthor => "luca.uy";
8591
public override string ModuleDescription => "Allows players to send a message to discord requesting players.";
8692

@@ -290,7 +296,7 @@ public void NeedCommand(CCSPlayerController? caller, string clientName)
290296

291297
var embed = new
292298
{
293-
title = _translator["EmbedTitle"],
299+
title = Config.UseHostname ? (ConVar.Find("hostname")?.StringValue ?? _translator["EmbedTitle"]) : _translator["EmbedTitle"],
294300
description = _translator["EmbedDescription"],
295301
color = ConvertHexToColor(Config.EmbedColor),
296302
fields,
@@ -363,7 +369,7 @@ private async Task SendEmbedToDiscord(object embed)
363369
private string GetHostname()
364370
{
365371
string hostname = ConVar.Find("hostname")?.StringValue ?? _translator["NeedInServerMessage"];
366-
if(string.IsNullOrEmpty(hostname) || hostname.Length <= 3)
372+
if (string.IsNullOrEmpty(hostname) || hostname.Length <= 3)
367373
{
368374
hostname = _translator["NeedInServerMessage"];
369375
}
@@ -380,7 +386,24 @@ private string GetCustomDomain()
380386
}
381387
private string GetIP()
382388
{
383-
return Config.IPandPORT;
389+
if (Config.GetIPandPORTautomatic)
390+
{
391+
string? ip = ConVar.Find("ip")?.StringValue;
392+
string? port = ConVar.Find("hostport")?.GetPrimitiveValue<int>().ToString();
393+
394+
if (!string.IsNullOrEmpty(ip) && !string.IsNullOrEmpty(port))
395+
{
396+
return $"{ip}:{port}";
397+
}
398+
else
399+
{
400+
return Config.IPandPORT;
401+
}
402+
}
403+
else
404+
{
405+
return Config.IPandPORT;
406+
}
384407
}
385408
private string MentionRoleID()
386409
{

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ https://github.com/user-attachments/assets/fca8fed1-c07c-4546-9972-dc1cd49ab769
3737
| `EmbedAuthorImage` | It will be the image (logo) that will appear as the author of the embed. | **YES** |
3838
| `EmbedThumbnail` | You can use this option to disable or enable the embed thumbnail. | **YES** |
3939
| `EmbedThumbnailImage` | It will be the image (logo) that will appear as the author of the embed. | **YES** |
40+
| `UseHostname` | If you set this configuration to true, the “EmbedTitle” of the translation will be replaced by the hostname you have configured in your server.cfg file. | **YES** |
41+
| `GetIPandPORTautomatic` | When you activate this option the plugin will try to get the IP:PORT of your server automatically, in case it is not possible use the IPandPORT configuration. | **YES** |
4042

4143
## Configuration example
4244
```
@@ -61,6 +63,8 @@ https://github.com/user-attachments/assets/fca8fed1-c07c-4546-9972-dc1cd49ab769
6163
"EmbedAuthorImage": "https://avatars.githubusercontent.com/u/61034981?v=4",
6264
"EmbedThumbnail": true,
6365
"EmbedThumbnailImage": "https://avatars.githubusercontent.com/u/61034981?v=4",
66+
"UseHostname": true,
67+
"GetIPandPORTautomatic": true,
6468
}
6569
```
6670

0 commit comments

Comments
 (0)