-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxshellz.rb
88 lines (67 loc) · 1.81 KB
/
xshellz.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
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'yaml'
require 'socket'
class XshellZ
attr_reader :server, :port, :username
attr_accessor :channel, :message
def initialize(server, port, username)
# Instance variables
@server = server
@port = port
@username = username
@socket
# let's call the connect method by the time the object is instantiate
connect
end
def connect
@socket = TCPSocket.open(@server, @port)
#print("addr: ", @socket.addr.join(":"), "\n")
#print("peer: ", @socket.peeraddr.join(":"), "\n")
@socket.puts "NICK #{@username}"
@socket.puts "USER #{@username} 0 * :#{@username}"
end
def channel=(channel)
@channel = channel
end
def join_channel
@socket.puts "JOIN #{@channel}"
end
def message=(message)
@message = message
end
def send_msg
@socket.puts "PRIVMSG #{@channel} :#{@message}"
while line = @socket.gets
#puts line.chop
if line.match(/End of \/NAMES list/)
#puts "Closing client socket"
@socket.puts "QUIT Disconnecting ..."
end
end
end
def disconnect
@socket.close
end
end
if __FILE__ == $0
# -------------------------------------
# MAIN CODE
# -------------------------------------
# Reading settings from YML
settings = YAML.load_file('account.yml')
server = settings['xshellz']['server']
port = settings['xshellz']['port']
username = settings['xshellz']['username']
# Running BotXshellZ
client = XshellZ.new(server, port, username)
trap("INT"){ client.disconnect }
# Setting the channel writter attribute
client.channel = "#tjt"
# Joinning the channel
client.join_channel
# Setting the message writter attribute
client.message = "!keep #{username}"
# Sending the message to the channel
client.send_msg
# Closing the socket nicely
client.disconnect
end