require("ts3defs") require("ts3errors") local helpPre = "\n" local function countHelpSubs(cmdName) local ret = 0 for k,v in pairs(helpCmds) do --print(k,v) if(v.parent ~= nil and string.lower(v.parent) == string.lower(cmdName)) then ret = ret+1 end end return ret end local function searchHelpCmds(cmdName, parent) local ret = nil for k,v in pairs(helpCmds) do if(parent == nil) then if(string.lower(v.cmd) == string.lower(cmdName)) then ret = k end else if(v.parent ~= nil and string.lower(v.parent) == string.lower(parent) and string.lower(v.cmd) == string.lower(cmdName)) then ret = k end end end return ret end local function getHelpCatCmd(cat, cmd, admin) local ret = nil for k,v in pairs(helpCmds) do if(v.parent ~= nil and string.lower(v.parent) == string.lower(cat)) then if(string.lower(cmd) == string.lower(v.cmd)) then if(v.admin == true and admin == true) then ret = k elseif(v.admin == false) then ret = k end end end end return ret end local function getHelpCmds(cat,admin) local ret = {} for k,v in pairs(helpCmds) do if(v.parent ~= nil and string.lower(v.parent) == string.lower(cat)) then if(v.admin == true and admin == true) then table.insert(ret, v.cmd) elseif(v.admin == false) then table.insert(ret, v.cmd) end end end return ret end local function showHelpCmds(admin) local ret = {} for k,v in pairs(helpCmds) do if(v.parent == nil) then if(v.admin == true and admin == true) then table.insert(ret, v.cmd) elseif(v.admin == false) then table.insert(ret, v.cmd) end end end return ret end local function helpFunc(SCHI, fromID, ffIgnored, args) -- Help for functions local qtArgs, qte, em = quoteArgs(args) local isAdmin = searchUserPerm(getUIDbyID(SCHI, fromID), "a") if(qte == 0) then if(#qtArgs == 0) then -- No Arguments local retTbl = showHelpCmds(isAdmin) local chatArr = chatList(retTbl, 6) local sendChat = helpPre.."Чтоб не забыть" for k,v in pairs(chatArr) do local msg = table.concat(v, ", ") end sendChat = "[color=purple][b]\nКоманды:[/b][/color][color=black][b]\n[color=blue].channel[/color] - Как создать канал\n[color=blue].staff[/color] - Персонал сервера\n\n[color=blue].version[/color] - Версия бота[/b][/color]" sendChatMsg(SCHI, sendChat, fromID, "channel", "blue") elseif(#qtArgs >= 1) then -- One Argument local srchHelp = searchHelpCmds(qtArgs[1]) if(srchHelp ~= nil) then --print("ADMIN", helpCmds[srchHelp].admin) if(helpCmds[srchHelp].admin == true and isAdmin == true or helpCmds[srchHelp].admin == false) then local cntSubs = countHelpSubs(helpCmds[srchHelp].cmd) if(cntSubs == 0) then if(#qtArgs == 1) then local sendChat = helpPre.."" ..helpCmds[srchHelp].name..""..helpCmds[srchHelp].short.."\n".. helpCmds[srchHelp].usage..""..helpCmds[srchHelp].example..""..helpCmds[srchHelp].info .."" sendChatMsg(SCHI, sendChat, fromID, "private", "dark") else sendChatMsg(SCHI, helpPre.."The command [b]"..helpCmds[srchHelp].name.."[/b] has no sub-commands.", fromID, "private", "red") end else if(#qtArgs == 1) then local retTbl = getHelpCmds(qtArgs[1], isAdmin) local chatArr = chatList(retTbl, 6) local sendChat = helpPre.."[color=purple][b]Команда: " ..helpCmds[srchHelp].name.."[/b][/color] "..helpCmds[srchHelp].short.."\n".. helpCmds[srchHelp].usage.."\n "..helpCmds[srchHelp].example.."\n\n "..helpCmds[srchHelp].info .."\n\n[color=red]Sub-Commands:\n[b]" for k,v in pairs(chatArr) do local msg = table.concat(v, ", ") sendChat = sendChat..msg end sendChat = sendChat.."[/b][/color]" sendChatMsg(SCHI, sendChat, fromID, "private", "dark") elseif(#qtArgs == 2) then -- Check second command --print("HELLO", helpCmds[srchHelp].cmd) local srchH = searchHelpCmds(qtArgs[2], helpCmds[srchHelp].cmd) if(srchH ~= nil) then print(helpCmds[srchH].parent, helpCmds[srchHelp].cmd) if(helpCmds[srchH].parent == helpCmds[srchHelp].cmd) then local cntS = countHelpSubs(helpCmds[srchH].cmd) if(cntS == 0) then local sendChat = helpPre.."[color=purple]Команада: [b]"..helpCmds[srchH].name.."[/b][/color]"..helpCmds[srchH].short.."\n".. helpCmds[srchH].usage.."\n"..helpCmds[srchH].example.."\n\n "..helpCmds[srchH].info .."" sendChatMsg(SCHI, sendChat, fromID, "private", "dark") else local retTbl = getHelpCmds(qtArgs[2], isAdmin) local chatArr = chatList(retTbl, 6) local sendChat = helpPre.."[color=purple]Команада: [b]"..helpCmds[srchH].name.."[/b][/color]"..helpCmds[srchH].short.."\n".. helpCmds[srchH].usage.."\n"..helpCmds[srchH].example.."\n\n "..helpCmds[srchH].info .."\n\n[color=red]Sub-Commands:\n[b]" for k,v in pairs(chatArr) do local msg = table.concat(v, ", ") sendChat = sendChat..msg end sendChat = sendChat.."[/b][/color]" sendChatMsg(SCHI, sendChat, fromID, "private", "dark") end else --print("1") sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] Category [b]"..helpCmds[srchHelp].name.."[/b] has no sub-command matching: [b]"..qtArgs[2].."[/b].", fromID, "private", "red") end else --print("2") sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] Category [b]"..helpCmds[srchHelp].name.."[/b] has no sub-command matching: [b]"..qtArgs[2].."[/b].", fromID, "private", "red") end elseif(#qtArgs == 3) then -- Check second command local srchH = searchHelpCmds(qtArgs[2]) if(srchH ~= nil) then if(helpCmds[srchH].parent == helpCmds[srchHelp].cmd) then local cntS = countHelpSubs(helpCmds[srchH].cmd) if(cntS == 0) then sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] Command [b]"..helpCmds[srchH].name.."[/b] has no sub-commands.", fromID, "private", "red") else -- Check third command local srH = searchHelpCmds(qtArgs[3]) if(srH ~= nil) then if(helpCmds[srH].parent == helpCmds[srchH].cmd) then local cnS = countHelpSubs(helpCmds[srH].cmd) if(cnS == 0) then local sendChat = helpPre.."[color=purple]Команада: [b]"..helpCmds[srH].name.."[/b][/color] [color=black] [b]"..helpCmds[srH].short.."[/b][/color]\n[color=green] [b]".. helpCmds[srH].usage.."[/b][/color]\n[color=black] [b]"..helpCmds[srH].example.."[/b][/color]\n\n [b]"..helpCmds[srH].info .."[/b]" sendChatMsg(SCHI, sendChat, fromID, "private", "blue") else local retTbl = getHelpCmds(qtArgs[3], isAdmin) local chatArr = chatList(retTbl, 6) local sendChat = helpPre.."[color=purple]Команада: [b]"..helpCmds[srH].name.."[/b][/color] [color=black] [b]"..helpCmds[srH].short.."[/b][/color]\n[color=green] [b]".. helpCmds[srH].usage.."[/b][/color]\n[color=black] [b]"..helpCmds[srH].example.."[/b][/color]\n\n [b]"..helpCmds[srH].info .."[/b]\n\n[color=red]Sub-Commands:\n[b]" for k,v in pairs(chatArr) do local msg = table.concat(v, ", ") sendChat = sendChat..msg end sendChat = sendChat.."[/b][/color]" sendChatMsg(SCHI, sendChat, fromID, "private", "blue") end else sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] Category [b]"..helpCmds[srchH].name.."[/b] has no sub-command matching: [b]"..qtArgs[2].."[/b].", fromID, "private", "red") end else sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] Category [b]"..helpCmds[srchH].name.."[/b] has no sub-command matching: [b]"..qtArgs[2].."[/b].", fromID, "private", "red") end end else sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] Category [b]"..helpCmds[srchHelp].name.."[/b] has no sub-command matching: [b]"..qtArgs[2].."[/b].", fromID, "private", "red") end else sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] Category [b]"..helpCmds[srchHelp].name.."[/b] has no sub-command matching: [b]"..qtArgs[2].."[/b].", fromID, "private", "red") end end end elseif(helpCmds[srchHelp].admin == true and isAdmin == false) then sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] Команда доступна только [b]персоналу сервера[/b].", fromID, "private", "red") end else sendChatMsg(SCHI, helpPre.."[b][Неправильная команда][/b] Используйте [b].help[/b] для получения списка команд.", fromID, "private", "red") end end else sendChatMsg(SCHI, helpPre.."[b]Ошибка![/b] "..em, fromID, "private", "red") end end addHelpCommand("help", "Help", "Lists all commands.", "help", ".help *command* *sub-command* *sub-sub-command*", ".help admin", "?") -- AFK System local afk = {} insertArray(afk, "modules/support/afk.txt") local function checkUserAFK(UID) local rv = nil for k,v in pairs(afk) do if(v[1] == UID) then rv = k end end return rv end local function updateAFKUser(UID) for k,v in pairs(afk) do if(v[1] == UID) then v[2] = os.time() updateText("modules/support/afk.txt", afk) end end end local function formatAFKType(afktype) afktype = tonumber(afktype) if(afktype == 1) then return "moved" else return "kicked" end end local function checkAFK(SCHI) local clients = getClients(SCHI) local add = 0 local botID = ts3.getClientID(SCHI) local botChan = getUserChanID(SCHI, botID) local rem = 0 local remTbl = {} for k,v in pairs(clients)do local myUID = getUIDbyID(SCHI, v) local chkAfk = checkUserAFK(myUID) local myChan = getUserChanID(SCHI, v) if(myChan == botChan) then if(chkAfk == nil and v ~= botID and searchUserPerm(myUID, "afk", "i") == false) then table.insert(afk, {myUID, os.time()}) add = add+1 end else if(chkAfk ~= nil) then table.remove(afk, chkAfk) add = add+1 end end end local movedUN = {} local afkUsers = {} for k,v in pairs(afk) do local chkCl = checkClient(SCHI, v[1]) --print("CHK CL", chkCl, v[1]) if(chkCl ~= nil) then local diff = os.difftime(os.time(), v[2]) --print("DIFF", diff, v[2], os.time(), (tonumber() * 60)) if(diff >= (tonumber(prefs["AFK"]["afkTimeout"]) * 60)) then local myID = getIDbyUID(SCHI, v[1]) local myUN = getUsernameByID(SCHI, myID) if(prefs["AFK"]["afkType"] == "1") then if(prefs["AFK"]["afkChan"] ~= "nil") then -- Check Channel local chkChan = checkChannel(SCHI, tonumber(prefs["AFK"]["afkChan"])) if(chkChan == true) then if(searchUserPerm(getUIDbyID(SCHI, myID), "afk", "i") == false) then table.insert(movedUN, myUN) ts3.requestClientMove(SCHI, myID, prefs["AFK"]["afkChan"], "") sendChatMsg(SCHI, "[color=red][b][AFK][/b][/color] You were moved to [color=red][b]"..getChanNameByID(SCHI, tonumber(prefs["AFK"]["afkChan"])).."[/b][/color] for being AFK.", myID, "private", "red") end end end else ts3.requestClientKickFromServer(SCHI, myID, "You exceeded the AFK limit and were kicked.") end if(searchUserPerm(getUIDbyID(SCHI, myID), "i") == false) then table.insert(afkUsers, k) end end else --print("HELLO REMOVE") table.insert(remTbl, k) rem = rem+1 end end --print("WHUT") for k,v in pairs(remTbl) do table.remove(afk, v) end for k,v in pairs(afkUsers) do table.remove(afk, v) end if(#movedUN > 0) then local sendMsg = "" if(prefs["AFK"]["afkType"] == "1") then sendMsg = "[color=red][b][AFK][/b][/color] [color=green][b]"..table.concat(movedUN, ", ").."[/b][/color] "..getPluralVerb(#movedUN, "past").." moved to [color=red][b]"..getChanNameByID(SCHI, tonumber(prefs["AFK"]["afkChan"])).."[/b][/color] for being AFK." else sendMsg = "[color=red][b][AFK][/b][/color] [color=green][b]"..table.concat(movedUN, ", ").."[/b][/color] "..getPluralVerb(#movedUN, "past").." kicked from the server for being AFK." end sendChatMsg(SCHI, sendMsg, botID, "channel", "blue") end if(add > 0 or #afkUsers > 0 or rem > 0) then updateText("modules/support/afk.txt", afk) end end local function afkSpeechHandler(SCHI, status, isWhisper, clID) if(status == 1) then updateAFKUser(getUIDbyID(SCHI, clID)) checkAFK(SCHI) end end local function afkMoveHandler(SCHI, clID, oldChID, newChID, visibility, moveMessage) --print("=== AFK MOVE",SCHI, clID, oldChID, newChID, visibility, moveMessage) local botID = ts3.getClientID(SCHI) --print("GETTING BOTS CHAN") local botChan = getUserChanID(SCHI, botID) local clUID = getUIDbyID(SCHI, clID) local chkAFK = checkUserAFK(clUID) --print("BOTCHAN====", botChan) --print("OLD CHANNEL", oldChID, "NEW CHAN", newChID, "BOT CHAN", botChan) if(oldChID == 0 and newChID == botChan) then --print("AFK JOINER") if(chkAFK == nil) then print("ADDING", clUID) table.insert(afk, {clUID, os.time()}) updateText("modules/support/afk.txt", afk) else updateAFKUser(clUID) end elseif(newChID == 0) then --print("AFK LEAVER") if(clUID == "" and chkAFK ~= nil) then table.remove(afk, chkAFK) updateText("modules/support/afk.txt", afk) end elseif(oldChID == afkChan) then --print("BACK FROM GOING AFK") if(chkAFK ~= nil) then --print("BACK", clUID) updateAFKUser(clUID) end elseif(oldChID == botChan) then -- Remove from list. print("MOVING MOVING MOVING", botChan, oldChID, chkAFK) if(chkAFK ~= nil) then --print("REMOVING", clUID) table.remove(afk, chkAFK) updateText("modules/support/afk.txt", afk) end elseif(newChID == botChan) then -- Add to list. if(chkAFK == nil) then --print("ADDING", clUID) table.insert(afk, {clUID, os.time(), (tonumber(prefs["AFK"]["afkTimeout"]) * 60)}) updateText("modules/support/afk.txt", afk) end end end local function afkConnectHandler(SCHI, status, errorNumber) if(status == 4) then checkAFK(SCHI) elseif(status == 0) then afk = {} updateText("modules/support/afk.txt", afk) end end connectHandlers[function(serverConnectionHandlerID, status, errorNumber) afkConnectHandler(serverConnectionHandlerID, status, errorNumber) end] = "afkConnectHandler" speechHandlers[function(serverConnectionHandlerID, status, isReceivedWhisper, clientID) afkSpeechHandler(serverConnectionHandlerID, status, isReceivedWhisper, clientID) end] = "afkSpeechHandler" moveHandlers[function(serverConnectionHandlerID, clientID, oldChannelID, newChannelID, visibility, moveMessage) afkMoveHandler(serverConnectionHandlerID, clientID, oldChannelID, newChannelID, visibility, moveMessage) end] = "afkMoveHandler" addHelpCommand("version", "", "[b]HelpBot v1.0[/b]", "version", "", "", "") commandList[function(serverConnectionHandlerID, fromID, ffIgnored, args, targetMode) helpFunc(serverConnectionHandlerID, fromID, ffIgnored, args, targetMode) end] = "help" commandList[function(serverConnectionHandlerID, fromID, ffIgnored, args, targetMode) helpFunc(serverConnectionHandlerID, fromID, ffIgnored, args, targetMode) end] = "?"