kirby 4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/CHANGELOG +8 -0
  2. data/LICENSE +184 -0
  3. data/README +44 -0
  4. data/bin/kirby +22 -0
  5. data/kirby.gemspec +45 -0
  6. data/lib/kirby.rb +125 -0
  7. metadata +68 -0
@@ -0,0 +1,8 @@
1
+
2
+ v4. Documentation; Rakefile. Shouldn't have bumped the version, but all right.
3
+
4
+ v3. del.icio.us integration.
5
+
6
+ v2. SVN rewrite.
7
+
8
+ v1. Spawned.
data/LICENSE ADDED
@@ -0,0 +1,184 @@
1
+ Academic Free License (AFL) v. 3.0
2
+
3
+ This Academic Free License (the "License") applies to any original work
4
+ of authorship (the "Original Work") whose owner (the "Licensor") has
5
+ placed the following licensing notice adjacent to the copyright notice
6
+ for the Original Work:
7
+
8
+ Licensed under the Academic Free License version 3.0
9
+
10
+ 1) Grant of Copyright License. Licensor grants You a worldwide,
11
+ royalty-free, non-exclusive, sublicensable license, for the duration of
12
+ the copyright, to do the following:
13
+
14
+ a) to reproduce the Original Work in copies, either alone or as part of
15
+ a collective work;
16
+
17
+ b) to translate, adapt, alter, transform, modify, or arrange the
18
+ Original Work, thereby creating derivative works ("Derivative Works")
19
+ based upon the Original Work;
20
+
21
+ c) to distribute or communicate copies of the Original Work and
22
+ Derivative Works to the public, under any license of your choice that
23
+ does not contradict the terms and conditions, including Licensor's
24
+ reserved rights and remedies, in this Academic Free License;
25
+
26
+ d) to perform the Original Work publicly; and
27
+
28
+ e) to display the Original Work publicly.
29
+
30
+ 2) Grant of Patent License. Licensor grants You a worldwide,
31
+ royalty-free, non-exclusive, sublicensable license, under patent claims
32
+ owned or controlled by the Licensor that are embodied in the Original
33
+ Work as furnished by the Licensor, for the duration of the patents, to
34
+ make, use, sell, offer for sale, have made, and import the Original Work
35
+ and Derivative Works.
36
+
37
+ 3) Grant of Source Code License. The term "Source Code" means the
38
+ preferred form of the Original Work for making modifications to it and
39
+ all available documentation describing how to modify the Original Work.
40
+ Licensor agrees to provide a machine-readable copy of the Source Code of
41
+ the Original Work along with each copy of the Original Work that
42
+ Licensor distributes. Licensor reserves the right to satisfy this
43
+ obligation by placing a machine-readable copy of the Source Code in an
44
+ information repository reasonably calculated to permit inexpensive and
45
+ convenient access by You for as long as Licensor continues to distribute
46
+ the Original Work.
47
+
48
+ 4) Exclusions From License Grant. Neither the names of Licensor, nor the
49
+ names of any contributors to the Original Work, nor any of their
50
+ trademarks or service marks, may be used to endorse or promote products
51
+ derived from this Original Work without express prior permission of the
52
+ Licensor. Except as expressly stated herein, nothing in this License
53
+ grants any license to Licensor's trademarks, copyrights, patents, trade
54
+ secrets or any other intellectual property. No patent license is granted
55
+ to make, use, sell, offer for sale, have made, or import embodiments of
56
+ any patent claims other than the licensed claims defined in Section 2.
57
+ No license is granted to the trademarks of Licensor even if such marks
58
+ are included in the Original Work. Nothing in this License shall be
59
+ interpreted to prohibit Licensor from licensing under terms different
60
+ from this License any Original Work that Licensor otherwise would have a
61
+ right to license.
62
+
63
+ 5) External Deployment. The term "External Deployment" means the use,
64
+ distribution, or communication of the Original Work or Derivative Works
65
+ in any way such that the Original Work or Derivative Works may be used
66
+ by anyone other than You, whether those works are distributed or
67
+ communicated to those persons or made available as an application
68
+ intended for use over a network. As an express condition for the grants
69
+ of license hereunder, You must treat any External Deployment by You of
70
+ the Original Work or a Derivative Work as a distribution under section
71
+ 1(c).
72
+
73
+ 6) Attribution Rights. You must retain, in the Source Code of any
74
+ Derivative Works that You create, all copyright, patent, or trademark
75
+ notices from the Source Code of the Original Work, as well as any
76
+ notices of licensing and any descriptive text identified therein as an
77
+ "Attribution Notice." You must cause the Source Code for any Derivative
78
+ Works that You create to carry a prominent Attribution Notice reasonably
79
+ calculated to inform recipients that You have modified the Original
80
+ Work.
81
+
82
+ 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants
83
+ that the copyright in and to the Original Work and the patent rights
84
+ granted herein by Licensor are owned by the Licensor or are sublicensed
85
+ to You under the terms of this License with the permission of the
86
+ contributor(s) of those copyrights and patent rights. Except as
87
+ expressly stated in the immediately preceding sentence, the Original
88
+ Work is provided under this License on an "AS IS" BASIS and WITHOUT
89
+ WARRANTY, either express or implied, including, without limitation, the
90
+ warranties of non-infringement, merchantability or fitness for a
91
+ particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL
92
+ WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential
93
+ part of this License. No license to the Original Work is granted by this
94
+ License except under this disclaimer.
95
+
96
+ 8) Limitation of Liability. Under no circumstances and under no legal
97
+ theory, whether in tort (including negligence), contract, or otherwise,
98
+ shall the Licensor be liable to anyone for any indirect, special,
99
+ incidental, or consequential damages of any character arising as a
100
+ result of this License or the use of the Original Work including,
101
+ without limitation, damages for loss of goodwill, work stoppage,
102
+ computer failure or malfunction, or any and all other commercial damages
103
+ or losses. This limitation of liability shall not apply to the extent
104
+ applicable law prohibits such limitation.
105
+
106
+ 9) Acceptance and Termination. If, at any time, You expressly assented
107
+ to this License, that assent indicates your clear and irrevocable
108
+ acceptance of this License and all of its terms and conditions. If You
109
+ distribute or communicate copies of the Original Work or a Derivative
110
+ Work, You must make a reasonable effort under the circumstances to
111
+ obtain the express assent of recipients to the terms of this License.
112
+ This License conditions your rights to undertake the activities listed
113
+ in Section 1, including your right to create Derivative Works based upon
114
+ the Original Work, and doing so without honoring these terms and
115
+ conditions is prohibited by copyright law and international treaty.
116
+ Nothing in this License is intended to affect copyright exceptions and
117
+ limitations (including "fair use" or "fair dealing"). This License shall
118
+ terminate immediately and You may no longer exercise any of the rights
119
+ granted to You by this License upon your failure to honor the conditions
120
+ in Section 1(c).
121
+
122
+ 10) Termination for Patent Action. This License shall terminate
123
+ automatically and You may no longer exercise any of the rights granted
124
+ to You by this License as of the date You commence an action, including
125
+ a cross-claim or counterclaim, against Licensor or any licensee alleging
126
+ that the Original Work infringes a patent. This termination provision
127
+ shall not apply for an action alleging patent infringement by
128
+ combinations of the Original Work with other software or hardware.
129
+
130
+ 11) Jurisdiction, Venue and Governing Law. Any action or suit relating
131
+ to this License may be brought only in the courts of a jurisdiction
132
+ wherein the Licensor resides or in which Licensor conducts its primary
133
+ business, and under the laws of that jurisdiction excluding its
134
+ conflict-of-law provisions. The application of the United Nations
135
+ Convention on Contracts for the International Sale of Goods is expressly
136
+ excluded. Any use of the Original Work outside the scope of this License
137
+ or after its termination shall be subject to the requirements and
138
+ penalties of copyright or patent law in the appropriate jurisdiction.
139
+ This section shall survive the termination of this License.
140
+
141
+ 12) Attorneys' Fees. In any action to enforce the terms of this License
142
+ or seeking damages relating thereto, the prevailing party shall be
143
+ entitled to recover its costs and expenses, including, without
144
+ limitation, reasonable attorneys' fees and costs incurred in connection
145
+ with such action, including any appeal of such action. This section
146
+ shall survive the termination of this License.
147
+
148
+ 13) Miscellaneous. If any provision of this License is held to be
149
+ unenforceable, such provision shall be reformed only to the extent
150
+ necessary to make it enforceable.
151
+
152
+ 14) Definition of "You" in This License. "You" throughout this License,
153
+ whether in upper or lower case, means an individual or a legal entity
154
+ exercising rights under, and complying with all of the terms of, this
155
+ License. For legal entities, "You" includes any entity that controls, is
156
+ controlled by, or is under common control with you. For purposes of this
157
+ definition, "control" means (i) the power, direct or indirect, to cause
158
+ the direction or management of such entity, whether by contract or
159
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
160
+ outstanding shares, or (iii) beneficial ownership of such entity.
161
+
162
+ 15) Right to Use. You may use the Original Work in all ways not
163
+ otherwise restricted or conditioned by this License or by law, and
164
+ Licensor promises not to interfere with or be responsible for such uses
165
+ by You.
166
+
167
+ 16) Modification of This License. This License is Copyright (c) 2005
168
+ Lawrence Rosen. Permission is granted to copy, distribute, or
169
+ communicate this License without modification. Nothing in this License
170
+ permits You to modify this License as applied to the Original Work or to
171
+ Derivative Works. However, You may modify the text of this License and
172
+ copy, distribute or communicate your modified version (the "Modified
173
+ License") and apply it to other original works of authorship subject to
174
+ the following conditions: (i) You may not indicate in any way that your
175
+ Modified License is the "Academic Free License" or "AFL" and you may not
176
+ use those names in the name of your Modified License; (ii) You must
177
+ replace the notice specified in the first paragraph above with the
178
+ notice "Licensed under <insert your license name here>" or with a notice
179
+ of your own that is not confusingly similar to the notice in this
180
+ License; and (iii) You may not claim that your original works are open
181
+ source software unless your Modified License has been approved by Open
182
+ Source Initiative (OSI) and You comply with its license review and
183
+ certification process.
184
+
data/README ADDED
@@ -0,0 +1,44 @@
1
+
2
+ Kirby
3
+
4
+ A super-clean IRC bot.
5
+
6
+ == License
7
+
8
+ Copyright 2007 Cloudburst, LLC. See included LICENSE file.
9
+
10
+ == Features
11
+
12
+ * <tt>irb</tt>-like interface
13
+ * safe, sandboxed Ruby environment
14
+ * svn repository commit watching
15
+ * silent del.icio.us link saving
16
+ * tolerable channel fault recovery
17
+
18
+ Kirby is considered feature-locked.
19
+
20
+ == Installation
21
+
22
+ sudo gem install kirby
23
+
24
+ == Usage
25
+
26
+ Run <tt>kirby [nick] [channel] [server] [delicious_name] [delicious_password]</tt>.
27
+
28
+ Optional parameters:
29
+ <tt>-d</tt>:: Daemonize.
30
+ <tt>-no-d</tt>:: Don't daemonize.
31
+ <tt>--silent</tt>:: Never speak, even for errors.
32
+
33
+ See the Kirby class for commands.
34
+
35
+ == Crontab example
36
+
37
+ You can use a crontask to keep Kirby alive at all times.
38
+
39
+ * * * * * /path/to/kirby [options...] > /dev/null 2>&1
40
+
41
+ == Further resources
42
+
43
+ * http://blog.evanweaver.com/pages/code#kirby
44
+ * http://rubyforge.org/forum/forum.php?forum_id=13984
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin rdoc
4
+ Run <tt>kirby [nick] [channel] [server] [delicious_name] [delicious_password]</tt>.
5
+
6
+ Optional parameters:
7
+ <tt>-d</tt>:: Daemonize.
8
+ <tt>-no-d</tt>:: Don't daemonize.
9
+ <tt>--silent</tt>:: Never speak, even for errors.
10
+ =end
11
+
12
+ require 'rubygems'
13
+ require 'kirby'
14
+
15
+ pid = open(Kirby::PIDFILE).gets.chomp rescue nil
16
+
17
+ if !pid or `ps #{pid}`.split("\n").size < 2
18
+ puts "Starting"
19
+ Daemons.daemonize if ARGV[0] == '-d' #:ontop => true
20
+ open(Kirby::PIDFILE, 'w') {|f| f.puts $$}
21
+ Kirby.instance.restart
22
+ end
@@ -0,0 +1,45 @@
1
+
2
+ # Gem::Specification for Kirby-4
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{kirby}
7
+ s.version = "4"
8
+ s.date = %q{2007-08-12}
9
+ s.summary = %q{A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us.}
10
+ s.email = %q{}
11
+ s.homepage = %q{http://blog.evanweaver.com/pages/code#kirby}
12
+ s.rubyforge_project = %q{fauna}
13
+ s.description = %q{A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us.}
14
+ s.default_executable = %q{kirby}
15
+ s.has_rdoc = true
16
+ s.authors = [""]
17
+ s.files = ["lib/kirby.rb", "bin/kirby", "README", "LICENSE", "CHANGELOG", "kirby.gemspec"]
18
+ s.executables = ["kirby"]
19
+ s.add_dependency(%q<hpricot>, ["> 0.0.0"])
20
+ s.add_dependency(%q<daemons>, ["> 0.0.0"])
21
+ end
22
+
23
+
24
+ # # Original Rakefile source (requires the Echoe gem):
25
+ #
26
+ #
27
+ # require 'rubygems'
28
+ # require 'echoe'
29
+ #
30
+ # Echoe.new("kirby", `cat CHANGELOG`[/^v([\d\.]+)\. /, 1]) do |p|
31
+ #
32
+ # p.name = "kirby"
33
+ # p.rubyforge_name = "fauna"
34
+ # p.description = p.summary = "A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us."
35
+ # p.url = "http://blog.evanweaver.com/pages/code#kirby"
36
+ # p.docs_host = "blog.evanweaver.com:~/www/snax/public/files/doc/"
37
+ # p.changes = `cat CHANGELOG`[/^v([\d\.]+\. .*)/, 1]
38
+ #
39
+ # p.extra_deps = ["hpricot", "daemons"]
40
+ # p.need_tar = false
41
+ # p.need_tar_gz = true
42
+ #
43
+ # p.rdoc_pattern = /bin|lib|README|CHANGELOG|LICENSE/
44
+ #
45
+ # end
@@ -0,0 +1,125 @@
1
+ %w[open3 daemons socket singleton open-uri cgi pathname hpricot yaml net/https].map{|s| require s}
2
+
3
+ =begin rdoc
4
+ In-channel commands:
5
+ <tt>>> [string of code]</tt>:: Evaluate some Ruby code.
6
+ <tt>reset_irb</tt>:: Reset the <tt>irb</tt> session.
7
+ <tt>add_svn [repository_url]</tt>:: Watch an svn repository for changes.
8
+ =end
9
+
10
+ class Kirby
11
+ include Singleton
12
+
13
+ PATH = Pathname.new(".").dirname.realpath.to_s
14
+ STORE = PATH + '/kirby.repositories'
15
+ PIDFILE = PATH + '/kirby.pid'
16
+
17
+ NICK = (ARGV[1] or "kirby-dev")
18
+ CHANNEL = ("#" + (ARGV[2] or "kirby-dev"))
19
+ SERVER = (ARGV[3] or "irc.freenode.org")
20
+ DELICIOUS_USER, DELICIOUS_PASS = ARGV[4], ARGV[5]
21
+ SILENT = ARGV[6] == "--silent"
22
+
23
+ # Connect and reconnect to the server
24
+ def restart
25
+ $store = (YAML.load_file STORE rescue {})
26
+ @socket.close if @socket
27
+ connect
28
+ listen
29
+ end
30
+
31
+ # Connect to the IRC server.
32
+ def connect
33
+ @socket = TCPSocket.new(SERVER, 6667)
34
+ write "USER #{[NICK]*3*" "} :#{NICK}"
35
+ write "NICK #{NICK}"
36
+ write "JOIN #{CHANNEL}"
37
+ end
38
+
39
+ # The event loop. Waits for socket traffic, and then responds to it. The server sends <tt>PING</tt> every 3 minutes, which means we don't need a separate thread to check for svn updates. All we do is wake on ping (or channel talking).
40
+ def listen
41
+ @socket.each do |line|
42
+ # puts "GOT: #{line.inspect}"
43
+ poll unless SILENT
44
+ case line.strip
45
+ when /^PING/ then write line.sub("PING", "PONG")[0..-3]
46
+ when /^ERROR/, /KICK #{CHANNEL} #{NICK} / then restart unless line =~ /PRIVMSG/
47
+ else
48
+ if msg = line[/ PRIVMSG #{CHANNEL} \:(.+)/, 1]
49
+ case msg
50
+ when /^>>\s*(.+)/ then try $1.chop
51
+ when /^#{NICK}/ then say "Usage: '>> CODE'. Say 'reset_irb' for a clean session. Say 'add_svn [repository_url]' to watch an svn repository."
52
+ when /^reset_irb/ then reset_irb
53
+ when /^add_svn (.+?)(\s|\r|\n|$)/ then $store[$1] = 0 and say $store.inspect
54
+ end unless SILENT
55
+ post($1) if DELICIOUS_PASS and msg =~ /(http:\/\/.*?)(\s|\r|\n|$)/
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ # Send a raw string to the server.
62
+ def write s
63
+ raise RuntimeError, "No socket" unless @socket
64
+ @socket.puts s += "\r\n"
65
+ # puts "WROTE: #{s.inspect}"
66
+ end
67
+
68
+ # Eval a piece of code in the <tt>irb</tt> environment.
69
+ def try s
70
+ reset_irb unless $session
71
+ try_eval(s).select{|e| e !~ /^\s+from .+\:\d+(\:|$)/}.each {|e| say e} rescue say "session error"
72
+ end
73
+
74
+ # Say something in the channel.
75
+ def say s
76
+ write "PRIVMSG #{CHANNEL} :#{s[0..450]}"
77
+ sleep 1
78
+ end
79
+
80
+ # Get a new <tt>irb</tt> session.
81
+ def reset_irb
82
+ say "Began new irb session"
83
+ $session = try_eval("!INIT!IRB!")
84
+ end
85
+
86
+ # Inner loop of the try method.
87
+ def try_eval s
88
+ reset_irb and return [] if s.strip == "exit"
89
+ result = open("http://tryruby.hobix.com/irb?cmd=#{CGI.escape(s)}",
90
+ {'Cookie' => "_session_id=#{$session}"}).read
91
+ result[/^Your session has been closed/] ? (reset_irb and try_eval s) : result.split("\n")
92
+ end
93
+
94
+ # Look for svn changes.
95
+ def poll
96
+ return unless (Time.now - $last_poll > 15 rescue true)
97
+ $last_poll = Time.now
98
+ $store.each do |repo, last|
99
+ (Hpricot(`svn log #{repo} -rHEAD:#{last} --limit 10 --xml`)/:logentry).reverse[1..-1].each do |ci|
100
+ $store[repo] = rev = ci.attributes['revision'].to_i
101
+ say "Commit #{rev} to #{repo.split("/").last} by #{(ci/:author).text}: #{(ci/:msg).text}"
102
+ end rescue nil
103
+ end
104
+ File.open(STORE, 'w') {|f| f.puts YAML.dump($store)}
105
+ end
106
+
107
+ # Post a url to the del.icio.us account.
108
+ def post url
109
+ query = {:url => url,
110
+ :description => (((Hpricot(open(url))/:title).first.innerHTML or url) rescue url),
111
+ :tags => (Hpricot(open("http://del.icio.us/url/check?url=#{CGI.escape(url)}"))/'.alphacloud'/:a).map{|s| s.innerHTML}.join(" "),
112
+ :replace => 'yes' }
113
+ begin
114
+ http = Net::HTTP.new('api.del.icio.us', 443)
115
+ http.use_ssl = true
116
+ http.start do |http|
117
+ req = Net::HTTP::Get.new('/v1/posts/add?' + query.map{|k,v| "#{k}=#{CGI.escape(v)}"}.join('&'))
118
+ req.basic_auth DELICIOUS_USER, DELICIOUS_PASS
119
+ http.request(req)
120
+ end.body
121
+ end
122
+ end
123
+
124
+ end
125
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: kirby
5
+ version: !ruby/object:Gem::Version
6
+ version: "4"
7
+ date: 2007-08-12 00:00:00 -04:00
8
+ summary: A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us.
9
+ require_paths:
10
+ - lib
11
+ email: ""
12
+ homepage: http://blog.evanweaver.com/pages/code#kirby
13
+ rubyforge_project: fauna
14
+ description: A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - ""
31
+ files:
32
+ - lib/kirby.rb
33
+ - bin/kirby
34
+ - README
35
+ - LICENSE
36
+ - CHANGELOG
37
+ - kirby.gemspec
38
+ test_files: []
39
+
40
+ rdoc_options: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ executables:
45
+ - kirby
46
+ extensions: []
47
+
48
+ requirements: []
49
+
50
+ dependencies:
51
+ - !ruby/object:Gem::Dependency
52
+ name: hpricot
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Version::Requirement
55
+ requirements:
56
+ - - ">"
57
+ - !ruby/object:Gem::Version
58
+ version: 0.0.0
59
+ version:
60
+ - !ruby/object:Gem::Dependency
61
+ name: daemons
62
+ version_requirement:
63
+ version_requirements: !ruby/object:Gem::Version::Requirement
64
+ requirements:
65
+ - - ">"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.0.0
68
+ version: