Advertisement
Guest User

bot

a guest
Dec 6th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.49 KB | None | 0 0
  1. local component=require("component");
  2. local bot=component.chat_box;
  3. local event =require("event");
  4. local dbName=io.open("\\dbName.txt","a");
  5. local dbPrefix=io.open("\\dbPrefix.txt","a");
  6. local dbAnswer=io.open("\\dbAnswer.txt","a");
  7. local varChoise="";
  8. print("#########Управление#########");
  9. print("имя  - изменить ник")
  10. print("префикс  - изменить префикс")
  11. print("локальный/глобальный  - изменить чат")
  12. print("добавить имя/префикс")
  13. print("выбор имя/префикс")
  14. print("");
  15. varConfChat="§6G"
  16. varName="§dВалерия";
  17. varPrefix="§bМ§4а§5л§1ы§2ш§3к§aа";
  18.  
  19. function conf(varConfChat)
  20. bot.setName(varConfChat .. "§8");
  21. end
  22.  
  23. function LineCount(file)
  24.    local ctr = 0;
  25.    for _ in io.lines(file) do
  26.      ctr = ctr + 1
  27.    end
  28.    return ctr;
  29. end
  30.  
  31. function split( str, del )
  32.  
  33.     local t = {}
  34.  
  35.     repeat
  36.       local b, e = str:find( del, 1, true )
  37.  
  38.       if b ~= nil then
  39.          t[ #t + 1 ] = str:sub( 1, b - 1 )
  40.          str = str:sub( e + 1 )
  41.       end
  42.     until b == nil
  43.  
  44.     t[ #t + 1 ] = str
  45.  
  46.     return t
  47. end
  48.  
  49. function dbAdd(var)
  50.  if var=="добавить имя" then
  51.   add=io.read();
  52.   dbName:write(add.."\n");
  53.   varName=add;
  54.   dbName:flush();
  55.  end
  56.  if var=="добавить префикс" then
  57.   add=io.read();
  58.   dbPrefix:write(add.."\n");
  59.   varPrefix=add;
  60.   dbPrefix:flush();
  61.  end
  62. end
  63.  
  64. function SAY(text)
  65. bot.say(chatNameString .. text);
  66. end
  67.  
  68. function dbChoise(var)
  69.  if var=="выбор имя" then
  70.   print("##########");
  71.   local t={};
  72.   for line in io.lines("\\dbName.txt") do
  73.    t[#t+1]=line;
  74.   end
  75.   for i=1,#t do
  76.    print(t[i]);
  77.   end
  78.   print("##########")
  79.   varChoise=io.read();
  80.   varName=t[tonumber(varChoise)];
  81.  end
  82.  
  83.  if var=="выбор префикс" then
  84.   print("##########");
  85.    local t={};
  86.    for line in io.lines("\\dbPrefix.txt") do
  87.     t[#t+1]=line;
  88.    end
  89.    for i=1,#t do
  90.     print(t[i]);
  91.    end
  92.    print("##########")
  93.    varChoise=io.read();
  94.    varPrefix=t[tonumber(varChoise)];
  95.  end
  96. end
  97.  
  98. function txtFind(text, string)
  99.  if text:find(string)~=nil then return true
  100.  else return false
  101.  end
  102. end
  103.  
  104. function AnswerControl(msg)
  105.  Mas={ };
  106.  stringMas={ };
  107.  acc=0;
  108.  for line in io.lines("\\dbAnswer.txt") do
  109.     Mas[#Mas+1]=line;
  110.  end
  111.  for i=1,#Mas,3 do
  112.   local string = Mas[i];
  113.   local stringMas = split(string,"$");
  114.   local acc=0;
  115.  for b=1,#stringMas,1 do
  116.   if txtFind(msg,stringMas[b]) then
  117.     acc=acc+1;
  118.   end
  119.  end
  120.   if acc==#stringMas then
  121.    SAY(Mas[i+1]);
  122.    break;
  123.   end
  124.  end
  125. end
  126.  
  127. function botMSG(nick, msg)
  128. if txtFind(msg, "риве") then
  129.   SAY("§9привет сладкий :3");
  130. end
  131. if msg=="настроить" and (nick=="SanyaRamzik")then
  132.  var=io.read();
  133.  tKey(var);
  134. end
  135. AnswerControl(msg);
  136. end
  137.  
  138. function tKey(var)
  139.  if var=="имя" then
  140.    name=io.read();
  141.    varName=name;
  142.   elseif var=="префикс" then
  143.    prefix=io.read();
  144.    varPrefix=prefix;
  145.   elseif var=="добавить имя" then
  146.    dbAdd(var);
  147.   elseif var=="добавить префикс" then
  148.    dbAdd(var);
  149.   elseif var=="выбор префикс" then
  150.    dbChoise(var);
  151.   elseif var=="выбор имя" then
  152.    dbChoise(var);
  153.   elseif var=="выход" then
  154.    os.exit(0);
  155.   elseif var=="глобальный" then
  156.     varConfChat="§6G";
  157.     conf(varConfChat);
  158.   elseif var=="локальный" then
  159.     varConfChat="§fL";
  160.     conf(varConfChat);
  161.  end
  162. end
  163.  
  164. while true do
  165.  
  166. chatNameString="§8[§4" .. varPrefix .. "§8]" .. varName .. "§f: ";
  167.  local _, add, nick, msg = event.pull("chat_message")
  168.  botMSG(nick, msg);
  169. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement