| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
local lua_command_table = { |
| 12 |
[1] = { |
| 13 |
["/w3motd"] = command_w3motd, |
| 14 |
|
| 15 |
|
| 16 |
["/quiz"] = command_quiz, |
| 17 |
|
| 18 |
|
| 19 |
["/ghost"] = command_ghost, |
| 20 |
|
| 21 |
["/host"] = command_host, |
| 22 |
["/chost"] = command_chost, |
| 23 |
["/unhost"] = command_unhost, |
| 24 |
["/ping"] = command_ping, ["/p"] = command_ping, |
| 25 |
["/swap"] = command_swap, |
| 26 |
["/open"] = command_open_close, |
| 27 |
["/close"] = command_open_close, |
| 28 |
["/start"] = command_start_abort_pub_priv, |
| 29 |
["/abort"] = command_start_abort_pub_priv, |
| 30 |
["/pub"] = command_start_abort_pub_priv, |
| 31 |
["/priv"] = command_start_abort_pub_priv, |
| 32 |
["/stats"] = command_stats, |
| 33 |
}, |
| 34 |
[8] = { |
| 35 |
["/redirect"] = command_redirect, |
| 36 |
}, |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
function handle_command(account, text) |
| 43 |
|
| 44 |
for cg,cmdlist in pairs(lua_command_table) do |
| 45 |
for cmd,func in pairs(cmdlist) do |
| 46 |
if string.starts(text, cmd) then |
| 47 |
|
| 48 |
|
| 49 |
if math_and(account_get_auth_command_groups(account.name), cg) == 0 then |
| 50 |
api.message_send_text(account.name, message_type_error, account.name, localize(account.name, "This command is reserved for admins.")) |
| 51 |
return -1 |
| 52 |
end |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
return func(account, text) |
| 58 |
end |
| 59 |
end |
| 60 |
end |
| 61 |
return 1 |
| 62 |
end |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
function handle_command_before(account, text) |
| 70 |
|
| 71 |
for k,username in pairs(config.flood_immunity_users) do |
| 72 |
if (username == account.name) then return 1 end |
| 73 |
end |
| 74 |
|
| 75 |
if (config.ghost) then |
| 76 |
|
| 77 |
for k,username in pairs(config.ghost_bots) do |
| 78 |
if (username == account.name) then return 1 end |
| 79 |
end |
| 80 |
end |
| 81 |
|
| 82 |
return 0 |
| 83 |
end |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
function split_command(text, args_count) |
| 90 |
local count = args_count |
| 91 |
local result = {} |
| 92 |
local tmp = "" |
| 93 |
|
| 94 |
|
| 95 |
if not string:empty(text) then |
| 96 |
text = string.sub(text, 2) |
| 97 |
end |
| 98 |
|
| 99 |
i = 0 |
| 100 |
|
| 101 |
for token in string.split(text) do |
| 102 |
if not string:empty(token) then |
| 103 |
if (i < count) then |
| 104 |
result[i] = token |
| 105 |
i = i + 1 |
| 106 |
else |
| 107 |
if not string:empty(tmp) then |
| 108 |
tmp = tmp .. " " |
| 109 |
end |
| 110 |
tmp = tmp .. token |
| 111 |
end |
| 112 |
end |
| 113 |
end |
| 114 |
|
| 115 |
if not string:empty(tmp) then |
| 116 |
result[count] = tmp |
| 117 |
end |
| 118 |
return result |
| 119 |
end |
| 120 |
|