From 27177bb50c2d389e6fe53ae27a4db050e645ad4a Mon Sep 17 00:00:00 2001 From: Cool Fire Date: Wed, 28 Jun 2017 19:02:29 +0200 Subject: [PATCH] Add socketmessage plugin --- plugins/socketmessage.rb | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 plugins/socketmessage.rb diff --git a/plugins/socketmessage.rb b/plugins/socketmessage.rb new file mode 100644 index 0000000..7aef744 --- /dev/null +++ b/plugins/socketmessage.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +# Plugin to get +class Socketmessage + + require 'socket' + require 'json' + + # This method is called when the plugin is first loaded + def initialize( status, config, output, irc, timer ) + @status = status + @config = config + @output = output + @irc = irc + @timer = timer + + @server = TCPServer.open('localhost', 2000) + + t = Thread.new{ startserver } + end + + # Close server + def unload + @server.close + return true + end + + def help( nick, user, host, from, msg, arguments, con ) + line = 'This plugin gets messages from a local socket. No interactive commands available' + + if( con ) + @output.c( line + "\n" ) + else + @irc.notice( nick, line ) + end + end + + private + def startserver + loop do + client = @server.accept + input = JSON.parse client.gets + @irc.message( input['dest'], input['message'] ) + client.close + end + end +end -- GitLab