-
Notifications
You must be signed in to change notification settings - Fork 3
/
Chat-Logger-GoldKingZ.cs
138 lines (118 loc) · 5.6 KB
/
Chat-Logger-GoldKingZ.cs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using Chat_Logger_GoldKingZ.Config;
namespace Chat_Logger_GoldKingZ;
public class ChatLoggerGoldKingZ : BasePlugin
{
public override string ModuleName => "Chat Logger (Log Chat To Text Or Discord WebHook)";
public override string ModuleVersion => "1.1.0";
public override string ModuleAuthor => "Gold KingZ";
public override string ModuleDescription => "https://github.com/oqyh";
private readonly PlayerChat _PlayerChat = new();
public override void Load(bool hotReload)
{
Configs.Load(ModuleDirectory);
Configs.Shared.CookiesModule = ModuleDirectory;
AddCommandListener("say", OnPlayerChat, HookMode.Post);
AddCommandListener("say_team", OnPlayerChatTeam, HookMode.Post);
RegisterEventHandler<EventPlayerConnectFull>(OnEventPlayerConnectFull);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);
RegisterListener<Listeners.OnMapEnd>(OnMapEnd);
}
public void OnMapStart(string Map)
{
if(Configs.GetConfigData().Text_AutoDeleteLogsMoreThanXdaysOld > 0)
{
string Fpath = Path.Combine(ModuleDirectory,"../../plugins/Chat-Logger-GoldKingZ/logs");
Helper.DeleteOldFiles(Fpath, "*" + ".txt", TimeSpan.FromDays(Configs.GetConfigData().Text_AutoDeleteLogsMoreThanXdaysOld));
}
}
private HookResult OnPlayerChat(CCSPlayerController? player, CommandInfo info)
{
if (player == null || !player.IsValid)return HookResult.Continue;
_PlayerChat.OnPlayerChat(player, info, false);
return HookResult.Continue;
}
private HookResult OnPlayerChatTeam(CCSPlayerController? player, CommandInfo info)
{
if (player == null || !player.IsValid)return HookResult.Continue;
_PlayerChat.OnPlayerChat(player, info, true);
return HookResult.Continue;
}
public HookResult OnEventPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
{
if (@event == null)return HookResult.Continue;
var player = @event.Userid;
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return HookResult.Continue;
var playerid = player.SteamID;
if (!string.IsNullOrEmpty(Configs.GetConfigData().Text_IncludeFlagsMessagesOnly) && Helper.IsPlayerInGroupPermission(player, Configs.GetConfigData().Text_IncludeFlagsMessagesOnly))
{
if (!Globals.TextIncude.ContainsKey(playerid))
{
Globals.TextIncude.Add(playerid, true);
}
if (Globals.TextIncude.ContainsKey(playerid))
{
Globals.TextIncude[playerid] = true;
}
}
if (!string.IsNullOrEmpty(Configs.GetConfigData().Text_ExcludeFlagsMessages) && Helper.IsPlayerInGroupPermission(player, Configs.GetConfigData().Text_ExcludeFlagsMessages))
{
if (!Globals.TextExclude.ContainsKey(playerid))
{
Globals.TextExclude.Add(playerid, true);
}
if (Globals.TextExclude.ContainsKey(playerid))
{
Globals.TextExclude[playerid] = true;
}
}
if (!string.IsNullOrEmpty(Configs.GetConfigData().Discord_IncludeFlagsMessagesOnly) && Helper.IsPlayerInGroupPermission(player, Configs.GetConfigData().Discord_IncludeFlagsMessagesOnly))
{
if (!Globals.DiscordIncude.ContainsKey(playerid))
{
Globals.DiscordIncude.Add(playerid, true);
}
if (Globals.DiscordIncude.ContainsKey(playerid))
{
Globals.DiscordIncude[playerid] = true;
}
}
if (!string.IsNullOrEmpty(Configs.GetConfigData().Discord_ExcludeFlagsMessages) && Helper.IsPlayerInGroupPermission(player, Configs.GetConfigData().Discord_ExcludeFlagsMessages))
{
if (!Globals.DiscordExclude.ContainsKey(playerid))
{
Globals.DiscordExclude.Add(playerid, true);
}
if (Globals.DiscordExclude.ContainsKey(playerid))
{
Globals.DiscordExclude[playerid] = true;
}
}
return HookResult.Continue;
}
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
{
if (@event == null) return HookResult.Continue;
var player = @event.Userid;
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return HookResult.Continue;
var playerid = player.SteamID;
if (Globals.Client_Text1.ContainsKey(playerid)) Globals.Client_Text1.Remove(playerid);
if (Globals.Client_Text2.ContainsKey(playerid)) Globals.Client_Text2.Remove(playerid);
if (Globals.TextIncude.ContainsKey(playerid)) Globals.TextIncude.Remove(playerid);
if (Globals.TextExclude.ContainsKey(playerid)) Globals.TextExclude.Remove(playerid);
if (Globals.DiscordIncude.ContainsKey(playerid)) Globals.DiscordIncude.Remove(playerid);
if (Globals.DiscordExclude.ContainsKey(playerid)) Globals.DiscordExclude.Remove(playerid);
if (Globals.TeamChat.ContainsKey(playerid)) Globals.TeamChat.Remove(playerid);
return HookResult.Continue;
}
public void OnMapEnd()
{
Helper.ClearVariables();
}
public override void Unload(bool hotReload)
{
Helper.ClearVariables();
}
}