All pastes #213114 Raw Edit

Anonymous

public text v1 · immutable
#213114 ·published 2006-10-21 06:24 UTC
rendered paste body
require 'open3'

class MetaPlugin < XChatRuby::XChatRubyPlugin
    include XChatRuby

    def initialize
        hook_command('HOOKCMD', XCHAT_PRI_NORM, method(:hookcmd), '')
    end

    def hookcmd(words, words_eol, data)
        words.shift
        if words.length != 2
            puts 'Usage: HOOKCMD <cmdname> <program>'
        else
            cmdname, program = words

            func = lambda do |words, words_eol, data|
                words.shift
                stdin, stdout, stderr = Open3.popen3(program, *words)
                while line = stdout.gets
                    line.chomp!
                    if line
                        command(line)
                    end
                end

                XCHAT_EAT_ALL
            end

            hook_command(cmdname.upcase, XCHAT_PRI_NORM, func, '')
        end

        return XCHAT_EAT_ALL
    end
end