· 6 years ago · Dec 10, 2019, 09:30 PM
1timeBetweenMessages = 1000 --time to wait between chat messages
2playerTickTable = { } --create a table with tick counts of the most recent chat message
3
4globalchat = true
5
6function globalchatstate(source)
7 if getElementData(source, "owner") == true then
8 if globalchat == true then
9 globalchat = false
10 outputChatBox( "Owner has deactivated the Global Chat!", getRootElement(), 255, 0, 0)
11 elseif globalchat == false then
12 globalchat = true
13 outputChatBox("Owner has activated the Global Chat!", getRootElement(), 255, 0, 0)
14 end
15 end
16end
17addCommandHandler("globalstate", globalchatstate)
18
19
20
21--The message output
22function playeGlobalChat ( source, cmd, ... )
23if globalchat == true then
24 if cmd == "globalchat" then
25
26 pcount = getElementsByType('player')
27--swear filter
28settings = {
29['swearFilter'] = {
30 ['enabled'] = false,
31 ['swearCost'] = 0,
32 ['swears'] = { -- Allows you to set the blocked swear words, syntax is ['WORD'] = 'REPLACEMENT'
33 ['shit'] = '***',
34 ['asshole'] = '***',
35 ['fuck'] = '***',
36 ['slut'] = '***',
37 ['bitch'] = '***',
38 ['cunt'] = '***',
39 ['whore'] = '***',
40 ['pussy'] = '***',
41 ['fag'] = '***',
42 ['perro'] = '***',
43 ['puta'] = '***',
44 ['joder'] = '***',
45 ['fuk'] = '***',
46 ['dick'] = '***',
47 ['gay'] = '***',
48 ['nigger'] = '***',
49 ['nigga'] = '***',
50 ['niggur'] = '***'
51 }
52}
53}
54
55 local msg = table.concat ( {...} , " " ) --concat the arguments from table to a string seperated by spaces
56 local msg = string.gsub ( msg, '#%x%x%x%x%x%x', '' ) --remove color-codes
57 local msg1 = string.gsub ( msg, '#%x%x%x%x%x%x', '' ) --remove color-codes
58 local isswear=false
59
60 if string.find ( msg, "%d"..".".."%d"..".".."%d"..".".."%d"..":".."%d" ) and getElementData(source,'owner') ~= true then --disallow links
61 local chatterName = getPlayerName ( source )
62 outputChatBox ( getPlayerName(source)..":#FFFFFF I just tried to spam a server ip so im a dick bag for life damn... :/ pls ban me.", root, 255, 255, 0,true)
63 outputChatBox ( getPlayerName(source)..":#FFFFFF I just tried to spam a server ip so im a dick bag for life damn... :/ pls ban me.", root, 255, 255, 0,true)
64 return
65 end
66
67 --Check whether the player is muted first
68 if isPlayerMuted ( source ) then
69 outputChatBox ("You are muted!", source, 255, 128, 22, true)
70 return
71 end
72
73
74 --exports.chatlogs:outputLogChat("GLOBAL : "..getPlayerName(source)..":"..msg)
75 if isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ( "Owner" ) ) then
76 outputChatBox ( "#922B21[#13FF00OWNER#922B21] - #922B21"..getPlayerName(source).." : #FFFFFF"..msg, getRootElement(), 255, 255, 255, true)
77 --exports.chatlogs:outputLogChat("GLOBAL : "..getPlayerName(source)..":"..msg)
78 elseif isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ("Admin" ) ) then
79 outputChatBox ("#922B21[#04ABFFADMIN#922B21] - #922B21"..getPlayerName(source).." : #FFFFFF"..msg, getRootElement(), 255, 255, 255, true)
80 --exports.chatlogs:outputLogChat("GLOBAL : "..getPlayerName(source)..":"..msg)
81 elseif isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ( "SuperModerator" ) ) then
82 outputChatBox ( "#922B21[#b0ff00SUPERMODERATOR#922B21] - #787878"..getPlayerName(source).." : #FFFFFF "..msg, getRootElement(), 255, 255, 255, true)
83 --exports.chatlogs:outputLogChat("GLOBAL : "..getPlayerName(source)..":"..msg)
84 elseif isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ( "Moderator" ) ) then
85 outputChatBox ( "#922B21[#00ff04MODERATOR#922B21] - #922B21"..getPlayerName(source).." : #FFFFFF "..msg, getRootElement(), 255, 255, 255, true)
86 --exports.chatlogs:outputLogChat("GLOBAL : "..getPlayerName(source)..":"..msg)
87 elseif isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ( "Supporter" ) ) then
88 outputChatBox ( "#922B21[#F1E700SUPPORTER#922B21] - #922B21"..getPlayerName(source).." : #FFFFFF "..msg, getRootElement(), 255, 255, 255, true)
89 --exports.chatlogs:outputLogChat("GLOBAL : "..getPlayerName(source)..":"..msg)
90 else
91
92
93
94 if settings['swearFilter']['enabled'] then
95 for i, v in pairs(settings['swearFilter']['swears']) do
96 while msg:lower():find(i:lower(),1,true) do
97 isswear=true
98 local start, end_ = msg:lower():find(i:lower(),1,true)
99 local found = msg:sub(start,end_)
100 msg = msg:gsub(found,v)
101 end
102 end
103 end
104
105
106
107
108
109
110 if string.find ( msg, "mtasa://" ) then --disallow links
111 local chatterName = getPlayerName ( source )
112 outputChatBox ( getPlayerName(source)..":#FFFFFF I just tried to spam a server ip so im a dick bag for life damn... :/ pls ban me.", root, 255, 255, 0,true)
113 outputChatBox ( getPlayerName(source)..":#FFFFFF I just tried to spam a server ip so im a dick bag for life damn... :/ pls ban me.", root, 255, 255, 0,true)
114 return
115 end
116
117 --[[ if string.find ( msg, "%d"..".".."%d"..".".."%d"..".".."%d"..":".."%d" ) then --disallow links
118 local chatterName = getPlayerName ( source )
119 outputChatBox ( getPlayerName(source)..":#FFFFFF I just tried to spam a server ip so im a dick bag for life damn... :/ pls ban me.", root, 255, 255, 0,true)
120 outputChatBox ( getPlayerName(source)..":#FFFFFF I just tried to spam a server ip so im a dick bag for life damn... :/ pls ban me.", root, 255, 255, 0,true)
121 return
122 end]]
123
124
125
126 local var, spacesCount = string.gsub( msg, " ", "") --get the count of spaces
127 if ( #msg / spacesCount ) > 20 and #msg > 20 then --check if there is at least one space per 20 or less characters
128 outputChatBox ( "Do not spam the chat with long words!", source, 255, 0, 0 )
129 return
130 end
131
132 if playerTickTable[source] then --check if a table entry for the player exists
133 local tick = getTickCount ( ) --get the current tick count in ms
134 local timePassed = tick - playerTickTable[source] --calculate the time that passed between two messages
135 if timePassed <= timeBetweenMessages then
136 outputChatBox ( "Please refrain from chat spam!", source, 255, 0, 0 )
137 return
138 end
139 else
140 playerTickTable[source] = getTickCount ( )
141 end
142 --End of anti-spam checks
143
144 outputChatBox ("#922B21[#922B21GLOBAL#922B21] - #922B21"..getPlayerName(source).."#d0d0d0 : "..string.gsub(msg, '#%x%x%x%x%x%x', ''), getRootElement(), 255, 255, 255, true)
145
146
147
148
149 if settings['swearFilter']['enabled'] then
150 if isswear then
151 for i, v in ipairs(getAdmins()) do
152 outputChatBox("#00ff00[Unfiltered Chat] #00ffff"..getPlayerName(source).." : #ffffff"..msg1, v, 0,0,0, true)
153 end
154 end
155 end
156 --Anti-spam checks
157 local onlyLettersMsg = string.gsub ( msg , "%A", "" ) --extract letters only
158 if onlyLettersMsg == string.upper ( onlyLettersMsg ) and #onlyLettersMsg > 6 then --check if there are more than 6 uppercase letters without any lowercase letters
159 outputChatBox ( "Turn off your capslock!", source, 255, 0, 0 )
160 return
161 end
162 end
163 --exports.chatlogs:outputLogChat("GLOBAL : "..getPlayerName(source)..":"..msg)
164 exports.discord:send("chat.message.text", { author = getPlayerName(source), text = msg })
165 playerTickTable[source] = getTickCount ( )
166 end
167 else
168 outputChatBox ( "GlobalChat is disabled", source, 255, 0, 0 )
169end
170end
171addCommandHandler ( "globalchat", playeGlobalChat )
172
173function getAdmins()
174 local staffs = {}
175 for k,v in ipairs(getElementsByType("player")) do
176 local acc = getAccountName(getPlayerAccount(v))
177 if ( isObjectInACLGroup( "user."..acc, aclGetGroup("Owner")) or isObjectInACLGroup( "user."..acc, aclGetGroup("Administrator")) or isObjectInACLGroup( "user."..acc, aclGetGroup("SuperModerator")) or isObjectInACLGroup( "user."..acc, aclGetGroup("Moderator")) or isObjectInACLGroup( "user."..acc, aclGetGroup("Supporter")) ) then
178 table.insert(staffs, v)
179 end
180 end
181 return staffs
182end
183
184addEventHandler ( "onPlayerQuit", root,
185 function ( )
186 playerTickTable[source] = nil --remove a leaving player from our cached table
187 end
188)