agig 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in agig.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 SHIBATA Hiroshi
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.
@@ -0,0 +1,29 @@
1
+ # Agig
2
+
3
+ Agig is another Github IRC Gateway, forked cho45's [gig.rb](https://github.com/cho45/net-irc/blob/master/examples/gig.rb)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'agig'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install agig
18
+
19
+ ## Usage
20
+
21
+ $ agig -d
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 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/agig/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["SHIBATA Hiroshi"]
6
+ gem.email = ["shibata.hiroshi@gmail.com"]
7
+ gem.description = %q{another Github IRC Gateway}
8
+ gem.summary = %q{agig is another Github IRC Gateway. agig is forked from gig.rb, and contained net-irc gems.}
9
+ gem.homepage = "https://github.com/hsbt/agig"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "agig"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Agig::VERSION
17
+
18
+ gem.add_dependency 'net-irc', ['>= 0']
19
+ gem.add_dependency 'libxml-ruby', ['>= 0']
20
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << "lib"
4
+ $LOAD_PATH << "../lib"
5
+
6
+ require 'agig'
7
+ Agig::Client.run
@@ -0,0 +1,13 @@
1
+ =begin
2
+ # gig.rb
3
+
4
+ Github IRC Gateway
5
+
6
+ =end
7
+
8
+ $KCODE = "u" unless defined? ::Encoding
9
+
10
+ require "agig/version"
11
+ require "agig/client"
12
+ require "agig/optparse"
13
+ require "agig/session"
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'net/irc'
3
+ require 'logger'
4
+
5
+ module Agig::Client
6
+ def self.run
7
+ opts = Agig::OptParser.parse!(ARGV)
8
+
9
+ opts[:logger] = Logger.new(opts[:log], "daily")
10
+ opts[:logger].level = opts[:debug] ? Logger::DEBUG : Logger::INFO
11
+
12
+ Net::IRC::Server.new(opts[:host], opts[:port], Agig::Session, opts).start
13
+ end
14
+ end
@@ -0,0 +1,47 @@
1
+ require "optparse"
2
+
3
+ module Agig::OptParser
4
+ def self.parse!(argv)
5
+ opts = {
6
+ :port => 16705,
7
+ :host => "localhost",
8
+ :log => nil,
9
+ :debug => false,
10
+ :foreground => false,
11
+ }
12
+
13
+ OptionParser.new do |parser|
14
+ parser.instance_eval do
15
+ self.banner = "Usage: #{$0} [opts]"
16
+ separator ""
17
+
18
+ separator "Options:"
19
+ on("-p", "--port [PORT=#{opts[:port]}]", "port number to listen") do |port|
20
+ opts[:port] = port
21
+ end
22
+
23
+ on("-h", "--host [HOST=#{opts[:host]}]", "host name or IP address to listen") do |host|
24
+ opts[:host] = host
25
+ end
26
+
27
+ on("-l", "--log LOG", "log file") do |log|
28
+ opts[:log] = log
29
+ end
30
+
31
+ on("-d", "--debug", "Enable debug mode") do |debug|
32
+ opts[:log] = $stdout
33
+ opts[:debug] = true
34
+ end
35
+
36
+ on("-f", "--foreground", "run foreground") do |foreground|
37
+ opts[:log] = $stdout
38
+ opts[:foreground] = true
39
+ end
40
+
41
+ parse!(argv)
42
+ end
43
+ end
44
+
45
+ opts
46
+ end
47
+ end
@@ -0,0 +1,101 @@
1
+ require 'rubygems'
2
+ require 'net/irc'
3
+ require 'net/https'
4
+ require 'libxml'
5
+ require 'ostruct'
6
+ require 'time'
7
+
8
+ class Agig::Session < Net::IRC::Server::Session
9
+ EVENTS = {
10
+ 'DownloadEvent' => '6',
11
+ 'GistEvent' => '10',
12
+ 'WatchEvent' => '15',
13
+ 'FollowEvent' => '15',
14
+ 'CreateEvent' => '13',
15
+ 'ForkEvent' => '3',
16
+ 'PushEvent' => '14',
17
+ }
18
+
19
+ def server_name
20
+ "github"
21
+ end
22
+
23
+ def server_version
24
+ "0.0.0"
25
+ end
26
+
27
+ def main_channel
28
+ @opts.main_channel || "#github"
29
+ end
30
+
31
+ def initialize(*args)
32
+ super
33
+ @last_retrieved = Time.now
34
+ @cert_store = OpenSSL::X509::Store.new
35
+ @cert_store.set_default_paths
36
+ end
37
+
38
+ def on_disconnected
39
+ @retrieve_thread.kill rescue nil
40
+ end
41
+
42
+ def on_user(m)
43
+ super
44
+ @real, *@opts = @real.split(/\s+/)
45
+ @opts = OpenStruct.new @opts.inject({}) {|r, i|
46
+ key, value = i.split("=", 2)
47
+ r.update key => case value
48
+ when nil then true
49
+ when /\A\d+\z/ then value.to_i
50
+ when /\A(?:\d+\.\d*|\.\d+)\z/ then value.to_f
51
+ else value
52
+ end
53
+ }
54
+ post @nick, JOIN, main_channel
55
+
56
+ @retrieve_thread = Thread.start do
57
+ loop do
58
+ begin
59
+ @log.info 'retrieveing feed...'
60
+ uri = URI.parse("https://github.com/#{@real}.private.atom?token=#{@pass}")
61
+ http = Net::HTTP.new(uri.host, uri.port)
62
+ http.use_ssl = true
63
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
64
+ http.cert_store = @cert_store
65
+ req = Net::HTTP::Get.new(uri.request_uri)
66
+ res = http.request(req)
67
+
68
+ doc = LibXML::XML::Document.string(res.body, :base_uri => uri.to_s)
69
+ ns = %w|a:http://www.w3.org/2005/Atom|
70
+ entries = []
71
+ doc.find('/a:feed/a:entry', ns).each do |n|
72
+ entries << {
73
+ :datetime => Time.parse(n.find('string(a:published)', ns)),
74
+ :id => n.find('string(a:id)', ns),
75
+ :title => n.find('string(a:title)', ns),
76
+ :author => n.find('string(a:author/a:name)', ns),
77
+ :link => n.find('string(a:link/@href)', ns),
78
+ }
79
+ end
80
+
81
+ entries.reverse_each do |entry|
82
+ next if entry[:datetime] <= @last_retrieved
83
+ type = entry[:id][%r|tag:github.com,2008:(.+?)/\d+|, 1]
84
+ post entry[:author], PRIVMSG, main_channel,
85
+ "\003#{EVENTS[type] || '5'}#{entry[:title]}\017 \00314#{entry[:link]}\017"
86
+ end
87
+
88
+ @last_retrieved = entries.first[:datetime]
89
+ @log.info 'sleep'
90
+ sleep 30
91
+ rescue Exception => e
92
+ @log.error e.inspect
93
+ e.backtrace.each do |l|
94
+ @log.error "\t#{l}"
95
+ end
96
+ sleep 10
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ module Agig
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: agig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - SHIBATA Hiroshi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: net-irc
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: libxml-ruby
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
+ description: another Github IRC Gateway
47
+ email:
48
+ - shibata.hiroshi@gmail.com
49
+ executables:
50
+ - agig
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - agig.gemspec
60
+ - bin/agig
61
+ - lib/agig.rb
62
+ - lib/agig/client.rb
63
+ - lib/agig/optparse.rb
64
+ - lib/agig/session.rb
65
+ - lib/agig/version.rb
66
+ homepage: https://github.com/hsbt/agig
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.21
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: agig is another Github IRC Gateway. agig is forked from gig.rb, and contained
90
+ net-irc gems.
91
+ test_files: []
92
+ has_rdoc: