failirc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/bin/failbot +162 -0
  2. data/bin/failircd +61 -0
  3. data/lib/failirc.rb +25 -0
  4. data/lib/failirc/client.rb +227 -0
  5. data/lib/failirc/client/channel.rb +98 -0
  6. data/lib/failirc/client/channels.rb +85 -0
  7. data/lib/failirc/client/client.rb +59 -0
  8. data/lib/failirc/client/clients.rb +43 -0
  9. data/lib/failirc/client/dispatcher.rb +209 -0
  10. data/lib/failirc/client/dispatcher/connectiondispatcher.rb +410 -0
  11. data/lib/failirc/client/dispatcher/event.rb +113 -0
  12. data/lib/failirc/client/dispatcher/eventdispatcher.rb +203 -0
  13. data/lib/failirc/client/module.rb +103 -0
  14. data/lib/failirc/client/modules/Base.rb +361 -0
  15. data/lib/failirc/client/modules/Logger.rb +89 -0
  16. data/lib/failirc/client/server.rb +89 -0
  17. data/lib/failirc/client/user.rb +66 -0
  18. data/lib/failirc/client/users.rb +100 -0
  19. data/lib/failirc/errors.rb +339 -0
  20. data/lib/failirc/extensions.rb +124 -0
  21. data/lib/failirc/mask.rb +117 -0
  22. data/lib/failirc/modes.rb +54 -0
  23. data/lib/failirc/responses.rb +360 -0
  24. data/lib/failirc/server.rb +266 -0
  25. data/lib/failirc/server/channel.rb +122 -0
  26. data/lib/failirc/server/channels.rb +84 -0
  27. data/lib/failirc/server/client.rb +100 -0
  28. data/lib/failirc/server/clients.rb +54 -0
  29. data/lib/failirc/server/dispatcher.rb +219 -0
  30. data/lib/failirc/server/dispatcher/connectiondispatcher.rb +477 -0
  31. data/lib/failirc/server/dispatcher/event.rb +113 -0
  32. data/lib/failirc/server/dispatcher/eventdispatcher.rb +196 -0
  33. data/lib/failirc/server/link.rb +50 -0
  34. data/lib/failirc/server/links.rb +49 -0
  35. data/lib/failirc/server/module.rb +103 -0
  36. data/lib/failirc/server/modules/Base.rb +2545 -0
  37. data/lib/failirc/server/modules/Cloaking.rb +170 -0
  38. data/lib/failirc/server/modules/Firewall.rb +104 -0
  39. data/lib/failirc/server/modules/Netlog.rb +67 -0
  40. data/lib/failirc/server/modules/Roulette.rb +78 -0
  41. data/lib/failirc/server/modules/TinyURL.rb +98 -0
  42. data/lib/failirc/server/modules/Translate.rb +62 -0
  43. data/lib/failirc/server/modules/WordFilter.rb +144 -0
  44. data/lib/failirc/server/user.rb +72 -0
  45. data/lib/failirc/server/users.rb +103 -0
  46. data/lib/failirc/sslutils.rb +74 -0
  47. data/lib/failirc/utils.rb +53 -0
  48. metadata +107 -0
@@ -0,0 +1,113 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module IRC
21
+
22
+ class Server
23
+
24
+ class Dispatcher
25
+
26
+ class Event
27
+ class Callback
28
+ attr_reader :method
29
+ attr_accessor :priority
30
+
31
+ def initialize (method, priority=0)
32
+ @method = method
33
+ @priority = priority
34
+ end
35
+
36
+ def call (*args)
37
+ return @method.call(*args)
38
+ end
39
+ end
40
+
41
+ attr_reader :types, :chain, :aliases, :dispatcher, :thing, :string
42
+ attr_accessor :special
43
+
44
+ def initialize (dispatcher, chain, thing, string)
45
+ @dispatcher = dispatcher
46
+ @chain = chain
47
+ @thing = thing
48
+ @string = string
49
+ @types = Event.types(dispatcher, chain, string)
50
+ @aliases = Event.aliases(dispatcher, chain, types)
51
+ @callbacks = Event.callbacks(dispatcher, chain, types)
52
+ end
53
+
54
+ def callbacks
55
+ if @callbacks
56
+ return @callbacks
57
+ else
58
+ tmp = Event.callbacks(@dispatcher, @chain, @type)
59
+
60
+ if tmp
61
+ return @callbacks = tmp
62
+ else
63
+ return []
64
+ end
65
+ end
66
+ end
67
+
68
+ def self.types (dispatcher, chain, string)
69
+ types = []
70
+
71
+ dispatcher.events[chain].each_key {|key|
72
+ if key.class == Regexp && key.match(string)
73
+ types.push key
74
+ end
75
+ }
76
+
77
+ return types
78
+ end
79
+
80
+ def self.aliases (dispatcher, chain, types)
81
+ aliases = []
82
+
83
+ dispatcher.aliases[chain].each {|key, value|
84
+ if types.include?(value)
85
+ aliases.push key
86
+ end
87
+ }
88
+
89
+ return aliases
90
+ end
91
+
92
+ def self.callbacks (dispatcher, chain, types)
93
+ callbacks = []
94
+
95
+ if chain == :pre || chain == :post || chain == :default
96
+ callbacks.insert(-1, *dispatcher.events[chain])
97
+ else
98
+ types.each {|type|
99
+ callbacks.insert(-1, *dispatcher.events[chain][type])
100
+ }
101
+ end
102
+
103
+ return callbacks
104
+ end
105
+ end
106
+
107
+ end
108
+
109
+ Event = Dispatcher::Event
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,196 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/utils'
21
+ require 'failirc/server/dispatcher/event'
22
+
23
+ module IRC
24
+
25
+ class Server
26
+
27
+ class Dispatcher
28
+
29
+ class EventDispatcher
30
+ attr_reader :server, :dispatcher, :handling, :aliases, :events
31
+
32
+ def initialize (dispatcher)
33
+ @server = dispatcher.server
34
+ @dispatcher = dispatcher
35
+ @handling = ThreadSafeHash.new
36
+
37
+ @aliases = {
38
+ :input => {},
39
+ :output => {},
40
+ }
41
+
42
+ @events = {
43
+ :pre => [],
44
+ :post => [],
45
+ :default => [],
46
+
47
+ :custom => {},
48
+
49
+ :input => {},
50
+ :output => {},
51
+ }
52
+ end
53
+
54
+ def handle (what, chain, deep, thing)
55
+ if chain != :input || deep
56
+ return
57
+ end
58
+
59
+ if what == :start
60
+ @handling[thing.socket] = true
61
+ else
62
+ @handling.delete(thing.socket)
63
+ end
64
+ end
65
+
66
+ def dispatch (chain, thing, string, deep=false)
67
+ if !thing
68
+ return
69
+ end
70
+
71
+ handle(:start, chain, deep, thing)
72
+
73
+ event = Event.new(self, chain, thing, string)
74
+ result = string
75
+
76
+ @events[:pre].each {|callback|
77
+ event.special = :pre
78
+
79
+ if callback.call(event, thing, string) == false
80
+ handle(:stop, chain, deep, thing)
81
+ return false
82
+ end
83
+ }
84
+
85
+ if !event.types.empty?
86
+ event.special = nil
87
+
88
+ event.callbacks.each {|callback|
89
+ begin
90
+ if callback.call(thing, string) == false
91
+ handle(:stop, chain, deep, thing)
92
+ return false
93
+ end
94
+ rescue Exception => e
95
+ self.debug e
96
+ end
97
+ }
98
+ elsif chain == :input
99
+ @events[:default].each {|callback|
100
+ event.special = :default
101
+
102
+ if callback.call(event, thing, string) == false
103
+ handle(:stop, chain, deep, thing)
104
+ return false
105
+ end
106
+ }
107
+ end
108
+
109
+ @events[:post].each {|callback|
110
+ event.special = :post
111
+
112
+ if callback.call(event, thing, string) == false
113
+ handle(:stop, chain, deep, thing)
114
+ return false
115
+ end
116
+ }
117
+
118
+ handle(:stop, chain, deep, thing)
119
+
120
+ return result
121
+ end
122
+
123
+ def execute (event, *args)
124
+ if @events[:custom][event]
125
+ @events[:custom][event].each {|callback|
126
+ begin
127
+ if callback.method.call(*args) == false
128
+ return false
129
+ end
130
+ rescue Exception => e
131
+ self.debug e
132
+ end
133
+ }
134
+ end
135
+ end
136
+
137
+ def alias (chain, symbol, regex)
138
+ if !regex
139
+ @aliases[chain].delete(symbol)
140
+ elsif !regex.class == Regexp
141
+ raise 'You have to alias to a Regexp.'
142
+ else
143
+ @aliases[chain][symbol] = regex
144
+ end
145
+ end
146
+
147
+ def register (chain, type, callback, priority=0)
148
+ if !type
149
+ events = @events[chain]
150
+
151
+ if !events
152
+ events = @events[chain] = []
153
+ end
154
+ else
155
+ if @aliases[chain]
156
+ if @aliases[chain][type]
157
+ type = @aliases[chain][type]
158
+ end
159
+ end
160
+
161
+ if !@events[chain]
162
+ @events[chain] = {}
163
+ end
164
+
165
+ events = @events[chain][type]
166
+
167
+ if !events
168
+ events = @events[chain][type] = []
169
+ end
170
+ end
171
+
172
+ if !callback
173
+ events.clear
174
+ elsif callback.is_a?(Array)
175
+ callback.each {|callback|
176
+ register(chain, type, callback)
177
+ }
178
+ else
179
+ if callback.is_a?(Event::Callback)
180
+ events.push(callback)
181
+ else
182
+ events.push(Event::Callback.new(callback, priority))
183
+ end
184
+ end
185
+
186
+ events.sort! {|a, b|
187
+ a.priority <=> b.priority
188
+ }
189
+ end
190
+ end
191
+
192
+ end
193
+
194
+ end
195
+
196
+ end
@@ -0,0 +1,50 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/utils'
21
+
22
+ module IRC
23
+
24
+ class Server
25
+
26
+ class Link
27
+ attr_reader :server, :socket, :listen, :host
28
+
29
+ def initialize (server, socket, listen)
30
+ @server = server
31
+ @socket = socket
32
+ @listen = listen
33
+ end
34
+
35
+ def raw (text)
36
+ @socket.puts text
37
+ end
38
+
39
+ def send (type, *args)
40
+ callback = @@callbacks[type]
41
+ callback(args)
42
+ end
43
+
44
+ @@callbacks = {
45
+ }
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,49 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/extensions'
21
+ require 'failirc/server/link'
22
+
23
+ module IRC
24
+
25
+ class Server
26
+
27
+ class Links < ThreadSafeHash
28
+ attr_reader :server
29
+
30
+ def initialize (server)
31
+ @server = server
32
+
33
+ super()
34
+ end
35
+
36
+ def inspect
37
+ result = ""
38
+
39
+ each {|link|
40
+ result << " #{link.inspect}"
41
+ }
42
+
43
+ return result[1, result.length]
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,103 @@
1
+ # failirc, a fail IRC library.
2
+ #
3
+ # Copyleft meh. [http://meh.doesntexist.org | meh.ffff@gmail.com]
4
+ #
5
+ # This file is part of failirc.
6
+ #
7
+ # failirc is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # failirc is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with failirc. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'failirc/utils'
21
+
22
+ module IRC
23
+
24
+ class Server
25
+
26
+ class Module
27
+ attr_reader :server
28
+
29
+ def initialize (server)
30
+ @server = server
31
+
32
+ if @aliases
33
+ if @aliases[:input]
34
+ @aliases[:input].each {|key, value|
35
+ @server.dispatcher.alias(:input, key, value)
36
+ }
37
+ end
38
+
39
+ if @aliases[:output]
40
+ @aliases[:output].each {|key, value|
41
+ @server.dispatcher.alias(:output, key, value)
42
+ }
43
+ end
44
+ end
45
+
46
+ if @events
47
+ if @events[:pre]
48
+ @server.dispatcher.register(:pre, nil, @events[:pre])
49
+ end
50
+
51
+ if @events[:post]
52
+ @server.dispatcher.register(:post, nil, @events[:post])
53
+ end
54
+
55
+ if @events[:default]
56
+ @server.dispatcher.register(:default, nil, @events[:default])
57
+ end
58
+
59
+ if @events[:custom]
60
+ @events[:custom].each {|key, value|
61
+ @server.dispatcher.register(:custom, key, value)
62
+ }
63
+ end
64
+
65
+ if @events[:input]
66
+ @events[:input].each {|key, value|
67
+ @server.dispatcher.register(:input, key, value)
68
+ }
69
+ end
70
+
71
+ if @events[:output]
72
+ @events[:output].each {|key, value|
73
+ @server.dispatcher.register(:output, key, value)
74
+ }
75
+ end
76
+ end
77
+
78
+ begin
79
+ rehash
80
+ rescue NameError
81
+ rescue Exception => e
82
+ self.debug e
83
+ end
84
+ end
85
+
86
+ def finalize
87
+ if @aliases
88
+ @aliases.each_key {|key|
89
+ @server.dispatcher.alias(key, nil)
90
+ }
91
+ end
92
+
93
+ if @events
94
+ @events.each_key {|key|
95
+ @server.dispatcher.register(key, nil)
96
+ }
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+ end