Advertisement
markov2019

Untitled

Sep 3rd, 2021 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local computer = require("computer")
  3. local cb = component.chat_box
  4. local event = require("event")
  5. local colors = require("colors")
  6. local terminal = require("term")
  7. local radar = component.radar
  8.  
  9. terminal.clear()
  10. print("ЧатБот варпа P")
  11.  
  12. local botName = " §8warp P: §8"
  13.  
  14. local blackList = {
  15.     "Pipidastro",
  16.     "Alex25764"
  17. }
  18.  
  19. local playersGreeted = {}
  20.  
  21. local state = false
  22.  
  23. function dump(table)
  24.     if type(table) == 'table' then
  25.        local s = '{ '
  26.        for k,v in pairs(table) do
  27.           if type(k) ~= 'number' then k = '"'..k..'"' end
  28.           s = s .. '['..k..'] = ' .. dump(v) .. ','
  29.        end
  30.        return s .. '} '
  31.     else
  32.        return tostring(table)
  33.     end
  34. end
  35.  
  36. local function Ads()
  37.     cb.say(botName .. "➢ §c/warp P - §7магазин предлагает всем заинтересованным лицам разделы под каждую основную модификацию сервера.§7 §7Прекрасное оформление, которое станет настоящей жемчужиной любого игрока!§7")
  38.     cb.say(botName .. "➢ §6[Механизмы]")
  39.     cb.say(botName .. "➢ §bДраконы и пчелы- [DraconicEvolution + §bFORESTRY]§b")
  40.     cb.say(botName .. "➢ §aТехника - [IC2 + AE2 + TE]§a")
  41.     cb.say(botName .. "➢ §cИ многое другое, приходите и запишите нас §cв блокноте!")
  42. end
  43.  
  44. local function checkIsLocalChat(message)
  45.     local firstLetter = string.sub(message, 1, 1)
  46.     return firstLetter ~= "!"
  47. end
  48.  
  49. local function isNumber(str)
  50.     return type(tonumber(str)) == "number"
  51. end
  52.  
  53. local function thanksForUser(message, nick)
  54.     if checkIsLocalChat(message) == true then
  55.         if isNumber(message) == true then
  56.             cb.say(botName .. "§cСпасибо за покупку, " .. nick)
  57.         end
  58.     end
  59. end
  60.  
  61. local function handlerMessage(message, nick)
  62.     print(nick, " написал " .. message)
  63.     thanksForUser(message, nick)
  64. end
  65.  
  66. local function resetArray(array)
  67.     for i = 1, #array do
  68.         array[i] = nil
  69.     end
  70. end
  71.  
  72. local function findElement(array, str)
  73.     local state = false
  74.     for k, v in pairs(array) do
  75.         if v == str then
  76.             state = true
  77.         end
  78.     end
  79.     return state
  80. end
  81.  
  82. cb.setName("§aP")
  83. cb.setDistance(250)
  84.  
  85. for i = 1, #blackList do
  86.     computer.addUser(blackList[i])
  87. end
  88.  
  89. while true do
  90.     local _, _, nick, msg = event.pull(1, "chat_message")
  91.     if msg ~= nil and nick ~= nil then
  92.         handlerMessage(msg, nick)
  93.     end
  94.  
  95.     local players = radar.getPlayers()
  96.  
  97.     for i = 1, #players do
  98.         local current = players[i].name
  99.         if not findElement(blackList, current) then
  100.             if not findElement(playersGreeted, current) then
  101.                 table.insert(playersGreeted, current)
  102.                 print(current, " пришел на варп")
  103.                 cb.say(botName .. "§cДобро пожаловать, " .. current .. ", будем рады видеть тебя вновь!")
  104.             end
  105.         end
  106.     end
  107.  
  108.     local hour = tonumber(os.date('%H'))
  109.  
  110.     if hour % 8 == 0 and state == false then
  111.         resetArray(playersGreeted)
  112.         Ads()
  113.         state = true
  114.     end
  115.     if hour % 8 ~= 0 and state == true then
  116.         state = false
  117.     end
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement