-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConsoleChat.cs
More file actions
94 lines (75 loc) · 3.05 KB
/
ConsoleChat.cs
File metadata and controls
94 lines (75 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Text.RegularExpressions;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;
namespace ConsoleChat
{
public class ConsoleChat : BasePlugin
{
public override string ModuleName => "Console Chat";
public override string ModuleVersion => "1.1";
public override string ModuleAuthor => "Oylsister";
public List<string> BlackList = new List<string> { "recharge", "recast", "cooldown", "cool" };
public override void Load(bool hotReload)
{
AddCommandListener("say", OnSayTest, HookMode.Pre);
}
public HookResult OnSayTest(CBaseEntity? client, CommandInfo info)
{
if (client == null)
{
if (!IsCountable(info.ArgString))
{
Server.PrintToChatAll($" {ChatColors.Red}CONSOLE:{ChatColors.Green} {info.ArgString}");
return HookResult.Handled;
}
else
{
var gameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules!;
var timeleft = gameRules.RoundTime - (Server.CurrentTime - gameRules.RoundStartTime);
var Countdown = GetCountNumber(info.ArgString);
if ((Countdown > 5) && (timeleft > Countdown))
{
int triggerTime = (int)Math.Ceiling(timeleft - Countdown);
if ((int)timeleft - 0.5f == (int)timeleft)
{
triggerTime++;
}
var min = triggerTime / 60;
var secs = triggerTime % 60;
Server.PrintToChatAll($" {ChatColors.Red}CONSOLE:{ChatColors.Green} {info.ArgString} {ChatColors.Orange}[ {min}:{secs:D2} ]");
return HookResult.Handled;
}
}
}
return HookResult.Continue;
}
bool CheckString(string str)
{
foreach (var blackword in BlackList)
{
if (str.Contains(blackword, StringComparison.OrdinalIgnoreCase))
return true;
}
return false;
}
public bool IsCountable(string message)
{
if (CheckString(message))
return false;
string pattern = @"\b(\d+)(\s*)(s|sec|second|seconds)\b";
return Regex.IsMatch(message, pattern, RegexOptions.IgnoreCase);
}
public int GetCountNumber(string message)
{
if (!IsCountable(message))
return 0;
string pattern = @"\b(\d+)(\s*)(s|sec|second|seconds)\b";
var match = Regex.Match(message, pattern, RegexOptions.IgnoreCase);
if (match.Success)
return int.Parse(match.Groups[1].Value);
return 0;
}
}
}