public
Description: An IRC bot that keeps track of who is who and makes links between users.
Homepage:
Clone URL: git://github.com/seadog/ybttre.git
Click here to lend your support to: ybttre and make a donation at www.pledgie.com !
ybttre / IRC.rb
100644 76 lines (64 sloc) 1.183 kb
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
require 'socket'
require 'openssl'
 
class IRC
attr_accessor :version, :listener
def initialize nick, ident, real, server, port, ssl
@sock = nil
@nick = nick
@ident = ident
@real = real
@server = server
@port = port
@ssl = ssl
end
 
def connect
@connection_password = generate_connection_password
socket = TCPSocket.new(@server, @port)
if @ssl == 1
@sock = OpenSSL::SSL::SSLSocket.new(socket)
@sock.connect
else
@sock = socket
end
if @sock
true
else
false
end
end
 
def send_line(line)
@sock.print("#{line}\r\n")
puts " --> #{line}"
end
 
def join_channel(chan)
send_line("JOIN #{chan}")
end
 
def send_pass_nick_user
send_line "PASS #{@connection_password}"
send_line "NICK #{@nick}"
send_line "USER #{@ident} hostname servername :#{@real}"
end
 
def readline
@sock.readline.chomp
end
 
def connected?
!@sock.closed?
end
 
def close
@sock.close
end
 
def pong num
send_line "PONG :#{num}"
end
 
def notice nick, message
send_line "NOTICE #{nick} :#{message}"
end
private
 
def generate_connection_password
a = String.new
2.times do
a += (rand*100000).to_i.to_s(36)
end
a
end
end