forked from benstigsen/RubyTwitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirc.rb
36 lines (30 loc) · 731 Bytes
/
irc.rb
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
# Initiate Socket
def init_socket
require("socket")
$socket = TCPSocket.new("irc.chat.twitch.tv", 6667)
$oauth, $botname, $channel = get_credentials
$messages = Array.new
end
# Initiate Response Queue
def init_msg_thread()
Thread.new do
while true
if $messages.length > 0
send_msg($messages.shift)
end
sleep(2) # Let's you send a max of 30 requests every 60 seconds
# DecAPI rate limit: 100 messages per 60 seconds
# Twitch rate limit: 100 messages per 30 seconds
end
end
end
# Send chat message
def send_msg(data)
# puts("[SENDMSG] #{data}")
$socket.puts("PRIVMSG ##{$channel} :#{data}\r\n")
end
# Send raw data
def send_raw(data)
# puts("[SENDRAW] #{data}")
$socket.puts("#{data}\r\n")
end