-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.rb
62 lines (48 loc) · 1.29 KB
/
bot.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
require 'socket'
require 'plugin'
module Bot
class Polkabot < Plugin
def initialize(server,port,nick,channel)
@server = server
@port = port
@socket = TCPSocket.open(@server, @port)
@nick = nick
@channel = channel
say_to_chan "NICK #{@nick}"
say_to_chan "USER #{@nick} 0 * #{@nick}"
say_to_chan "JOIN ##{@channel}"
say_to_chan "PRIVMSG ##{@channel} : All hail gsathya"
end
def say_to_chan(msg)
puts msg
@socket.puts msg
end
def say(msg)
puts msg
@socket.puts "PRIVMSG ##{@channel} :#{@username}, #{msg}"
end
def parse
match
rescue LocalJumpError
puts "Local Jump Error"
end
def die
say_to_chan "PART ##{@channel}"
say_to_chan 'QUIT'
@socket.close
end
def run
until @socket.eof? do
@msg = @socket.gets.strip
puts @msg
@username = @msg.match("(:)(.*)(!)").to_s.delete(':!')
if @msg.match(/^PING :(.*)$/) then
say_to_chan "PONG #{$~[1]}"
end
parse
end
rescue IOError
puts "Flush Socket"
end
end
end