Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Библиотеки
- local com = require("component")
- local computer = require('computer')
- local event = require('event')
- local sides = require('sides')
- local unicode = require('unicode')
- local term = require('term')
- local shell = require("shell")
- local fs = require('filesystem')
- --Компоненты
- local gpu = com.gpu
- local color = gpu.setForeground -- Установка заднего фона
- local rep = string.rep
- local cb = com.chat_box
- local color = gpu.setForeground
- --Загрузка
- color(0x00ff00)
- term.clear()
- gpu.setResolution(80,25)
- print("\nНастройка библиотек...")
- --os.sleep(2)
- if not fs.exists("/lib/stem.lua") then
- shell.execute("wget https://gitlab.com/UnicornFreedom/stem/raw/master/stem.lua /lib/stem.lua")
- end
- local stem = require('stem')
- if not fs.exists("/lib/moskovLib.lua") then
- shell.execute("wget https://www.dropbox.com/s/hpsx9fa4jpbpxet/moskovLib.lua?dl=1 /lib/moskovLib.lua")
- end
- local mos = require("moskovLib")
- print("\nИнициализация...")
- --os.sleep(2)
- print("Запуск программы...")
- --os.sleep(2)
- local server = stem.connect('stem.fomalhaut.me')
- --Конфиг
- local width, height = 146, 42
- cb.setName("§4WEB§7")
- --Глобальные переманные
- local roles = {{"NpVpanthera","&f[&4Куратор&f]"},{"nikilum", "&f[&1Гл.модератор&f]"},{"moskovroma","&f[&3Ст.модератор&f]"}}
- local roles_chat = {{"§4NpVpanthera","§8[§4К§8]"},{"§9nikilum", "§8[§9ГМ§8]"},{"§3moskovroma","§8[§3СТ§8]"}}
- local nick = ""
- local role = ""
- local channel_id = ""
- local log_message = {}
- local rol = ""
- --Фронтэнд
- function boxGlobalSmall(width,height,text,col)
- color(col)
- gpu.fill(1,1,1,height,'│')
- gpu.fill(width,1,1,height,'│')
- gpu.set(1,1,'┌'..string.rep('─',width-2)..'┐')
- gpu.set(1,height,'└'..string.rep('─',width-2)..'┘')
- gpu.fill(1+(width/4),1,1,height,'│')
- mos.centeringLeft(width,1,"&g┬")
- mos.centeringLeft(width,height,"&g┴")
- --mos.centeringRight(width,height,"&g╢ &7Автор: moskovroma&g ╟")
- if text ~= nil then
- mos.centeringMid(width+36,1,"&g╢ &7"..text.." &g╟")
- end
- end
- function drawConfig(nick)
- mos.centeringAny(8,2,width,2,"&gКонфиг")
- gpu.set(1,3,'├'..string.rep('─',((width)/4)-1)..'┤')
- mos.centeringAny(8,2,width,5,"&gПодключен: &6"..nick)
- for i=1,#roles do
- if nick == roles[i][1] then rol = roles[i][2] mos.centeringAny(8,2,width,6,"&gРоль: &3"..roles[i][2]) end
- end
- color(0x00ff00)
- gpu.set(1,8,'├'..string.rep('─',((width)/4)-1)..'┤')
- mos.printButton(9,10,20,3,0xffa500,0x00ff00,"Смена пользователя") --x,y,w,h,col1,col2,text
- mos.printButton(9,15,20,3,0x24b3a7,0x00ff00,"Смена канала")
- mos.printButton(9,height-4,20,3,0xff0000,0x00ff00,"Выход")
- end
- --Бекэнд
- function Connect( ... )
- term.clear()
- gpu.setResolution(80,25)
- mos.printText(0,1,"Подключение к серверу &3\'stem.fomalhaut.me\'")
- color(0x00ff00)
- print("\nВведите адрес канала: ")
- term.setCursor(23,2)
- channel_id = io.read()
- channel_id, _ = channel_id:gsub("\n", "")
- mos.printText(0,3,"Адрес канала: &3"..channel_id)
- color(0x00ff00)
- while true do
- mos.printText(0,5,"Введите ник: ")
- term.setCursor(14,5)
- nick = io.read()
- nick, _ = nick:gsub("\n", "")
- for i=1,#roles do
- if nick == roles[i][1] then
- role = roles_chat[i][2]
- return
- end
- end
- color(0xff0000)
- print("\nERROR: Ник веден не верно!")
- color(0x00ff00)
- os.sleep(2)
- mos.clearArea(1,4,80,height-4)
- end
- end
- function drawMessage( message )
- mos.clearArea(38,2,108,height - 2)
- local max = height - 4
- table.insert(log_message,message)
- if #log_message <=max then
- local i = 2
- for num = #log_message, 1, -1 do
- mos.printText(38,height-i,rol.." &8"..nick.."&f: &a"..log_message[num])
- i = i + 1
- end
- elseif #log_message > max then
- for num = #log_message, #log_message-max, -1 do
- mos.printText(38,height-i,rol.." &8"..nick.."&f: &a"..log_message[num])
- i = i + 1
- end
- end
- end
- function Click( x,y,nickT )
- if mos.pressButton(x,y,{9,height-4,20,3}) then --Выход
- term.clear()
- server:unsubscribe(channel_id)
- server:disconnect()
- os.exit()
- end
- end
- --Запуск
- Connect()
- term.clear()
- gpu.setResolution(width, height)
- server:subscribe(channel_id)
- --event.listen('stem_message', function(_, _, channel_id, message) drawMessage(message) end)
- while true do
- boxGlobalSmall(width,height,"OpenChat",0x00ff00)
- drawConfig(nick)
- local e, _, x, y, _, nickT = event.pull(10)
- if e == "touch" then
- Click(x,y,nickT)
- elseif e == "stem_message" then
- drawMessage(x)
- cb.say(role.." §8"..nick.."§f: §a"..x)
- elseif e == "chat_message" then
- server:send(channel_id, x..": "..y)
- end
- end
Add Comment
Please, Sign In to add comment