# frozen_string_literal: true class LiveFeedBot def initialize @semafor = Mutex.new @config = Booru::CONFIG.livefeed @redis = Redis.new(host: 'localhost', driver: :hiredis) @sock = nil @ok_send = false @subscriber = Thread.new do @redis.subscribe 'modfeed' do |on| on.message do |_channel, message| putirc "PRIVMSG #{@config[:channels][:modfeed]} :#{message}" if @ok_send end end end end def run_irc_conn @sock = TCPSocket.new( @config[:irc_host], @config[:irc_port] ) @ok_send = false putirc "NICK #{@config[:irc_nick]}" putirc "USER #{@config[:irc_user]} * * :#{@config[:irc_real]}" while line = @sock.gets line.chomp! puts "irc >>> #{line}" split = line.split(' ') if split[0] == 'PING' putirc "PONG #{split[1..].join(' ')}" elsif split[1] == '376' putirc "JOIN #{@config[:channels][:modfeed]}" @ok_send = true end end rescue @sock = nil end private def open_irc_conn(proxy) end def putirc(line) return unless @sock @semafor.synchronize do @sock.puts line puts "irc <<< #{line}" end end end