miu-irc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/miu/plugins/irc.rb +127 -0
- data/lib/miu-irc/connection.rb +92 -0
- data/lib/miu-irc/version.rb +5 -0
- data/lib/miu-irc.rb +5 -0
- data/miu-irc.gemspec +24 -0
- metadata +125 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 mashiro
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Miu::IRC
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'miu-irc'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install miu-irc
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,127 @@
|
|
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
|
@@ -0,0 +1,92 @@
|
|
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.rb
ADDED
data/miu-irc.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'miu-irc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "miu-irc"
|
8
|
+
gem.version = Miu::IRC::VERSION
|
9
|
+
gem.authors = ["mashiro"]
|
10
|
+
gem.email = ["mail@mashiro.org"]
|
11
|
+
gem.description = %q{irc plugin for miu}
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'miu'
|
21
|
+
gem.add_dependency 'ircp'
|
22
|
+
gem.add_dependency 'celluloid-io'
|
23
|
+
gem.add_development_dependency 'rake'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: miu-irc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mashiro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: miu
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ircp
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: celluloid-io
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: irc plugin for miu
|
79
|
+
email:
|
80
|
+
- mail@mashiro.org
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- lib/miu-irc.rb
|
91
|
+
- lib/miu-irc/connection.rb
|
92
|
+
- lib/miu-irc/version.rb
|
93
|
+
- lib/miu/plugins/irc.rb
|
94
|
+
- miu-irc.gemspec
|
95
|
+
homepage: ''
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: 866858604891186946
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: 866858604891186946
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.8.24
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: irc plugin for miu
|
125
|
+
test_files: []
|