1local banDays = 7
2
3function onSay(player, words, param)
4 if player:getGroup():getId() < 3 then
5 return false
6 end
7
8 local name = param
9 local reason = ''
10
11 local separatorPos = param:find(',')
12 if separatorPos then
13 name = param:sub(0, separatorPos - 1)
14 reason = string.trim(param:sub(separatorPos + 1))
15 end
16
17 local accountId = getAccountNumberByPlayerName(name)
18 if accountId == 0 then
19 return false
20 end
21
22 local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId)
23 if resultId ~= false then
24 result.free(resultId)
25 return false
26 end
27
28 local timeNow = os.time()
29 db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" ..
30 accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. timeNow + (banDays * 86400) .. ", " .. player:getGuid() .. ")")
31
32 local target = Player(name)
33 if target then
34 player:sendTextMessage(MESSAGE_EVENT_ADVANCE, target:getName() .. " has been banned.")
35 target:remove()
36 else
37 player:sendTextMessage(MESSAGE_EVENT_ADVANCE, name .. " has been banned.")
38 end
39end
40