Advertisement
Freack100

DisCCord package

Jan 13th, 2017
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.03 KB | None | 0 0
  1. local bc=select(1,...)or""
  2. local cc={["main.lua"]="local db;db=dofile(\"fix.lua\").require;local _c\
  3. _c=db(\"http\").AsyncHTTPQueue;local ac;ac=table.sort;local bc,cc=term.getSize()local dc=db(\"json\")local _d=_c()\
  4. local ad\
  5. local bd=Application(1,1,bc,cc):set({terminatable=true,colour=colours.white,backgroundColour=colours.grey})bd:importFromTML(\"markup/master.tml\")\
  6. local cd={servers={},server=\"\",channel=\"\",lastMessages={},channels={},channelsOpen=false}\
  7. local dd={masterTheme=Theme.fromFile(\"masterTheme\",\"styles/master.theme\"),pages=bd:query(\"PageContainer\").result[1],serverSelector=bd:query(\"Dropdown#serverSelector\").result[1],serverUsername=bd:query(\"Input#usernameInput\").result[1],channelsContainer=bd:query(\"ScrollContainer#channels\").result[1],messageContainer=bd:query(\"ScrollContainer#messages\").result[1]}bd:addTheme(dd.masterTheme)\
  8. _d:get(\"servers\",function(b_a)b_a=dc.parse(b_a)\
  9. cd.servers=b_a;for c_a,d_a in pairs(cd.servers)do\
  10. dd.serverSelector:addOption(d_a,d_a)end end)local __a\
  11. __a=function()\
  12. return\
  13. _d:get(\"receive/\"..cd.server..\"/\"..cd.channel,function(b_a)\
  14. local c_a=dc.parse(b_a)\
  15. ac(c_a,function(_aa,aaa)return _aa.timestamp<aaa.timestamp end)cd.lastMessages=c_a\
  16. dd.messageContainer:clearNodes()local d_a=0\
  17. for _aa,aaa in pairs(cd.lastMessages)do\
  18. local baa=Label(aaa.author..\":\",1,_aa+d_a):set({colour=colors.cyan})\
  19. local caa=TextContainer(aaa.content,1,_aa+d_a+1,50,3):set({backgroundColour=colors.black})dd.messageContainer:addNode(baa)\
  20. dd.messageContainer:addNode(caa)d_a=d_a+3 end end)end;local a_a\
  21. a_a=function()\
  22. return\
  23. _d:get(\"server/\"..cd.server..\"/channels\",function(b_a)\
  24. b_a=dc.parse(b_a)cd.channels=b_a;dd.channelsContainer:clearNodes()\
  25. for c_a,d_a in\
  26. pairs(cd.channels)do\
  27. local _aa=Button(\"#\"..d_a):set({height=3,width=10,horizontalAlign=\"centre\",verticalAlign=\"centre\",X=1,Y=1 + ( (c_a-1)*3)})\
  28. _aa:on(\"trigger\",function(aaa)cd.channel=d_a;return __a()end)dd.channelsContainer:addNode(_aa)end end)end\
  29. bd:query(\"#serverNextButton\"):on(\"trigger\",function(b_a)\
  30. local c_a=dd.serverSelector:getSelectedValue()local d_a=dd.serverUsername.value\
  31. if c_a and#d_a>0 then cd.server=c_a\
  32. cd.username=d_a;a_a()return dd.pages:selectPage(\"chat\")end end)\
  33. bd:query(\"#chatBackButton\"):on(\"trigger\",function(b_a)cd.server=\"\"cd.channel=\"\"return\
  34. dd.pages:selectPage(\"serverSelect\")end)\
  35. bd:query(\"#toggleChannels\"):on(\"trigger\",function(b_a)\
  36. cd.channelsOpen=not cd.channelsOpen;b_a.text=cd.channelsOpen and\"<\"or\">\"\
  37. return\
  38. bd:query(\"#channelsContainer\").result[1]:animate(\"animateChannelContainer\",\"X\",\
  39. cd.channelsOpen and 1 or-8,0.3,cd.channelsOpen and\"inCubic\"or\"outCubic\",function()\
  40. end)end)\
  41. bd:query(\"#chatInput\"):on(\"trigger\",function(b_a,c_a,d_a)local _aa=c_a;b_a.value=\"\"\
  42. local aaa=dc.stringify({user=cd.username,content=_aa})return\
  43. _d:post(\"send/\"..cd.server..\"/\"..cd.channel,aaa,function()end)end)dd.pages:selectPage(\"serverSelect\")\
  44. ad=os.startTimer(1)\
  45. bd:addThread(Thread(function()\
  46. while true do local b_a={coroutine.yield()}\
  47. if b_a[1]==\"timer\"and\
  48. b_a[2]==ad then\
  49. if dd.server~=\"\"and dd.channel~=\"\"then __a()end;ad=os.startTimer(2)end end end))bd:addThread(_d:startRequestsThread())\
  50. bd:addThread(_d:handleResponsesThread())return bd:start()",["nodes/node.ti"]="",["fix.lua"]="local b\
  51. b=function(c)\
  52. if fs.exists(c)then return dofile(c)else return dofile(c..\".lua\")end end;return{require=b}",["json.lua"]="local ba={}\
  53. local function ca(cb)if type(cb)~='table'then return type(cb)end;local db=1\
  54. for _c in pairs(cb)do if\
  55. cb[db]~=nil then db=db+1 else return'table'end end;if db==1 then return'table'else return'array'end end\
  56. local function da(cb)local db={'\\\\','\"','/','\\b','\\f','\\n','\\r','\\t'}\
  57. local _c={'\\\\','\"','/','b','f','n','r','t'}\
  58. for ac,bc in ipairs(db)do cb=cb:gsub(bc,'\\\\'.._c[ac])end;return cb end\
  59. local function _b(cb,db,_c,ac)db=db+#cb:match('^%s*',db)\
  60. if\
  61. cb:sub(db,db)~=_c then if ac then\
  62. error('Expected '.._c..' near position '..db)end;return db,false end;return db+1,true end\
  63. local function ab(cb,db,_c)_c=_c or''local ac='End of input found while parsing string.'if db>#cb then\
  64. error(ac)end;local bc=cb:sub(db,db)if bc=='\"'then return _c,db+1 end;if\
  65. bc~='\\\\'then return ab(cb,db+1,_c..bc)end\
  66. local cc={b='\\b',f='\\f',n='\\n',r='\\r',t='\\t'}local dc=cb:sub(db+1,db+1)if not dc then error(ac)end;return ab(cb,db+2,_c..\
  67. (cc[dc]or dc))end\
  68. local function bb(cb,db)local _c=cb:match('^-?%d+%.?%d*[eE]?[+-]?%d*',db)\
  69. local ac=tonumber(_c)if not ac then\
  70. error('Error parsing number at position '..db..'.')end;return ac,db+#_c end\
  71. function ba.stringify(cb,db)local _c={}local ac=ca(cb)\
  72. if ac=='array'then if db then\
  73. error('Can\\'t encode array as key.')end;_c[#_c+1]='['\
  74. for bc,cc in ipairs(cb)do if bc>1 then\
  75. _c[#_c+1]=', 'end;_c[#_c+1]=ba.stringify(cc)end;_c[#_c+1]=']'elseif ac=='table'then if db then\
  76. error('Can\\'t encode table as key.')end;_c[#_c+1]='{'\
  77. for bc,cc in pairs(cb)do if#_c>1 then\
  78. _c[#_c+1]=', 'end;_c[#_c+1]=ba.stringify(bc,true)\
  79. _c[#_c+1]=':'_c[#_c+1]=ba.stringify(cc)end;_c[#_c+1]='}'elseif ac=='string'then return'\"'..da(cb)..'\"'elseif ac=='number'then if db then return\
  80. '\"'..tostring(cb)..'\"'end;return\
  81. tostring(cb)elseif ac=='boolean'then return tostring(cb)elseif ac=='nil'then return'null'else error('Unjsonifiable type: '..\
  82. ac..'.')end;return table.concat(_c)end;ba.null={}\
  83. function ba.parse(cb,db,_c)db=db or 1;if db>#cb then\
  84. error('Reached unexpected end of input.')end\
  85. local ac=db+#cb:match('^%s*',db)local bc=cb:sub(ac,ac)\
  86. if bc=='{'then local cc,dc,_d={},true,true;ac=ac+1\
  87. while true do\
  88. dc,ac=ba.parse(cb,ac,'}')if dc==nil then return cc,ac end;if not _d then\
  89. error('Comma missing between object items.')end;ac=_b(cb,ac,':',true)\
  90. cc[dc],ac=ba.parse(cb,ac)ac,_d=_b(cb,ac,',')end elseif bc=='['then local cc,dc,_d={},true,true;ac=ac+1\
  91. while true do dc,ac=ba.parse(cb,ac,']')if dc==nil then\
  92. return cc,ac end;if not _d then\
  93. error('Comma missing between array items.')end;cc[#cc+1]=dc;ac,_d=_b(cb,ac,',')end elseif bc=='\"'then return ab(cb,ac+1)elseif bc=='-'or bc:match('%d')then return bb(cb,ac)elseif bc==\
  94. _c then return nil,ac+1 else\
  95. local cc={['true']=true,['false']=false,['null']=ba.null}for _d,ad in pairs(cc)do local bd=ac+#_d-1\
  96. if cb:sub(ac,bd)==_d then return ad,bd+1 end end;local dc='position '..ac..\
  97. ': '..cb:sub(ac,ac+10)error(\
  98. 'Invalid json syntax starting at '..dc)end end;return ba",["styles/master.theme"]="<Input>\
  99.  <backgroundColour>lightGray</backgroundColour>\
  100. </Input>\
  101. \
  102. <Button id=serverNextButton>\
  103.  <horizontalAlign>centre</horizontalAlign>\
  104.  <backgroundColour>cyan</backgroundColour>\
  105.  <activeColour>black</activeColour>\
  106.  <activeBackgroundColour>white</activeBackgroundColour>\
  107. </Button>\
  108. \
  109. <Input id=chatInput>\
  110.  <backgroundColour>white</backgroundColour>\
  111.  <colour>lightGrey</colour>\
  112.  <focusedColour>black</focusedColour>\
  113. </Input>\
  114. \
  115. <ScrollContainer id=messages>\
  116.  <backgroundColour>gray</backgroundColour>\
  117.  <scrollbarColour>lightBlue</scrollbarColour>\
  118.  <activeScrollbarColour>blue</activeScrollbarColour>\
  119.  <trayColour>lightGray</trayColour>\
  120. </ScrollContainer>\
  121. \
  122. <Container id=channelsContainer>\
  123.  <backgroundColour>black</backgroundColour>\
  124. </Container>\
  125. \
  126. <ScrollContainer id=channels>\
  127.  <backgroundColour>black</backgroundColour>\
  128. </ScrollContainer>\
  129. \
  130. <Button id=chatBackButton>\
  131.  <horizontalAlign>centre</horizontalAlign>\
  132.  <backgroundColour>black</backgroundColour>\
  133.  <colour>lightGray</colour>\
  134. </Button>\
  135. \
  136. <TextContainer class=\"message\">\
  137.  <backgroundColour>green</backgroundColour>\
  138. </TextContainer>\
  139. ",["markup/master.tml"]="<PageContainer X=1 Y=1 width=51 height=19>\
  140. \
  141.  <Page id=serverSelect xScrollAllowed=false>\
  142.    <Label X=22 Y=3 text=\"DisCCord\" />\
  143.    <Label X=7 Y=6 text=\"Server:\" />\
  144.    <Label X=27 Y=6 text=\"Username:\" />\
  145.    <Input X=27 Y=7 limit=20 width=18 id=usernameInput />\
  146.    <Button X=17 Y=11 width=18 id=serverNextButton text=\"Next\" />\
  147.    <Dropdown X=7 Y=7 width=18 maxHeight=4 id=serverSelector />\
  148.  </Page>\
  149. \
  150.  <Page id=chat>\
  151.  <Button X=45 Y=19 text=\"back\" width=7 id=chatBackButton />\
  152. \
  153.  <ScrollContainer X=2 Y=1 height=18 width=50 id=messages xScrollAllowed=false/>\
  154. \
  155.  <Input X=2 Y=19 width=43 limit=100 id=chatInput placeholder=\"Insert text here...\"/>\
  156. \
  157.    <Container X=\"-8\" Y=1 height=19 width=10 id=channelsContainer>\
  158.      <ScrollContainer X=1 Y=2 width=10 height=18 id=channels/>\
  159.      <Label X=1 Y=1 text=\"Channels \" backgroundColour=black/>\
  160.      <Button X=10 Y=1 width=1 text=\">\" id=toggleChannels/>\
  161.    </Container>\
  162.  </Page>\
  163. \
  164. </PageContainer>\
  165. ",["http.lua"]="local aa,ba,ca,da,_b;aa=table.insert\
  166. ba={[\"Content-Type\"]=\"application/json; charset=UTF-8\",[\"Content-Encoding\"]=\"identity\"}ca=\"http://misoshiki-bot-misoshiki.44fs.preview.openshiftapps.com/\"\
  167. do local ab\
  168. local bb={}bb.__index=bb\
  169. ab=setmetatable({__init=function(cb,db,_c,ac,bc)cb.url=ca..db;cb.callback=bc;cb.headers=ac;cb.data=_c\
  170. cb.running=false;cb.processed=false end,__base=bb,__name=\"AsyncHTTPRequest\"},{__index=bb,__call=function(cb,...)\
  171. local db=setmetatable({},bb)cb.__init(db,...)return db end})bb.__class=ab;da=ab end\
  172. do local ab\
  173. local bb={get=function(cb,db,_c)return aa(cb.requests,da(db,nil,nil,_c))end,post=function(cb,db,_c,ac)return\
  174. aa(cb.requests,da(db,_c,ba,ac))end,startRequestsThread=function(cb)\
  175. return\
  176. Thread(function()while true do sleep(0)\
  177. for db,_c in\
  178. pairs(cb.requests)do if not _c.running then _c.running=true\
  179. http.request(_c.url,_c.data,_c.headers)end end end end)end,handleResponsesThread=function(cb)\
  180. return\
  181. Thread(function()\
  182. while\
  183. true do local db={coroutine.yield(\"http_success\")}\
  184. local _c,ac=db[2],false\
  185. for bc,cc in pairs(cb.requests)do\
  186. if not ac then\
  187. if cc.url==_c and not cc.processed then ac=true\
  188. local dc=db[3]local _d=dc.readAll()dc:close()\
  189. pcall(function()return cc.callback(_d)end)cc.processed=true end end end end end)end}bb.__index=bb\
  190. ab=setmetatable({__init=function(cb)cb.requests={}end,__base=bb,__name=\"AsyncHTTPQueue\"},{__index=bb,__call=function(cb,...)\
  191. local db=setmetatable({},bb)cb.__init(db,...)return db end})bb.__class=ab;_b=ab end;return{AsyncHTTPQueue=_b,AsyncHTTPRequest=da}"}local dc=
  192. type(getfenv)=="function"and getfenv()or _ENV or _G;if dc.TI_VFS_RAW then
  193. dc=dc.TI_VFS_RAW end;local _d=dc.fs
  194. local ad=setmetatable({fs=setmetatable({},{__index=_G["fs"]}),os=setmetatable({},{__index=_G["os"]})},{__index=dc})local bd=ad["fs"]
  195. local cd=setmetatable({},{__index=function(caa,daa)if daa=="TI_VFS_RAW"then return ad end
  196. return ad[daa]end})cd._G=cd;cd._ENV=cd
  197. local dd={["markup"]=true,["styles"]=true,["nodes"]=true}
  198. local __a={["^"]="%^",["$"]="%$",["("]="%(",[")"]="%)",["%"]="%%",["*"]="[^/]*",["."]="%.",["["]="%[",["]"]="%]",["+"]="%+",["-"]="%-"}
  199. function cd.load(caa,daa,_ba,aba)return load(caa,daa or'(load)',_ba,aba or cd)end
  200. function cd.loadstring(caa,daa)return cd.load(caa,daa,'t',cd)end
  201. function cd.loadfile(caa,daa)local _ba=cd;local aba=fs.open(caa,"r")if aba then local bba,cba=load(aba.readAll(),fs.getName(caa),'t',
  202. daa or cd)
  203. aba.close()return bba,cba end
  204. return nil,'File not found'end
  205. if type(setfenv)=="function"then setfenv(cd.loadfile,cd)end
  206. function cd.os.run(caa,daa,...)local _ba=cd;local aba,bba={...},caa
  207. setmetatable(bba,{__index=cd})local cba,dba=loadfile(daa,bba)
  208. if cba then local _ca,aca=pcall(function()
  209. cba(table.unpack(aba))end)
  210. if not _ca then if aca and
  211. aca~=""then printError(aca)end;return false end;return true end;if dba and dba~=""then printError(dba)end;return false end;local a_a={}
  212. function cd.os.loadAPI(caa)local daa,_ba=cd,fs.getName(caa)if a_a[_ba]==true then
  213. printError("API ".._ba..
  214. " is already being loaded")return false end;a_a[_ba]=true
  215. local aba=setmetatable({},{__index=cd})local bba,cba=loadfile(caa,aba)
  216. if bba then local _ca,aca=pcall(bba)if not _ca then
  217. printError(aca)a_a[_ba]=nil;return false end else printError(cba)a_a[_ba]=
  218. nil;return false end;local dba={}
  219. for _ca,aca in pairs(aba)do if _ca~="_ENV"then dba[_ca]=aca end end;cd[_ba],a_a[_ba]=dba,nil;return true end;cd.os.loadAPI"/rom/apis/io"
  220. function cd.dofile(caa)local daa=cd
  221. local _ba,aba=loadfile(caa,cd)if _ba then return _ba()else error(aba,2)end end
  222. if type(setfenv)=="function"then setfenv(cd.dofile,cd)end
  223. function bd.open(caa,daa)caa=fs.combine("",caa)
  224. if cc[caa]then
  225. if
  226. daa=="w"or daa=="wb"or daa=="a"or daa=="ab"then return
  227. error("Cannot open file in mode '"..tostring(daa)..
  228. "'. File is inside of Titanium VFS and is read only")end;local _ba,aba=cc[caa],{}if daa=="rb"then
  229. aba.read=function()if#_ba==0 then return end
  230. local bba=_ba:sub(1,1):byte()_ba=_ba:sub(2)return bba end end
  231. aba.readLine=function()if
  232. #_ba==0 then return end;local bba,cba=_ba:match"^([^\n\r]*)[\n\r](.*)$"
  233. _ba=cba or""return bba or _ba end
  234. aba.readAll=function()if#_ba==0 then return end;local bba=_ba;_ba=""return bba end;aba.close=function()_ba=""end;return aba else return
  235. _d.open(fs.combine(bc,caa),daa)end end
  236. function bd.isReadOnly(caa)caa=fs.combine("",caa)if cc[caa]then return true end;return
  237. _d.isReadOnly(fs.combine(bc,caa))end;function bd.getSize(caa)
  238. return cc[caa]and#cc[caa]or _d.getSize(caa)end
  239. function bd.list(caa)caa=fs.combine("",caa)local daa=
  240. _d.isDir(caa)and _d.list(caa)or{}
  241. local function _ba(aba)for i=1,#daa do if
  242. daa[i]==aba then return end end;daa[#daa+1]=aba end
  243. if dd[caa]then
  244. for aba in pairs(cc)do if aba:match(("^%s/"):format(caa))then
  245. _ba(aba:match(("^%s/([^/]+)"):format(caa)))end end elseif caa==""then
  246. for aba in pairs(cc)do _ba(aba:match"^([^/]+)")end end;return daa end
  247. function bd.find(caa)caa=fs.combine("",caa)local daa=_d.find(caa)or{}
  248. caa=("^(%s)(.*)$"):format(caa:gsub(".",__a))
  249. for _ba in pairs(cc)do local aba,bba=_ba:match(caa)
  250. if aba and
  251. (bba==""or bba:sub(1,1)=="/")then local cba
  252. for i=1,#daa do if daa[i]==aba then cba=true;break end end;if not cba then daa[#daa+1]=aba end end end;return daa end
  253. function bd.isDir(caa)caa=fs.combine("",caa)return dd[caa]or
  254. _d.isDir(fs.combine(bc,caa))end
  255. function bd.exists(caa)caa=fs.combine("",caa)
  256. if cc[caa]or dd[caa]then return true end;return _d.exists(fs.combine(bc,caa))end;local b_a=fs.combine(bc,"/tpm")
  257. if not fs.exists(b_a)then if not http then return
  258. error"HTTP API required"end
  259. local caa=http.get"https://gitlab.com/hbomb79/Titanium-Package-Manager/raw/master/tpm"if not caa then return error"Failed to download TPM"end
  260. local daa=fs.open(b_a,"w")daa.write(caa.readAll())caa.close()
  261. daa.close()end;local c_a,d_a=loadfile(b_a)if not c_a then return
  262. error("Failed to load TPM '"..tostring(d_a).."'")end
  263. c_a"fetch"
  264. c_a("--disposable","--depend",shell.getRunningProgram(),"install","Titanium:v0.1.0-alpha.7")if not cd.Titanium then
  265. cd.dofile("/.tpm/packages/Titanium/v0.1.0-alpha.7")end;local _aa=cd.Titanium
  266. if not _aa then
  267. return
  268. error"Failed to execute Titanium package. Titanium is not loaded. Please load Titanium before executing this package, or repackage this application using the --titanium flag."end;local aaa,baa=cd.loadfile"main.lua"if aaa then aaa()else
  269. return error("Failed to run file from bundle vfs: "..
  270. tostring(baa))end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement