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