Last active
April 6, 2018 12:11
-
-
Save znz/c8d70ed84c385e88adb275fdc915d170 to your computer and use it in GitHub Desktop.
JIS (IRCnet) <-> UTF-8 (IRC client) proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'nkf' | |
require 'socket' | |
Socket.tcp_server_loop(6668) do |socket, client_addr| | |
begin | |
begin | |
ircnet_socket = Socket.tcp('irc.ircnet.ne.jp', 6667) | |
loop do | |
rs, = IO.select([socket, ircnet_socket]) | |
break if rs.empty? | |
if rs.include?(ircnet_socket) | |
jis_line = ircnet_socket.gets | |
socket.puts NKF.nkf('-Jwxm0 --fb-xml', jis_line) | |
end | |
if rs.include?(socket) | |
utf8_line = socket.gets | |
ircnet_socket.puts NKF.nkf('-Wjxm0 --fb-xml', utf8_line) | |
end | |
end | |
rescue | |
p $! | |
ensure | |
ircnet_socket.close if ircnet_socket && !ircnet_socket.closed? | |
end | |
ensure | |
socket.close if !socket.closed? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
new generic version is https://github.com/znz/ansible-playbook-raspi201804/blob/master/provision/roles/matterbridge/files/nkf-proxy.rb