Skip to content

Commit

Permalink
use a message queue
Browse files Browse the repository at this point in the history
  • Loading branch information
aktowns committed Jan 20, 2012
1 parent c34a348 commit 6a0c07b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config.yml
Expand Up @@ -21,6 +21,8 @@ Plugins:
Update: core
- Plugin: youtubeurls-plugin
Update: core
- Plugin: twitter-plugin
Update: core
# - Plugin: ey-plugin
# Update: core
# Settings:
Expand Down
15 changes: 13 additions & 2 deletions mirai/core.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions mirai/plugin.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions mirai/pluginhandler.rb
Expand Up @@ -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) }
Expand Down

0 comments on commit 6a0c07b

Please sign in to comment.