-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.rb
75 lines (59 loc) · 1.74 KB
/
main.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
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
# Requied packages / modules
require_relative("irc.rb")
require_relative("twitch_commands.rb")
require_relative("local_commands.rb")
# Socket
init_socket
init_msg_thread # Thread to queue up responses and respect rate limits
# Authorization Login
send_raw("PASS #{$oauth}") # Send the password(oauth) to Twitch
send_raw("NICK #{$botname}") # Send the botname to Twitch
send_raw("JOIN ##{$channel}") # Send the channel to Twitch
# Thread Initialization
Thread.abort_on_exception = true
running = true
# Thread for recieving Twitch IRC data
Thread.start do
send_msg("Connected!")
puts "#{$botname} Joined ##{$channel}" # Connection Status
puts "You should be fully connected now" # Connection Status
while (running) do
ready = IO.select([$socket])
ready[0].each do |s|
line = s.gets
# Twitch PING Message
if line.index("PING") == 0
puts("-".bold.red * line.length)
puts("#{"[Twitch]".bold.cyan} #{"IRC".bold.yellow}: #{line.strip.bold.green}")
puts("-".bold.red * line.length)
send_raw("PONG :tmi.twitch.tv\r\n") # Respond to Twitch IRC PING message
else
message_data = line.match(/^:(.+)!(.+)PRIVMSG ##{$channel} :(.+)$/)
# Message from chat
if message_data
user = message_data[1].chomp
message = message_data[3].chomp
# Command
if message[0] == $prefix
twitch_command(user, message)
# Message
else
puts("#{"[MESSAGE]".bold.green} #{user.bold}: #{message.bold.green}")
end
end
end
end
end
end
# Loop to keep bot going and for taking user input in console
clear_console
while (running) do
input = gets.chomp.downcase
if input == "disconnect"
send_msg("Disconnecting!")
send_msg("/disconnect")
running = false
exit
end
local_command(input)
end