-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
69 lines (50 loc) · 1.61 KB
/
main.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
local config = require( "config" )
local console = require( "console" )
local handle = require( "handle" )
local sendChannel
local receiveChannel
local function messageType( msg )
local msgType = "unknown"
if string.sub( msg, 1, 4 ) == "PING" then -- the message is a ping
msgType = "ping"
elseif string.find( msg, ":[%w_]+![%w_]+@[%w_]+%.tmi%.twitch%.tv PRIVMSG #[%w_]+ :" ) then -- if the message contains this pattern then it is a chat message
msgType = "chat"
end
return msgType
end
function love.load()
love.window.setMode( 1280, 720 )
love.window.setTitle( "Lua IRC API" )
love.graphics.setBackgroundColor( 102, 102, 102 )
local IRCThread = love.thread.newThread( "poll.lua" )
sendChannel = love.thread.getChannel( "IRCSend" )
receiveChannel = love.thread.getChannel( "IRCReceive" )
IRCThread:start()
console:init( 0, 0, 560, 720 )
end
function love.update()
local response = receiveChannel:pop()
if response == nil then return end
print( response )
local reply = handle.message( response, messageType( response ), console )
if reply then
sendChannel:push( reply .. "\r\n" )
end
end
function love.draw()
console:draw()
love.graphics.setColor( 255, 255, 255 )
love.graphics.print( love.timer.getDelta(), 570, 10 )
for i = 1,9 do
local coord = 72 * i
love.graphics.line( 560 + coord, 0, 560 + coord, 720 )
love.graphics.line( 560, coord, 1280, coord )
end
end
function love.wheelmoved( xDelta, yDelta )
console:scroll( -yDelta )
end
function love.threaderror( thread, errStr )
print( "Thread error:" )
print( errStr )
end