update ruby client
This commit is contained in:
parent
4fb053fbe9
commit
f742b9fc88
@ -14,16 +14,19 @@
|
|||||||
# Type Enter and nothing else to refresh the messages.
|
# Type Enter and nothing else to refresh the messages.
|
||||||
# Type messages and send them, hopefully everyone hears you just fine.
|
# Type messages and send them, hopefully everyone hears you just fine.
|
||||||
#
|
#
|
||||||
# Commands (which always begin with a forward slash):
|
# Commands (which always begin with a forward slash, case doesn't matter):
|
||||||
#
|
#
|
||||||
# Commands must be near the beginning of messages, and will preform their respective action.
|
# Commands must be near the beginning of messages, and will preform their respective action.
|
||||||
#
|
#
|
||||||
# BYE, QUIT - exits
|
# BYE, QUIT - exits
|
||||||
# SAY - says something verbatim
|
# SAY - says something verbatim
|
||||||
|
# RAW - send a raw message (no prefix)
|
||||||
# CLEAR - clears the terminal
|
# CLEAR - clears the terminal
|
||||||
# NICK... - sets the nick
|
# NICK... - sets the nick
|
||||||
# RECONNECT - reconnects
|
# RECONNECT - reconnects
|
||||||
# DELAY... - sets delays
|
# DELAY... - sets delays
|
||||||
|
#
|
||||||
|
# /nick anon9999
|
||||||
|
|
||||||
require 'socket'
|
require 'socket'
|
||||||
require 'readline'
|
require 'readline'
|
||||||
@ -40,13 +43,17 @@ def read_from(socket)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def raw(socket, msg)
|
||||||
|
socket.puts(msg)
|
||||||
|
end
|
||||||
|
|
||||||
def post(socket, msg)
|
def post(socket, msg)
|
||||||
update_prefix
|
update_prefix
|
||||||
socket.puts(@prefix + msg)
|
raw(socket, @prefix + msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_prefix
|
def update_prefix
|
||||||
date = Time.now.utc.strftime("%Y/%m/%d %k:%M:%S")
|
date = Time.now.utc.strftime("%Y/%m/%d %k:%M")
|
||||||
@prefix = "<#{date} #{@name}> "
|
@prefix = "<#{date} #{@name}> "
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -82,36 +89,47 @@ def main
|
|||||||
delay = 0
|
delay = 0
|
||||||
|
|
||||||
h = { "BYE" => 1, "QUIT" => 1, "SAY" => 2, "CLEAR" => 3, "NAME" => 4, "NICK" => 4,
|
h = { "BYE" => 1, "QUIT" => 1, "SAY" => 2, "CLEAR" => 3, "NAME" => 4, "NICK" => 4,
|
||||||
"RC" => 5, "RECONNECT" => 5, "DELAY" => 6 }
|
"RC" => 5, "RECONNECT" => 5, "DELAY" => 6, "RAW" => 7 }
|
||||||
|
|
||||||
update_prefix
|
update_prefix
|
||||||
while msg = Readline.readline(@prefix, true)
|
while msg = Readline.readline(@prefix, true)
|
||||||
if not msg.empty?
|
if not msg.empty?
|
||||||
msg.strip!
|
msg.strip!
|
||||||
word = msg.split(/^\/([\w]*)$|^([\w]*) (.*)$/)[1..]
|
word = msg.split(/^\/([\w]*)\W+?(.*)?$/)[1..]
|
||||||
case h[word[0]]
|
if not word.empty?
|
||||||
when h["BYE"]
|
case h[word[0].upcase]
|
||||||
post(socket, "BYE")
|
when h["BYE"]
|
||||||
exit 0
|
post(socket, "BYE")
|
||||||
when h["CLEAR"]
|
exit 0
|
||||||
puts "\e[1;1H\e[2J"
|
when h["CLEAR"]
|
||||||
when h["NICK"]
|
puts "\e[1;1H\e[2J"
|
||||||
if not word[1].empty?
|
when h["NICK"]
|
||||||
@name = word[1]
|
if not word[1].empty?
|
||||||
|
@name = word[1]
|
||||||
|
end
|
||||||
|
when h["RC"]
|
||||||
|
puts "reconnecting..."
|
||||||
|
socket.close
|
||||||
|
socket = connect
|
||||||
|
when h["DELAY"]
|
||||||
|
delay = word[1].to_i
|
||||||
|
when h["SAY"]
|
||||||
|
if not word.length > 1
|
||||||
|
word.push("")
|
||||||
|
end
|
||||||
|
post(socket, word[1])
|
||||||
|
when h["RAW"]
|
||||||
|
begin
|
||||||
|
raw(socket, (msg.match(/\/?raw (.*)/i)[1]))
|
||||||
|
puts "raw message sent"
|
||||||
|
rescue
|
||||||
|
puts "didn't send that"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
post(socket, msg)
|
||||||
end
|
end
|
||||||
when h["RC"]
|
|
||||||
puts "reconnecting..."
|
|
||||||
socket.close
|
|
||||||
socket = connect
|
|
||||||
when h["DELAY"]
|
|
||||||
delay = word[1].to_i
|
|
||||||
when h["SAY"]
|
|
||||||
if not word.length > 1
|
|
||||||
word.push("")
|
|
||||||
end
|
|
||||||
post(socket, word[1])
|
|
||||||
else
|
else
|
||||||
post(socket, msg)
|
post(socket, msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user