diff --git a/config.yml b/config.yml index 5ff96cd..a08e005 100644 --- a/config.yml +++ b/config.yml @@ -21,6 +21,8 @@ Plugins: Update: core - Plugin: youtubeurls-plugin Update: core + - Plugin: twitter-plugin + Update: core # - Plugin: ey-plugin # Update: core # Settings: diff --git a/mirai/core.rb b/mirai/core.rb index 6056bb3..dfe267c 100644 --- a/mirai/core.rb +++ b/mirai/core.rb @@ -4,12 +4,22 @@ def initialize config, servername, eventmachine, webserver @config, @servername, @em, @webserver = config, servername, eventmachine, webserver @handlers = {} puts "Core initialized for #{servername}".blue + + @sendQ = [] end def on_connect rawsend "PASS #{@config.password(@servername)}" if !@config.password(@servername).nil? rawsend "NICK #{@config.nick}" rawsend "USER #{@config.user} mirai * 0 :#{@config.fullname}" + + EventMachine::PeriodicTimer.new(1) do + if @sendQ.length > 0 + msg = @sendQ.pop + @em.send_data "#{msg}\r\n" + puts "#{msg}".yellow + end + end end def on_data data @@ -80,8 +90,9 @@ def unregister_web_handler handler private def rawsend data - @em.send_data data + "\r\n" - puts "#{data}".yellow + @sendQ << data + #@em.send_data data + "\r\n" + #puts "#{data}".yellow end def privmsg target, message diff --git a/mirai/plugin.rb b/mirai/plugin.rb index bfb405e..3f87f07 100644 --- a/mirai/plugin.rb +++ b/mirai/plugin.rb @@ -2,6 +2,16 @@ module Mirai class Plugin def initialize config, em, servername, pluginname, handler, settings @em, @config, @servername, @pluginname, @handler, @settings = em, config, servername, pluginname, handler, settings + + @sendQ = [] + + EventMachine::PeriodicTimer.new(1) do + if @sendQ.length > 0 + msg = @sendQ.pop + @em.send_data "#{msg}\r\n" + puts "[#{@pluginname}] #{msg}".magenta + end + end end def inspect @@ -12,8 +22,9 @@ def inspect private def rawsend raw - puts "[#{@pluginname}] #{raw}".magenta - @em.send_data "#{raw}\r\n" + # puts "[#{@pluginname}] #{raw}".magenta + # @em.send_data "#{raw}\r\n" + @sendQ << raw end def privmsg channel, message diff --git a/mirai/pluginhandler.rb b/mirai/pluginhandler.rb index fd1f7af..9627115 100644 --- a/mirai/pluginhandler.rb +++ b/mirai/pluginhandler.rb @@ -12,6 +12,7 @@ def initialize config, servername, em, core next if plugin["Update"] != "core" name = plugin["Plugin"] metadatalocation = "plugins/#{name}/" + throw "Plugin is undefined" if name.nil? || name.strip == "" throw "Plugin #{name} does not exist in #{metadatalocation}/#{name}.yml" if !File.exist?("#{metadatalocation}/#{name}.yml") pluginmeta = File.open("#{metadatalocation}/#{name}.yml", 'r') {|fp| YAML::load(fp.read) }