/
OmegleClient.lua
115 lines (105 loc) · 3.5 KB
/
OmegleClient.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--@import me.yevano.omegle.OmegleSession
--@import see.hook.Hooks
--@import see.net.Http
--@import see.concurrent.ThreadPool
--@import see.io.Terminal
--@import see.util.Color
function OmegleClient.main(args)
local threadPool = ThreadPool.new()
local session = OmegleSession.new(args:unpack())
local connected = true
local typing = false
local connectionHook
if Terminal.isColor() then
Terminal.setFG(Color.PURPLE)
end
if session.commonLikes then
local intString = String.new()
if session.commonLikes:length() > 0 then
intString:add(session.commonLikes[1])
end
for i = 2, session.commonLikes:length() do
intString:add(STR(", ", session.commonLikes[i]))
end
System.print(STR("Found partner with common interests: ", intString, "."))
end
System.print(STR("Connected to ", session.id))
session:requestEvent()
local sendString = String.new()
connectionHook = Hooks.add("http_success", function(url, handle)
local event = session:extractEvent(handle.readAll())
if event then
if event.type == OmegleSession.EVENT_MESSAGE then
Terminal.clearLine()
if Terminal.isColor() then
Terminal.setFG(Color.RED)
System.write("Stranger: ")
Terminal.setFG(Color.YELLOW)
else
System.write("Stranger: ")
end
System.print(event.message)
drawInput(typing, sendString)
elseif event.type == OmegleSession.EVENT_TYPING then
typing = not typing
elseif event.type == OmegleSession.EVENT_DISCONNECTED then
if Terminal.isColor() then
Terminal.setFG(Color.PURPLE)
end
System.print("Stranger disconnected.")
connected = false
Hooks.remove(connectionHook)
end
end
session:requestEvent()
end)
Hooks.add("char", function(c)
sendString:add(c)
drawInput(typing, sendString)
end)
Hooks.add("key", function(k)
if k == 28 then
session:send(sendString)
if Terminal.isColor() then
Terminal.setFG(Color.BLUE)
System.write("You: ")
Terminal.setFG(Color.YELLOW)
else
System.write("You: ")
end
System.print(sendString)
sendString = String.new()
drawInput(typing, sendString)
elseif k == 14 then
if sendString:length() == 0 then return end
sendString:remove(-1, 1)
drawInput(typing, sendString)
elseif k == 157 then
connected = false
session:disconnect()
if Terminal.isColor() then
Terminal.setFG(Color.PURPLE)
end
System.print("You have disconnected.")
end
end)
while connected do
Hooks.run()
end
end
function drawInput(typing, message)
if Terminal.isColor() then
Terminal.setFG(Color.WHITE)
end
local pos = Terminal.getPos()
local size = Terminal.getSize()
Terminal.setPos(1, size.y)
Terminal.write(typing and "T" or " ")
Terminal.clearLine()
if message:length() > size.x - 1 then
Terminal.write(message:sub(-(size.x - 1), -1):lstr())
else
Terminal.write(message:lstr())
end
Terminal.setPos(pos.x, pos.y)
end