Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component=require("component");
- local bot=component.chat_box;
- local event =require("event");
- local dbName=io.open("\\dbName.txt","a");
- local dbPrefix=io.open("\\dbPrefix.txt","a");
- local dbAnswer=io.open("\\dbAnswer.txt","a");
- local varChoise="";
- print("#########Управление#########");
- print("имя - изменить ник")
- print("префикс - изменить префикс")
- print("локальный/глобальный - изменить чат")
- print("добавить имя/префикс")
- print("выбор имя/префикс")
- print("");
- varConfChat="§6G"
- varName="§dВалерия";
- varPrefix="§bМ§4а§5л§1ы§2ш§3к§aа";
- function conf(varConfChat)
- bot.setName(varConfChat .. "§8");
- end
- function LineCount(file)
- local ctr = 0;
- for _ in io.lines(file) do
- ctr = ctr + 1
- end
- return ctr;
- end
- function split( str, del )
- local t = {}
- repeat
- local b, e = str:find( del, 1, true )
- if b ~= nil then
- t[ #t + 1 ] = str:sub( 1, b - 1 )
- str = str:sub( e + 1 )
- end
- until b == nil
- t[ #t + 1 ] = str
- return t
- end
- function dbAdd(var)
- if var=="добавить имя" then
- add=io.read();
- dbName:write(add.."\n");
- varName=add;
- dbName:flush();
- end
- if var=="добавить префикс" then
- add=io.read();
- dbPrefix:write(add.."\n");
- varPrefix=add;
- dbPrefix:flush();
- end
- end
- function SAY(text)
- bot.say(chatNameString .. text);
- end
- function dbChoise(var)
- if var=="выбор имя" then
- print("##########");
- local t={};
- for line in io.lines("\\dbName.txt") do
- t[#t+1]=line;
- end
- for i=1,#t do
- print(t[i]);
- end
- print("##########")
- varChoise=io.read();
- varName=t[tonumber(varChoise)];
- end
- if var=="выбор префикс" then
- print("##########");
- local t={};
- for line in io.lines("\\dbPrefix.txt") do
- t[#t+1]=line;
- end
- for i=1,#t do
- print(t[i]);
- end
- print("##########")
- varChoise=io.read();
- varPrefix=t[tonumber(varChoise)];
- end
- end
- function txtFind(text, string)
- if text:find(string)~=nil then return true
- else return false
- end
- end
- function AnswerControl(msg)
- Mas={ };
- stringMas={ };
- acc=0;
- for line in io.lines("\\dbAnswer.txt") do
- Mas[#Mas+1]=line;
- end
- for i=1,#Mas,3 do
- local string = Mas[i];
- local stringMas = split(string,"$");
- local acc=0;
- for b=1,#stringMas,1 do
- if txtFind(msg,stringMas[b]) then
- acc=acc+1;
- end
- end
- if acc==#stringMas then
- SAY(Mas[i+1]);
- break;
- end
- end
- end
- function botMSG(nick, msg)
- if txtFind(msg, "риве") then
- SAY("§9привет сладкий :3");
- end
- if msg=="настроить" and (nick=="SanyaRamzik")then
- var=io.read();
- tKey(var);
- end
- AnswerControl(msg);
- end
- function tKey(var)
- if var=="имя" then
- name=io.read();
- varName=name;
- elseif var=="префикс" then
- prefix=io.read();
- varPrefix=prefix;
- elseif var=="добавить имя" then
- dbAdd(var);
- elseif var=="добавить префикс" then
- dbAdd(var);
- elseif var=="выбор префикс" then
- dbChoise(var);
- elseif var=="выбор имя" then
- dbChoise(var);
- elseif var=="выход" then
- os.exit(0);
- elseif var=="глобальный" then
- varConfChat="§6G";
- conf(varConfChat);
- elseif var=="локальный" then
- varConfChat="§fL";
- conf(varConfChat);
- end
- end
- while true do
- chatNameString="§8[§4" .. varPrefix .. "§8]" .. varName .. "§f: ";
- local _, add, nick, msg = event.pull("chat_message")
- botMSG(nick, msg);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement