Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add various modules.

  • Loading branch information...
commit e0bac0cf5e915c46727b72fd759d34a4ada15deb 1 parent 8335f7d
@meh authored
View
2  bin/failircd
@@ -48,7 +48,7 @@ args.each {|option, value|
end
}
-ircd = IRC::Server.new(YAML.parse_file(options[:config]).transform)
+ircd = IRC::Server.new(options[:config])
[:INT, :KILL].each {|sig|
trap sig.to_s do
View
26 etc/failircd.yml
@@ -35,23 +35,25 @@ modules:
firewall:
- tinyurl:
- timeout: 5
- length: 42
-
cloaking:
keys:
- jsdhfjhsdjfhjsadhf8829348h98ashd9uasd
- 23895yu9134h 9uhs9aduhf9ashd f2 99urhsaj
- 938jhrfjsadnlbkdsfgkj
- autojoin:
- channel: "#lol"
+ autojoin: "#lol"
- netlog:
+# wordfilter:
+# filters:
+# netlog:
+
+ shorten:
+ service: isgd
+ timeout: 5
+ length: 42
- reupload:
- timeout: 30
- service: imageshack
- sites:
- 4chan: images\.4chan\.org
+# reupload:
+# service: imageshack
+# timeout: 30
+# matches:
+# 4chan: images\.4chan\.org
View
12 lib/failirc/common/events/callback.rb
@@ -20,18 +20,20 @@
module IRC; class Events
class Callback
+ include Comparable
+
attr_reader :method, :options
def initialize (options={}, &block)
@block = block
@options = options
+
+ raise ArgumentError, 'options has to be a Hash' unless @options.is_a?(Hash)
end
- [:priority].each {|name|
- define_method name do
- @options[name]
- end
- }
+ def <=> (value)
+ (options[:priority] || 0) <=> (value.options[:priority] || 0)
+ end
def call (*args, &block)
begin
View
4 lib/failirc/common/events/event.rb
@@ -27,9 +27,7 @@ def initialize (owner, chain, callbacks=[], aliases=[])
@chain = chain
@aliases = aliases
- @callbacks = callbacks.sort {|a, b|
- a.priority <=> b.priority
- }
+ @callbacks = callbacks.sort
end
def on (thing, string)
View
5 lib/failirc/common/modes.rb
@@ -42,8 +42,11 @@ def self.define (&block)
}
end
+ attr_reader :extended
+
def initialize (data=nil)
- @modes = HashWithIndifferentAccess.new
+ @modes = HashWithIndifferentAccess.new
+ @extended = InsensitiveStruct.new
if data.is_a?(Modes)
@modes.merge!(data.to_hash)
View
10 lib/failirc/common/modules.rb
@@ -21,18 +21,18 @@
module IRC
-class Modules
- attr_reader :owner, :list
+class Modules < Array
+ attr_reader :owner, :module
def initialize (owner, path)
@owner = owner
@path = path
- @list = []
+ @module = Module.for(@owner)
end
def load (name, options={})
- mod = Module.for(@owner).new(options)
+ mod = @module.new(name, options)
$:.each {|path|
path = "#{path}/#{@path}/#{name}.rb"
@@ -41,7 +41,7 @@ def load (name, options={})
begin
mod.instance_eval(File.read(path), File.realpath(path), 1)
- return @list.push(mod).last
+ return push(mod).last
rescue Exception => e
IRC.debug e
View
17 lib/failirc/common/modules/module.rb
@@ -19,7 +19,7 @@
require 'failirc/common/events'
-module IRC; class Modules
+module IRC; class Modules < Array
class Module
def self.for (what)
@@ -44,15 +44,24 @@ def self.for (what)
include Events::DSL
- attr_reader :options
+ attr_reader :name, :options
- def initialize (options={})
+ def initialize (name, options={})
+ @name = name
@options = options
Events::DSL.initialize(self)
end
- [:name, :version, :identifier].each {|var|
+ def rehash (options=nil, &block)
+ if block
+ @rehash = block
+ else
+ @rehash.call(options) if @rehash
+ end
+ end
+
+ [:version, :identifier].each {|var|
data = {}
define_method var do |*args|
View
38 lib/failirc/server.rb
@@ -42,8 +42,6 @@ class Server
def_delegators :@modules, :load
def initialize (options={})
- @options = HashWithIndifferentAccess.new(options)
-
@created_on = Time.new
@dispatcher = Dispatcher.new(self)
@@ -51,23 +49,26 @@ def initialize (options={})
@workers = Workers.new(self)
@modules = Modules.new(self, '/failirc/server/modules')
- if (@options[:server][:listen] rescue nil)
- @options[:server][:listen].each {|data|
- listen(data)
- }
+ if options.is_a?(Hash)
+ @options = HashWithIndifferentAccess.new(options)
+ else
+ @path = options
+ rehash
end
+ server = self
+ @modules.module.class_eval {
+ define_method :server do
+ server
+ end
+ }
+
if @options[:modules]
@options[:modules].each {|name, data|
begin
mod = @modules.load(name, data || {})
if mod
- server = self
- mod.define_singleton_method :server do
- server
- end
-
hook mod
IRC.debug "#{name} loaded"
@@ -79,6 +80,21 @@ def initialize (options={})
end
}
end
+
+ if (@options[:server][:listen] rescue nil)
+ @options[:server][:listen].each {|data|
+ listen(data)
+ }
+ end
+ end
+
+ def rehash
+ old, @options = @options, HashWithIndifferentAccess.new(YAML.parse_file(@path).transform)
+
+ @modules.each {|mod|
+ mod.options.clear.merge!(@options[:modules][mod.name])
+ mod.rehash((old[:modules][mod.name] rescue nil))
+ }
end
def start
View
26 lib/failirc/server/modules/autojoin.rb
@@ -0,0 +1,26 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+version '0.0.1'
+
+on :connected do |client|
+ [options].flatten.compact.each {|channel|
+ server.fire :join, client, channel
+ }
+end
View
21 lib/failirc/server/modules/base.rb
@@ -32,7 +32,6 @@
extend Base
-name 'base'
version '0.1.0'
identifier 'RFC 1460, 2810, 2811, 2812, 2813;'
@@ -47,8 +46,10 @@
@servers = {}
[:clients, :servers, :channels].each {|name|
+ mod = self
+
server.define_singleton_method name do
- instance_variable_get name
+ mod.instance_variable_get name
end
}
@@ -750,6 +751,8 @@ def nick_is_ok? (thing, nick)
end
observe :join do |thing, channel, password=nil|
+ return unless thing.client?
+
@mutex.synchronize {
if !channel.channel_type
channel = "##{channel}"
@@ -822,13 +825,15 @@ def nick_is_ok? (thing, nick)
mask = user.mask
end
- user.channel.send ":#{mask} JOIN :#{user.channel.to_s}"
+ debugger
+
+ user.channel.send ":#{mask} JOIN :#{user.channel}"
if !user.channel.topic.nil?
- server.dispatch user.client, "TOPIC #{user.channel.to_s}"
+ server.dispatch user.client, "TOPIC #{user.channel}"
end
- server.dispatch user.client, "NAMES #{user.channel.to_s}"
+ server.dispatch user.client, "NAMES #{user.channel}"
end
on :part do |thing, string|
@@ -866,7 +871,7 @@ def nick_is_ok? (thing, nick)
mask = user.mask
end
- user.channel.send ":#{mask} PART #{user.channel.to_s} :#{text}"
+ user.channel.send ":#{mask} PART #{user.channel} :#{text}"
@mutex.synchronize {
user.channel.delete(user)
@@ -1070,7 +1075,7 @@ def nick_is_ok? (thing, nick)
users: users
end
- thing.send RPL_ENDOFNAMES, channel.to_s
+ thing.send RPL_ENDOFNAMES, channel
end
on :topic do |thing, string|
@@ -1114,7 +1119,7 @@ def nick_is_ok? (thing, nick)
channel.topic = from, topic
end
- channel.send ":#{channel.topic.set_by} TOPIC #{channel} :#{channel.topic.to_s}"
+ channel.send ":#{channel.topic.set_by} TOPIC #{channel} :#{channel.topic}"
end
end
View
4 lib/failirc/server/modules/base/channel.rb
@@ -162,10 +162,6 @@ def level (level)
def to_s
@name
end
-
- def inspect
- to_s
- end
end
end; end; end
View
2  lib/failirc/server/modules/base/user/can.rb
@@ -25,7 +25,7 @@ def initialize (user)
end
def method_missing (*args, &block)
- @user.modes.can.send(*args, &block) || @user.client.modes.can(*args, &block)
+ @user.modes.can.send(*args, &block) || @user.client.modes.can.send(*args, &block)
end
end
View
1  lib/failirc/server/modules/firewall.rb
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
-name 'firewall'
version '0.0.1'
on :start do
View
43 lib/failirc/server/modules/shorten.rb
@@ -0,0 +1,43 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+require 'timeout'
+require 'shortie'
+
+version '0.0.1'
+
+on :message, priority: -100 do |chain=:input, from, to, message|
+ return unless chain == :input
+
+ message.scan(%r{https?://\S+}).each {|uri|
+ next if uri.length <= (options[:length] ? options[:length].to_i : 42)
+
+ begin timeout(options[:timeout] ? options[:timeout].to_f : 5) {
+ message.gsub!(/#{Regexp.escape(uri)}/, Shortie::Service.find_by_key(options[:service]).shorten(uri))
+ } rescue Timeout::Error end
+ }
+end
+
+on :message, priority: -100 do |chain=:input, from, to, message|
+ return unless chain == :output
+
+ if to.modes.extended.tinyurl_preview
+ message.gsub!('http://tinyurl.com', 'http://preview.tinyurl.com')
+ end
+end
View
25 lib/failirc/server/modules/wordfilter.rb
@@ -0,0 +1,25 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+name 'wordfilter'
+version '0.0.1'
+
+on :message, priority: -1 do |chain=:input, from, to, message|
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.