SanyaRamzik

tester

May 10th, 2020
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 KB | None | 0 0
  1. --------------------------------------------
  2. --          ТЕСТЕР МОД. СОСТАВА           --
  3. --         edited by SanyaRamzik          --
  4. -- https://pastebin.com/U1eLaRbS  таблица --
  5. --------------------------------------------
  6. -- Основные команды: -start [nickname]    --
  7. --                   -stop                --
  8. --                   -local ; -global     --
  9. --------------------------------------------
  10. local com=require('component')
  11. local bot=com.chat_box
  12. local gpu=com.gpu
  13. local event=require('event')
  14. local W,H=gpu.getResolution()
  15. -- ############# --
  16.  
  17. varName="§8HiTechCraft";
  18. varPrefix="§4Тестер";
  19. local whiteList = {'SanyaRamzik'}
  20. local data=io.open("\\dbTester.txt","a")
  21.  
  22. local exp='test'
  23. local testKey=false
  24. local dbMass={}
  25. local num=1
  26. local trueCount=0
  27. -- ############# --
  28. function txtFind(text, string)
  29.  if text:find(string)~=nil then return true
  30.  else return false end
  31. end
  32.  
  33. function split( str, del )
  34.  
  35.     local t = {}
  36.  
  37.     repeat
  38.       local b, e = str:find( del, 1, true )
  39.  
  40.       if b ~= nil then
  41.          t[ #t + 1 ] = str:sub( 1, b - 1 )
  42.          str = str:sub( e + 1 )
  43.       end
  44.     until b == nil
  45.  
  46.     t[ #t + 1 ] = str
  47.  
  48.     return t
  49. end
  50.  
  51. function SAY(text)
  52.   chatNameString="§8[§4" .. varPrefix .. "§8]" .. varName .. "§f: ";
  53.   bot.say(chatNameString .. text);
  54. end
  55.  
  56. local function conf(stat)
  57. bot.setName(stat .. "§8");
  58. end
  59.  
  60. function TakeQuest()
  61.   for line in io.lines("\\dbTester.txt") do dbMass[#dbMass+1]=line; end
  62. end
  63.  
  64. function test(nick,msg,db)
  65. if nick==exp then
  66.   local answ=split(db[num+1],':')
  67.   local answKey=true
  68.   local answSetter=0
  69.   for i=1,#answ do
  70.     if i~=3 and txtFind(msg,answ[i])==false then answKey=false end
  71.     if i==3 and msg:find("(%d+)[^%d]")~=nil then
  72.       local wh=split(answ[i],' ')
  73.       local min_max=split(wh[1],'-')
  74.       local min=tonumber(min_max[1]); local max=tonumber(min_max[2])
  75.       _,_,n=msg:find("(%d+)[^%d]"); n=tonumber(n)
  76.       if txtFind(msg,'hour') then n=n*60
  77.       elseif txtFind(msg,'day') then n=n*60*24
  78.       elseif txtFind(msg,'week') then n=n*60*24*7
  79.       end
  80.       if txtFind(tostring(wh[2]),'hour') then min=min*60; max=max*60
  81.       elseif txtFind(tostring(wh[2]),'day') then min=min*60*24; max=max*60*24
  82.       elseif txtFind(tostring(wh[2]),'week') then min=min*60*24*7; max=max*60*24*7
  83.       end
  84.       if n<min or n>max then answKey=false end
  85.     end
  86.   end
  87.   if answKey==true then trueCount=trueCount+1; end
  88.   SAY(tostring(answKey)..' --засчитано: '..trueCount..'/'..tostring(math.floor(#dbMass/3)))
  89.   num=num+3
  90. end
  91. end
  92.  
  93. local function botMSG(nick,msg)
  94. local ModKey=false
  95.   for i=1,#whiteList do if nick==whiteList[i] then ModKey=true end end
  96.   if ModKey==true then
  97.     if txtFind(msg,'-start')==true and testKey==false then k=split(msg,' '); exp=k[2]; testKey=true; num=1; SAY('§cTEST STARTED')
  98.     elseif msg=='-stop' and testKey==true then testKey=false; trueCount=0; num=1; SAY('§cTEST STOPED')
  99.     elseif msg=='-local' then conf("§fL")
  100.     elseif msg=='-global' then conf("§6G")
  101.     elseif msg=='-exit' then os.exit() end
  102.   end
  103. end
  104. -- ############## --
  105. conf("§fL"); TakeQuest()
  106. gpu.setBackground(0x000000); gpu.setForeground(0xffffff); gpu.fill(1,1,W,H,' ')
  107. local d=5
  108. gpu.set(W/2-(string.len('-start')/2)+1,d,'-start'); d=d+2
  109. gpu.set(W/2-(string.len('-stop')/2)+1,d,'-stop'); d=d+2
  110. gpu.set(W/2-(string.len('-exit')/2)+1,d,'-exit'); d=d+2
  111. gpu.set(W/2-(string.len('-local')/2)+1,d,'-local'); d=d+2
  112. gpu.set(W/2-(string.len('-global')/2)+1,d,'-global'); d=d+3
  113. gpu.set(10,d,"устное/warn/tempmute/mute/tempban/ban  [num] min/hours/days [пункт]")
  114. gpu.set(10,d+1,"либо  -")
  115. while true do
  116.  if num>#dbMass then testKey=false; SAY('Тест пройден; Stoped') trueCount=0 end
  117.  if testKey==true then os.sleep(2)
  118.    varName='§8Нарушитель' m=split(dbMass[num],'%'); for i=1,#m do SAY(m[i]) end varName='§8HiTechCraft' end
  119.  local _, add, nick, msg = event.pull("chat_message")
  120.   os.sleep(1)
  121.  if testKey==true then test(nick,msg,dbMass) end
  122.  botMSG(nick,msg)
  123. end
Add Comment
Please, Sign In to add comment