miu-irc 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +7 -3
- data/lib/miu-irc.rb +1 -5
- data/lib/miu/nodes/irc.rb +6 -0
- data/lib/miu/nodes/irc/client.rb +95 -0
- data/lib/miu/nodes/irc/connection.rb +83 -0
- data/lib/miu/nodes/irc/node.rb +75 -0
- data/lib/miu/nodes/irc/publisher.rb +20 -0
- data/lib/miu/nodes/irc/subscriber.rb +45 -0
- data/lib/miu/nodes/irc/version.rb +7 -0
- data/miu-irc.gemspec +7 -6
- metadata +44 -42
- data/lib/miu-irc/connection.rb +0 -92
- data/lib/miu-irc/version.rb +0 -5
- data/lib/miu/plugins/irc.rb +0 -127
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: afbf8d374be8d7fd2583538fe2fc791b41ae9538
|
|
4
|
+
data.tar.gz: 0b2fde222cb446b126f54839eaf9ce7be632d5e1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8883d235a562ed3dbdb0a54faf9cdd7798f4bc0d951efd4cec74385d7213cfbff1dc4ab9fe68f0dd15eb3f4ddcb044977bd62b54b9b14498a6cb408ee39781d8
|
|
7
|
+
data.tar.gz: 005cb785d8bfa83b77962d5c71f60857aaf732e92a41e79cc5ee5217da0abad1f06bcbdfc5d7ea84ea93b2bc43ef75ecd94e7a1b828e4653f78769882e736fdf
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Miu::IRC
|
|
1
|
+
# Miu::Nodes::IRC
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
IRC node for Miu
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -18,7 +18,11 @@ Or install it yourself as:
|
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
```ruby
|
|
22
|
+
miu irc init
|
|
23
|
+
vim config/miu.god # edit your settings
|
|
24
|
+
miu supervise
|
|
25
|
+
```
|
|
22
26
|
|
|
23
27
|
## Contributing
|
|
24
28
|
|
data/lib/miu-irc.rb
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'miu/nodes/irc/connection'
|
|
2
|
+
require 'miu/nodes/irc/publisher'
|
|
3
|
+
require 'miu/nodes/irc/subscriber'
|
|
4
|
+
|
|
5
|
+
module Miu
|
|
6
|
+
module Nodes
|
|
7
|
+
module IRC
|
|
8
|
+
class Client < Connection
|
|
9
|
+
attr_reader :channels
|
|
10
|
+
attr_reader :node, :publisher, :subscriber
|
|
11
|
+
|
|
12
|
+
def initialize(node, options)
|
|
13
|
+
super options
|
|
14
|
+
@node = node
|
|
15
|
+
@channels = Array(options[:channels])
|
|
16
|
+
@publisher = Publisher.new @node.options['pub-host'], @node.options['pub-port'], @node.options['pub-tag']
|
|
17
|
+
@subscriber = Subscriber.new @node.options['sub-host'], @node.options['sub-port'], @node.options['sub-tag']
|
|
18
|
+
|
|
19
|
+
async.run
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def close
|
|
23
|
+
@publisher.close
|
|
24
|
+
@subscriber.close
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def on_376(msg)
|
|
29
|
+
@channels.each do |channel|
|
|
30
|
+
send_message 'JOIN', *channel.split(/ +/)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
@subscriber.async.run self
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def on_ping(msg)
|
|
37
|
+
send_message 'PONG', msg.params[0]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def on_privmsg(msg)
|
|
41
|
+
publish_text msg, false
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def on_notice(msg)
|
|
45
|
+
publish_text msg, true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def on_join(msg)
|
|
49
|
+
channels = msg.params[0].split(',') rescue []
|
|
50
|
+
channels.each do |channel|
|
|
51
|
+
publish Miu::Messages::Enter do |c|
|
|
52
|
+
c.room.name = channel
|
|
53
|
+
c.user.name = to_name(msg)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def on_part(msg)
|
|
59
|
+
channels = msg.params[0].split(',') rescue []
|
|
60
|
+
channels.each do |channel|
|
|
61
|
+
publish Miu::Messages::Leave do |c|
|
|
62
|
+
c.room.name = channel
|
|
63
|
+
c.user.name = to_name(msg)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def to_name(msg)
|
|
71
|
+
msg.prefix.nick || msg.prefix.servername
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def publish_text(msg, notice)
|
|
75
|
+
publish Miu::Messages::Text do |c|
|
|
76
|
+
c.room.name = msg.params[0]
|
|
77
|
+
c.user.name = to_name(msg)
|
|
78
|
+
c.text = msg.params[1]
|
|
79
|
+
c.meta = {
|
|
80
|
+
:notice => notice
|
|
81
|
+
}
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def publish(type)
|
|
86
|
+
msg = type.new do |m|
|
|
87
|
+
m.network.name = @node.options[:network]
|
|
88
|
+
yield m.content
|
|
89
|
+
end
|
|
90
|
+
@publisher.write msg
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'celluloid/io'
|
|
2
|
+
require 'ircp'
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
|
|
5
|
+
module Miu
|
|
6
|
+
module Nodes
|
|
7
|
+
module IRC
|
|
8
|
+
class Connection
|
|
9
|
+
include Celluloid::IO
|
|
10
|
+
|
|
11
|
+
BUFFER_SIZE = 1024 * 4
|
|
12
|
+
|
|
13
|
+
attr_reader :host, :port
|
|
14
|
+
attr_reader :nick, :user, :real, :pass
|
|
15
|
+
attr_reader :encoding
|
|
16
|
+
attr_reader :socket
|
|
17
|
+
|
|
18
|
+
def initialize(options)
|
|
19
|
+
@host = options[:host]
|
|
20
|
+
@port = options[:port] || 6667
|
|
21
|
+
@nick = options[:nick]
|
|
22
|
+
@user = options[:user] || @nick
|
|
23
|
+
@real = options[:real] || @nick
|
|
24
|
+
@pass = options[:pass]
|
|
25
|
+
@encoding = options[:encoding] || 'UTF-8'
|
|
26
|
+
|
|
27
|
+
@socket = TCPSocket.new @host, @port
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def close
|
|
31
|
+
@socket.close if @socket && !@socket.closed?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def send_message(*args)
|
|
35
|
+
msg = Ircp::Message.new(*args)
|
|
36
|
+
Miu::Logger.debug "<< #{msg.to_s.strip}"
|
|
37
|
+
@socket.write msg.to_irc
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def run
|
|
41
|
+
attach
|
|
42
|
+
readlines do |data|
|
|
43
|
+
msg = Ircp.parse data rescue nil
|
|
44
|
+
if msg
|
|
45
|
+
Miu::Logger.debug ">> #{msg.to_s.strip}"
|
|
46
|
+
on_message msg
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def readlines(buffer_size = BUFFER_SIZE, &block)
|
|
52
|
+
readbuf = ''.force_encoding('ASCII-8BIT')
|
|
53
|
+
loop do
|
|
54
|
+
readbuf << @socket.readpartial(buffer_size).force_encoding('ASCII-8BIT')
|
|
55
|
+
while data = readbuf.slice!(/.+\r\n/)
|
|
56
|
+
block.call encode(data, @encoding)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def encode(str, encoding)
|
|
62
|
+
str.force_encoding(encoding).encode!(:invalid => :replace, :undef => :replace)
|
|
63
|
+
str.chars.select { |c| c.valid_encoding? }.join
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def attach
|
|
67
|
+
send_message 'PASS', @pass if @pass
|
|
68
|
+
send_message 'NICK', @nick
|
|
69
|
+
send_message 'USER', @user, '*', '*', @real
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def on_message(msg)
|
|
73
|
+
begin
|
|
74
|
+
method = "on_#{msg.command.to_s.downcase}"
|
|
75
|
+
__send__ method, msg if respond_to? method
|
|
76
|
+
rescue => e
|
|
77
|
+
Miu::Logger.exception e
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'miu/nodes/irc/client'
|
|
2
|
+
|
|
3
|
+
module Miu
|
|
4
|
+
module Nodes
|
|
5
|
+
module IRC
|
|
6
|
+
class Node
|
|
7
|
+
include Miu::Node
|
|
8
|
+
description 'IRC node for miu'
|
|
9
|
+
|
|
10
|
+
attr_reader :options
|
|
11
|
+
|
|
12
|
+
def initialize(options)
|
|
13
|
+
@options = options
|
|
14
|
+
|
|
15
|
+
Miu::Logger.info "Options:"
|
|
16
|
+
@options.each do |k, v|
|
|
17
|
+
Miu::Logger.info " #{k}: #{v}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@client = Client.new(self, {
|
|
21
|
+
:host => options[:host], :port => options[:port],
|
|
22
|
+
:nick => options[:nick], :user => options[:user], :real => options[:real],
|
|
23
|
+
:pass => options[:pass],
|
|
24
|
+
:channels => options[:channels],
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
[:INT, :TERM].each do |sig|
|
|
28
|
+
trap(sig) { exit }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
sleep
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def shutdown
|
|
37
|
+
@client.close
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
register :irc do
|
|
41
|
+
desc 'start', %(Start miu-irc node)
|
|
42
|
+
option 'host', :type => :string, :desc => 'irc host', :required => true, :aliases => '-a'
|
|
43
|
+
option 'port', :type => :numeric, :default => 6667, :desc => 'irc port', :aliases => '-p'
|
|
44
|
+
option 'nick', :type => :string, :desc => 'irc nick', :required => true, :aliases => '-n'
|
|
45
|
+
option 'user', :type => :string, :desc => 'irc user'
|
|
46
|
+
option 'real', :type => :string, :desc => 'irc real'
|
|
47
|
+
option 'pass', :type => :string, :desc => 'irc pass'
|
|
48
|
+
option 'encoding', :type => :string, :default => 'utf-8', :desc => 'irc encoding'
|
|
49
|
+
option 'channels', :type => :array, :default => [], :desc => 'irc join channels', :banner => %('#channel1 password' '#channel2')
|
|
50
|
+
option 'network', :type => :string, :default => 'irc', :desc => 'network name'
|
|
51
|
+
add_miu_pub_options 'miu.input.irc.'
|
|
52
|
+
add_miu_sub_options 'miu.output.irc.'
|
|
53
|
+
def start
|
|
54
|
+
Node.new options
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
desc 'init', %(Generates a miu-irc configurations)
|
|
58
|
+
def init
|
|
59
|
+
config <<-EOS
|
|
60
|
+
Miu.watch 'irc' do |w|
|
|
61
|
+
w.start = 'miu irc start', {
|
|
62
|
+
'--host' => 'chat.freenode.net',
|
|
63
|
+
'--nick' => 'miu',
|
|
64
|
+
'--channels' => ['#miu'],
|
|
65
|
+
'--verbose' => false
|
|
66
|
+
}
|
|
67
|
+
w.keepalive
|
|
68
|
+
end
|
|
69
|
+
EOS
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'miu'
|
|
2
|
+
require 'celluloid/zmq'
|
|
3
|
+
|
|
4
|
+
module Miu
|
|
5
|
+
module Nodes
|
|
6
|
+
module IRC
|
|
7
|
+
class Publisher
|
|
8
|
+
include Miu::Publisher
|
|
9
|
+
include Celluloid::ZMQ
|
|
10
|
+
socket_type Celluloid::ZMQ::PubSocket
|
|
11
|
+
|
|
12
|
+
def write(msg)
|
|
13
|
+
packet = super
|
|
14
|
+
Miu::Logger.debug "[PUB] #{packet}"
|
|
15
|
+
packet
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'miu'
|
|
2
|
+
require 'celluloid/zmq'
|
|
3
|
+
|
|
4
|
+
module Miu
|
|
5
|
+
module Nodes
|
|
6
|
+
module IRC
|
|
7
|
+
class Subscriber
|
|
8
|
+
include Miu::Subscriber
|
|
9
|
+
include Celluloid::ZMQ
|
|
10
|
+
socket_type Celluloid::ZMQ::SubSocket
|
|
11
|
+
|
|
12
|
+
def run(irc)
|
|
13
|
+
@irc = irc
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def on_packet(packet)
|
|
20
|
+
Miu::Logger.debug "[SUB] #{packet}"
|
|
21
|
+
super
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def on_text(tag, msg)
|
|
25
|
+
target = msg.content.room.name
|
|
26
|
+
text = msg.content.text
|
|
27
|
+
notice = !!msg.content.meta['notice']
|
|
28
|
+
|
|
29
|
+
command = notice ? 'NOTICE' : 'PRIVMSG'
|
|
30
|
+
irc.send_message command, target, text
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def on_enter(tag, msg)
|
|
34
|
+
channel = msg.content.room.name
|
|
35
|
+
irc.send_message 'JOIN', channel
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def on_leave(tag, msg)
|
|
39
|
+
channel = msg.content.room.name
|
|
40
|
+
irc.send_message 'PART', channel
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/miu-irc.gemspec
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'miu
|
|
4
|
+
require 'miu/nodes/irc/version'
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = "miu-irc"
|
|
8
|
-
gem.version = Miu::IRC::VERSION
|
|
8
|
+
gem.version = Miu::Nodes::IRC::VERSION
|
|
9
9
|
gem.authors = ["mashiro"]
|
|
10
10
|
gem.email = ["mail@mashiro.org"]
|
|
11
11
|
gem.description = %q{irc plugin for miu}
|
|
@@ -17,8 +17,9 @@ Gem::Specification.new do |gem|
|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
18
|
gem.require_paths = ["lib"]
|
|
19
19
|
|
|
20
|
-
gem.add_dependency 'miu'
|
|
21
|
-
gem.add_dependency 'ircp'
|
|
22
|
-
gem.add_dependency 'celluloid-io'
|
|
23
|
-
gem.
|
|
20
|
+
gem.add_dependency 'miu', '>= 0.2.2'
|
|
21
|
+
gem.add_dependency 'ircp', '>= 1.1.7'
|
|
22
|
+
gem.add_dependency 'celluloid-io', '>= 0.14.0'
|
|
23
|
+
gem.add_dependency 'celluloid-zmq', '>= 0.14.0'
|
|
24
|
+
gem.add_development_dependency 'rake', '>= 10.0.3'
|
|
24
25
|
end
|
metadata
CHANGED
|
@@ -1,80 +1,85 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: miu-irc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.1.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- mashiro
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
11
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: miu
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
16
|
requirements:
|
|
19
|
-
- -
|
|
17
|
+
- - '>='
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
21
|
-
version:
|
|
19
|
+
version: 0.2.2
|
|
22
20
|
type: :runtime
|
|
23
21
|
prerelease: false
|
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
23
|
requirements:
|
|
27
|
-
- -
|
|
24
|
+
- - '>='
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
|
-
version:
|
|
26
|
+
version: 0.2.2
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
|
31
28
|
name: ircp
|
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
|
33
|
-
none: false
|
|
34
30
|
requirements:
|
|
35
|
-
- -
|
|
31
|
+
- - '>='
|
|
36
32
|
- !ruby/object:Gem::Version
|
|
37
|
-
version:
|
|
33
|
+
version: 1.1.7
|
|
38
34
|
type: :runtime
|
|
39
35
|
prerelease: false
|
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
-
none: false
|
|
42
37
|
requirements:
|
|
43
|
-
- -
|
|
38
|
+
- - '>='
|
|
44
39
|
- !ruby/object:Gem::Version
|
|
45
|
-
version:
|
|
40
|
+
version: 1.1.7
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
|
47
42
|
name: celluloid-io
|
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
|
49
|
-
none: false
|
|
50
44
|
requirements:
|
|
51
|
-
- -
|
|
45
|
+
- - '>='
|
|
52
46
|
- !ruby/object:Gem::Version
|
|
53
|
-
version:
|
|
47
|
+
version: 0.14.0
|
|
54
48
|
type: :runtime
|
|
55
49
|
prerelease: false
|
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
-
none: false
|
|
58
51
|
requirements:
|
|
59
|
-
- -
|
|
52
|
+
- - '>='
|
|
60
53
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
54
|
+
version: 0.14.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: celluloid-zmq
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.14.0
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.14.0
|
|
62
69
|
- !ruby/object:Gem::Dependency
|
|
63
70
|
name: rake
|
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
|
65
|
-
none: false
|
|
66
72
|
requirements:
|
|
67
|
-
- -
|
|
73
|
+
- - '>='
|
|
68
74
|
- !ruby/object:Gem::Version
|
|
69
|
-
version:
|
|
75
|
+
version: 10.0.3
|
|
70
76
|
type: :development
|
|
71
77
|
prerelease: false
|
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
-
none: false
|
|
74
79
|
requirements:
|
|
75
|
-
- -
|
|
80
|
+
- - '>='
|
|
76
81
|
- !ruby/object:Gem::Version
|
|
77
|
-
version:
|
|
82
|
+
version: 10.0.3
|
|
78
83
|
description: irc plugin for miu
|
|
79
84
|
email:
|
|
80
85
|
- mail@mashiro.org
|
|
@@ -88,38 +93,35 @@ files:
|
|
|
88
93
|
- README.md
|
|
89
94
|
- Rakefile
|
|
90
95
|
- lib/miu-irc.rb
|
|
91
|
-
- lib/miu
|
|
92
|
-
- lib/miu
|
|
93
|
-
- lib/miu/
|
|
96
|
+
- lib/miu/nodes/irc.rb
|
|
97
|
+
- lib/miu/nodes/irc/client.rb
|
|
98
|
+
- lib/miu/nodes/irc/connection.rb
|
|
99
|
+
- lib/miu/nodes/irc/node.rb
|
|
100
|
+
- lib/miu/nodes/irc/publisher.rb
|
|
101
|
+
- lib/miu/nodes/irc/subscriber.rb
|
|
102
|
+
- lib/miu/nodes/irc/version.rb
|
|
94
103
|
- miu-irc.gemspec
|
|
95
104
|
homepage: ''
|
|
96
105
|
licenses: []
|
|
106
|
+
metadata: {}
|
|
97
107
|
post_install_message:
|
|
98
108
|
rdoc_options: []
|
|
99
109
|
require_paths:
|
|
100
110
|
- lib
|
|
101
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
|
-
none: false
|
|
103
112
|
requirements:
|
|
104
|
-
- -
|
|
113
|
+
- - '>='
|
|
105
114
|
- !ruby/object:Gem::Version
|
|
106
115
|
version: '0'
|
|
107
|
-
segments:
|
|
108
|
-
- 0
|
|
109
|
-
hash: 866858604891186946
|
|
110
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
|
-
none: false
|
|
112
117
|
requirements:
|
|
113
|
-
- -
|
|
118
|
+
- - '>='
|
|
114
119
|
- !ruby/object:Gem::Version
|
|
115
120
|
version: '0'
|
|
116
|
-
segments:
|
|
117
|
-
- 0
|
|
118
|
-
hash: 866858604891186946
|
|
119
121
|
requirements: []
|
|
120
122
|
rubyforge_project:
|
|
121
|
-
rubygems_version:
|
|
123
|
+
rubygems_version: 2.0.0
|
|
122
124
|
signing_key:
|
|
123
|
-
specification_version:
|
|
125
|
+
specification_version: 4
|
|
124
126
|
summary: irc plugin for miu
|
|
125
127
|
test_files: []
|
data/lib/miu-irc/connection.rb
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
require 'celluloid/io'
|
|
2
|
-
require 'ircp'
|
|
3
|
-
require 'forwardable'
|
|
4
|
-
|
|
5
|
-
module Miu
|
|
6
|
-
module IRC
|
|
7
|
-
class Connection
|
|
8
|
-
include Celluloid::IO
|
|
9
|
-
|
|
10
|
-
BUFFER_SIZE = 1024 * 4
|
|
11
|
-
|
|
12
|
-
attr_reader :host, :port
|
|
13
|
-
attr_reader :nick, :user, :real, :pass
|
|
14
|
-
attr_reader :encoding, :channels
|
|
15
|
-
attr_reader :socket
|
|
16
|
-
|
|
17
|
-
def initialize(options)
|
|
18
|
-
@host = options[:host]
|
|
19
|
-
@port = options[:port] || 6667
|
|
20
|
-
@nick = options[:nick]
|
|
21
|
-
@user = options[:user] || @nick
|
|
22
|
-
@real = options[:real] || @nick
|
|
23
|
-
@pass = options[:pass]
|
|
24
|
-
@encoding = options[:encoding] || 'UTF-8'
|
|
25
|
-
@channels = options[:channels] || []
|
|
26
|
-
|
|
27
|
-
@socket = TCPSocket.new @host, @port
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def finalize
|
|
31
|
-
close
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def close
|
|
35
|
-
@socket.close if @socket && !@socket.closed?
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def send_message(*args)
|
|
39
|
-
msg = Ircp::Message.new(*args)
|
|
40
|
-
puts "[SEND] #{msg}"
|
|
41
|
-
@socket.write msg.to_irc
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def run
|
|
45
|
-
attach
|
|
46
|
-
readlines do |data|
|
|
47
|
-
msg = Ircp.parse data rescue nil
|
|
48
|
-
if msg
|
|
49
|
-
puts "[RECV] #{msg}"
|
|
50
|
-
on_message msg
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def readlines(buffer_size = BUFFER_SIZE, &block)
|
|
56
|
-
readbuf = ''.force_encoding('ASCII-8BIT')
|
|
57
|
-
loop do
|
|
58
|
-
readbuf << @socket.readpartial(buffer_size).force_encoding('ASCII-8BIT')
|
|
59
|
-
while data = readbuf.slice!(/.+\r\n/)
|
|
60
|
-
block.call encode(data, @encoding)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def encode(str, encoding)
|
|
66
|
-
str.force_encoding(encoding).encode!(:invalid => :replace, :undef => :replace)
|
|
67
|
-
str.chars.select { |c| c.valid_encoding? }.join
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def attach
|
|
71
|
-
send_message 'PASS', @pass if @pass
|
|
72
|
-
send_message 'NICK', @nick
|
|
73
|
-
send_message 'USER', @user, '*', '*', @real
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def on_message(msg)
|
|
77
|
-
method = "on_#{msg.command.to_s.downcase}"
|
|
78
|
-
__send__ method, msg if respond_to? method
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def on_376(msg)
|
|
82
|
-
@channels.each do |channel|
|
|
83
|
-
send_message 'JOIN', *channel.split(/ +/)
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def on_ping(msg)
|
|
88
|
-
send_message 'PONG'
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
data/lib/miu-irc/version.rb
DELETED
data/lib/miu/plugins/irc.rb
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
require 'miu'
|
|
2
|
-
require 'miu-irc/connection'
|
|
3
|
-
|
|
4
|
-
module Miu
|
|
5
|
-
module Plugins
|
|
6
|
-
class IRC
|
|
7
|
-
include Miu::Plugin
|
|
8
|
-
|
|
9
|
-
def initialize(options)
|
|
10
|
-
@publisher = Miu::Publisher.new({
|
|
11
|
-
:host => options[:'miu-pub-host'],
|
|
12
|
-
:port => options[:'miu-pub-port'],
|
|
13
|
-
})
|
|
14
|
-
@subscriber = Miu::Subscriber.new({
|
|
15
|
-
:host => options[:'miu-sub-host'],
|
|
16
|
-
:port => options[:'miu-sub-port'],
|
|
17
|
-
:subscribe => 'miu.output.irc.',
|
|
18
|
-
})
|
|
19
|
-
@irc_client = IRCClient.new(@publisher, {
|
|
20
|
-
:host => options[:host],
|
|
21
|
-
:port => options[:port],
|
|
22
|
-
:nick => options[:nick],
|
|
23
|
-
:user => options[:user],
|
|
24
|
-
:real => options[:real],
|
|
25
|
-
:pass => options[:pass],
|
|
26
|
-
:channels => options[:channels],
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
@publisher.connect
|
|
30
|
-
@subscriber.connect
|
|
31
|
-
@irc_client.async.run
|
|
32
|
-
|
|
33
|
-
@future = Celluloid::Future.new do
|
|
34
|
-
@subscriber.each do |msg|
|
|
35
|
-
p msg
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
[:INT, :TERM].each do |sig|
|
|
40
|
-
trap(sig) do
|
|
41
|
-
shutdown
|
|
42
|
-
exit
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
sleep
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
def shutdown
|
|
52
|
-
@irc_client.close
|
|
53
|
-
@subscriber.close
|
|
54
|
-
@publisher.close
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class IRCClient < Miu::IRC::Connection
|
|
58
|
-
def initialize(publisher, options)
|
|
59
|
-
@publisher = publisher
|
|
60
|
-
super options
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def on_privmsg(msg)
|
|
64
|
-
publish_text_message msg
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def on_notice(msg)
|
|
68
|
-
publish_text_message msg, 'notice'
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
private
|
|
72
|
-
|
|
73
|
-
def publish_text_message(msg, sub_type = nil)
|
|
74
|
-
return unless msg.prefix
|
|
75
|
-
|
|
76
|
-
m = Miu::Messages::Text.new(:sub_type => sub_type) do |m|
|
|
77
|
-
m.network.name = 'irc'
|
|
78
|
-
m.content.tap do |c|
|
|
79
|
-
c.room.name = msg.params[0]
|
|
80
|
-
c.user.name = msg.prefix.nick || msg.prefix.servername
|
|
81
|
-
c.text = msg.params[1]
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
@publisher.send 'miu.input.irc.', m
|
|
86
|
-
rescue => e
|
|
87
|
-
Mou::Logger.exception e
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
register :irc, :desc => %(IRC plugin for miu) do
|
|
92
|
-
desc 'start', %(Start miu-irc plugin)
|
|
93
|
-
option 'host', :type => :string, :desc => 'irc host', :required => true, :aliases => '-a'
|
|
94
|
-
option 'port', :type => :numeric, :default => 6667, :desc => 'irc port', :aliases => '-p'
|
|
95
|
-
option 'nick', :type => :string, :desc => 'irc nick', :required => true, :aliases => '-n'
|
|
96
|
-
option 'user', :type => :string, :desc => 'irc user'
|
|
97
|
-
option 'real', :type => :string, :desc => 'irc real'
|
|
98
|
-
option 'pass', :type => :string, :desc => 'irc pass'
|
|
99
|
-
option 'encoding', :type => :string, :default => 'UTF-8', :desc => 'irc encoding'
|
|
100
|
-
option 'channels', :type => :array, :default => [], :desc => 'irc join channels', :banner => '#channel1 #channel2'
|
|
101
|
-
add_miu_pub_options!
|
|
102
|
-
add_miu_sub_options!
|
|
103
|
-
def start
|
|
104
|
-
IRC.new options
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
desc 'init', %(Generates a miu-irc configurations)
|
|
108
|
-
def init
|
|
109
|
-
append_to_file 'config/miu.god', <<-CONF
|
|
110
|
-
|
|
111
|
-
God.watch do |w|
|
|
112
|
-
w.dir = Miu.root
|
|
113
|
-
w.log = Miu.root.join('log/irc.log')
|
|
114
|
-
w.name = 'irc'
|
|
115
|
-
|
|
116
|
-
host = 'chat.freenode.net'
|
|
117
|
-
nick = 'miu'
|
|
118
|
-
w.start = "bundle exec miu irc start --host=\#{host} --nick=\#{nick}"
|
|
119
|
-
|
|
120
|
-
w.keepalive
|
|
121
|
-
end
|
|
122
|
-
CONF
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|