diff --git a/etc/failircd.yml b/etc/failircd.yml index 8fdec40..01dee64 100644 --- a/etc/failircd.yml +++ b/etc/failircd.yml @@ -33,6 +33,10 @@ modules: quit: "Quit: #{message}" kill: "Killed by #{sender.nick}: #{message.empty? ? 'No reason' : message}" + autotune: + minimum: 10 + rate: 10 + firewall: cloaking: @@ -52,8 +56,8 @@ modules: timeout: 5 length: 42 -# reupload: -# service: imageshack -# timeout: 30 -# matches: -# 4chan: images\.4chan\.org + reupload: + service: imageshack + timeout: 30 + matches: + 4chan: images\.4chan\.org diff --git a/lib/failirc/common/events/callback.rb b/lib/failirc/common/events/callback.rb index 714e63c..d814c27 100644 --- a/lib/failirc/common/events/callback.rb +++ b/lib/failirc/common/events/callback.rb @@ -32,7 +32,7 @@ def initialize (options={}, &block) end def <=> (value) - (options[:priority] || 0) <=> (value.options[:priority] || 0) + (value.options[:priority] || 0) <=> (options[:priority] || 0) end def call (*args, &block) diff --git a/lib/failirc/common/modules/module.rb b/lib/failirc/common/modules/module.rb index 9aba8d8..b6d2696 100644 --- a/lib/failirc/common/modules/module.rb +++ b/lib/failirc/common/modules/module.rb @@ -31,7 +31,7 @@ def self.for (what) return what.const_get(name) if what.const_defined?(name) } - scopes.first.const_get(name) + super end }.tap {|klass| klass.class_eval { diff --git a/lib/failirc/common/workers.rb b/lib/failirc/common/workers.rb index 7876e3a..805e7ee 100644 --- a/lib/failirc/common/workers.rb +++ b/lib/failirc/common/workers.rb @@ -22,7 +22,10 @@ module IRC class Workers - attr_reader :parent + extend Forwardable + + attr_reader :parent + def_delegators :@pool, :max, :max=, :min, :min= def initialize (parent, range = 2 .. 4) @parent = parent diff --git a/lib/failirc/server.rb b/lib/failirc/server.rb index 2bc3a6c..361623a 100644 --- a/lib/failirc/server.rb +++ b/lib/failirc/server.rb @@ -34,7 +34,7 @@ module IRC class Server extend Forwardable - attr_reader :options, :dispatcher, :created_on + attr_reader :options, :dispatcher, :workers, :created_on def_delegators :@dispatcher, :listen, :running? def_delegators :@events, :register, :dispatch, :observe, :fire, :hook diff --git a/lib/failirc/server/modules/autotune.rb b/lib/failirc/server/modules/autotune.rb new file mode 100644 index 0000000..bc9c8b6 --- /dev/null +++ b/lib/failirc/server/modules/autotune.rb @@ -0,0 +1,28 @@ +# failirc, a fail IRC library. +# +# Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org] +# +# This file is part of failirc. +# +# failirc is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# failirc is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with failirc. If not, see . + +version '0.0.1' + +on :connect do + server.workers.max = ((options[:minimum] || 10).to_i + server.clients.length / (options[:rate] || 10).to_i).to_i +end + +on :disconnect do + server.workers.max = ((options[:minimum] || 10).to_i + server.clients.length / (options[:rate] || 10).to_i).to_i +end diff --git a/lib/failirc/server/modules/base.rb b/lib/failirc/server/modules/base.rb index 3f6df3d..1f9c5a5 100644 --- a/lib/failirc/server/modules/base.rb +++ b/lib/failirc/server/modules/base.rb @@ -49,7 +49,7 @@ mod = self server.define_singleton_method name do - mod.instance_variable_get name + mod.instance_variable_get "@#{name}" end } @@ -768,7 +768,7 @@ def nick_is_ok? (thing, nick) if @channels[channel] channel = @channels[channel] else - channel = @channels[channel] = Channel.new(server, channel) + channel = @channels[channel] = Channel.new(server, ~channel) end if channel.modes.limit? @@ -1112,9 +1112,9 @@ def nick_is_ok? (thing, nick) from.send ERR_CHANOPRIVSNEEDED, channel else if channel.modes.anonymous? - channel.topic = Mask.new('anonymous', 'anonymous', 'anonymous.'), topic + channel.topic = Mask.new('anonymous', 'anonymous', 'anonymous.'), ~topic else - channel.topic = from, topic + channel.topic = from, ~topic end channel.send ":#{channel.topic.set_by} TOPIC #{channel} :#{channel.topic}" diff --git a/lib/failirc/server/modules/base/channel.rb b/lib/failirc/server/modules/base/channel.rb index 2efe597..e9cc143 100644 --- a/lib/failirc/server/modules/base/channel.rb +++ b/lib/failirc/server/modules/base/channel.rb @@ -157,7 +157,11 @@ def level (level) end def to_s - @name + name + end + + def inspect + "#" end end diff --git a/lib/failirc/server/modules/base/user.rb b/lib/failirc/server/modules/base/user.rb index f4d5e9a..ea6e16d 100644 --- a/lib/failirc/server/modules/base/user.rb +++ b/lib/failirc/server/modules/base/user.rb @@ -84,11 +84,11 @@ def can end def to_s - return "#{level}#{nick}" + "#{level}#{nick}" end def inspect - return "#" + "#" end end diff --git a/lib/failirc/server/modules/reupload.rb b/lib/failirc/server/modules/reupload.rb new file mode 100644 index 0000000..f9a666d --- /dev/null +++ b/lib/failirc/server/modules/reupload.rb @@ -0,0 +1,56 @@ +# failirc, a fail IRC library. +# +# Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org] +# +# This file is part of failirc. +# +# failirc is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# failirc is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with failirc. If not, see . + +require 'net/http' +require 'uri' + +version '0.0.1' + +def reupload (url, time=5, service=:imageshack) + result = url + + begin + case service + when :imageshack + result = timeout time do + response = Net::HTTP.get_response(URI.parse("http://imageshack.us/transload.php?url=#{URI.escape(url)}")) + Net::HTTP.get(URI.parse(response['location'])).match(%r{(.*?img.*?\..*?)})[1] rescue nil + end + end + rescue Timeout::Error + rescue Exception => e + IRC.debug e + + result = url + end + + return result || url +end + +on :message, priorty: -102 do |chain=:input, from, to, message| + return unless chain == :input + + message.scan(%r{https?://\S+}).uniq.each {|uri| + options[:matches].each {|name, regex| + next unless uri.match(/#{regex}/) + + message.gsub!(/#{Regexp.escape(uri)}/, "#{reupload(uri, (options[:timeout] || 5).to_f, (options[:service] || 'imageshack').to_sym)} (#{name})") + } + } +end diff --git a/lib/failirc/server/modules/shorten.rb b/lib/failirc/server/modules/shorten.rb index a329041..a582b33 100644 --- a/lib/failirc/server/modules/shorten.rb +++ b/lib/failirc/server/modules/shorten.rb @@ -41,7 +41,7 @@ class << self } end -on :message, priority: -100 do |chain=:input, from, to, message| +on :message, priority: 100 do |chain=:input, from, to, message| return unless chain == :output if to.modes.extended.tinyurl_preview