update ruby client

This commit is contained in:
Emil Williams 2024-02-17 18:55:24 +00:00
parent 4fb053fbe9
commit f742b9fc88

View File

@ -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,14 +89,15 @@ 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?
case h[word[0].upcase]
when h["BYE"] when h["BYE"]
post(socket, "BYE") post(socket, "BYE")
exit 0 exit 0
@ -110,6 +118,16 @@ def main
word.push("") word.push("")
end end
post(socket, word[1]) 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
else else
post(socket, msg) post(socket, msg)
end end