Skip to content

Commit d69eec4

Browse files
committed
Fixed temp banning
1 parent f00f68c commit d69eec4

File tree

2 files changed

+10
-48
lines changed

2 files changed

+10
-48
lines changed

resources/irc/scripts/irccommands.lua

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,9 @@ addEventHandler("onIRCResourceStart",root,
5656
function (server,channel,user,command,name,...)
5757
if not name then ircNotice(user,"syntax is !ban <name> [reason] (time)") return end
5858
local reason = table.concat({...}," ") or ""
59-
local t = split(reason,40)
60-
local time
61-
if #t > 1 then
62-
time = "("..t[#t]
63-
end
6459
local player = getPlayerFromPartialName(name)
6560
if player then
66-
if time then
67-
addBan(getPlayerIP(player),nil,getPlayerSerial(player),ircGetUserNick(user),reason,toMs(time)/1000)
68-
else
69-
addBan(getPlayerIP(player),nil,getPlayerSerial(player),ircGetUserNick(user),reason)
70-
end
61+
addBan(getPlayerIP(player),nil,getPlayerSerial(player),ircGetUserNick(user),reason,getTimeFromString(reason)/1000)
7162
else
7263
ircNotice(user,"'"..name.."' no such player")
7364
end
@@ -257,50 +248,23 @@ addEventHandler("onIRCResourceStart",root,
257248
function (server,channel,user,command,name,...)
258249
if not name then ircNotice(user,"syntax is !banname <name> (<reason>)") return end
259250
local reason = table.concat({...}," ") or ""
260-
local t = split(reason,40)
261-
local time
262-
if #t > 1 then
263-
time = "("..t[#t]
264-
end
265-
if time then
266-
addBan(nil,name,nil,ircGetUserNick(user),reason,toMs(time)/1000)
267-
else
268-
addBan(nil,name,nil,ircGetUserNick(user),reason)
269-
end
251+
addBan(nil,name,nil,ircGetUserNick(user),reason,getTimeFromString(reason)/1000)
270252
end
271253
)
272254

273255
addIRCCommandHandler("!banserial",
274256
function (server,channel,user,command,serial,...)
275257
if not serial then ircNotice(user,"syntax is !banserial <name> (<reason>)") return end
276258
local reason = table.concat({...}," ") or ""
277-
local t = split(reason,40)
278-
local time
279-
if #t > 1 then
280-
time = "("..t[#t]
281-
end
282-
if time then
283-
addBan(nil,nil,serial,ircGetUserNick(user),reason,toMs(time)/1000)
284-
else
285-
addBan(nil,nil,serial,ircGetUserNick(user),reason)
286-
end
259+
addBan(nil,nil,serial,ircGetUserNick(user),reason,getTimeFromString(reason)/1000)
287260
end
288261
)
289262

290263
addIRCCommandHandler("!banip",
291264
function (server,channel,user,command,ip,...)
292265
if not ip then ircNotice(user,"syntax is !banname <name> (<reason>)") return end
293266
local reason = table.concat({...}," ") or ""
294-
local t = split(reason,40)
295-
local time
296-
if #t > 1 then
297-
time = "("..t[#t]
298-
end
299-
if time then
300-
addBan(ip,nil,nil,ircGetUserNick(user),reason,toMs(time)/1000)
301-
else
302-
addBan(ip,nil,nil,ircGetUserNick(user),reason)
303-
end
267+
addBan(ip,nil,nil,ircGetUserNick(user),reason,getTimeFromString(reason)/1000)
304268
end
305269
)
306270

resources/irc/scripts/mutes.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,13 @@ times["month"] = 2592000000
118118
times["months"] = 2592000000
119119
function getTimeFromString (string)
120120
if type(string) ~= "string" then return false end
121+
string = string.gsub(string,"[%(%)]"," ") -- support for old syntax
122+
121123
local time = 0
122-
for i,v in pairs (times) do
123-
local start,stop = string.find(string,i)
124-
if start then
125-
local number = string.sub(string,start-2,start-1)
126-
if number and tonumber(number) then
127-
number = tonumber(number)
128-
time = time + number*v
129-
end
124+
local words = split(string,32)
125+
for i,word in ipairs (words) do
126+
if times[word] and words[i-1] then
127+
time = time + tonumber(words[i-1])*times[word]
130128
end
131129
end
132130
return time

0 commit comments

Comments
 (0)