sandofsky-kirby 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/LICENSE +184 -0
- data/README +62 -0
- data/bin/kirby +47 -0
- data/kirby.gemspec +35 -0
- data/lib/kirby.rb +201 -0
- metadata +75 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
v4.2.1. Small fix for tryruby compatibility.
|
3
|
+
|
4
|
+
v4.2. Add channel logging; clean up options handling; fix docs.
|
5
|
+
|
6
|
+
v4.1. Watch atom feeds for git commits [lifo].
|
7
|
+
|
8
|
+
v4. Documentation; Rakefile. Shouldn't have bumped the version, but all right.
|
9
|
+
|
10
|
+
v3. del.icio.us integration.
|
11
|
+
|
12
|
+
v2. SVN rewrite.
|
13
|
+
|
14
|
+
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,62 @@
|
|
1
|
+
|
2
|
+
Kirby
|
3
|
+
|
4
|
+
A super-clean IRC bot.
|
5
|
+
|
6
|
+
== License
|
7
|
+
|
8
|
+
Copyright 2007, 2008 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file.
|
9
|
+
|
10
|
+
The public certificate for the gem is here[http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem].
|
11
|
+
|
12
|
+
If you use this software, please {make a donation}[http://blog.evanweaver.com/donate/], or {recommend Evan}[http://www.workingwithrails.com/person/7739-evan-weaver] at Working with Rails.
|
13
|
+
|
14
|
+
== Features
|
15
|
+
|
16
|
+
* <tt>irb</tt>-like interface
|
17
|
+
* safe, sandboxed Ruby environment
|
18
|
+
* svn and git-atom commit watching
|
19
|
+
* silent del.icio.us link saving
|
20
|
+
* tolerable channel fault recovery
|
21
|
+
|
22
|
+
Kirby is considered feature-locked.
|
23
|
+
|
24
|
+
== Installation
|
25
|
+
|
26
|
+
sudo gem install kirby
|
27
|
+
|
28
|
+
== Usage
|
29
|
+
|
30
|
+
To start a basic Kirby from the command line:
|
31
|
+
|
32
|
+
cd working/directory
|
33
|
+
kirby mynick mychannel myserver.org [delicious_user] [delicious_pass] [--options]
|
34
|
+
|
35
|
+
Logs and repository histories get saved to the working directory.
|
36
|
+
|
37
|
+
Available post-parameters are:
|
38
|
+
<tt>----daemon</tt>:: Daemonize.
|
39
|
+
<tt>----silent</tt>:: Never speak, even for errors.
|
40
|
+
<tt>----log</tt>:: Log channel chatter to a file.
|
41
|
+
<tt>----debug</tt>:: Debug mode.
|
42
|
+
|
43
|
+
See the Kirby class for in-channel commands.
|
44
|
+
|
45
|
+
== Crontab example
|
46
|
+
|
47
|
+
You can use a crontask to keep Kirby alive at all times. For example:
|
48
|
+
|
49
|
+
* * * * * bash -c 'cd /working/directory; kirby mynick mychannel irc.freenode.net \
|
50
|
+
--daemon --log --silent &> /dev/null'
|
51
|
+
|
52
|
+
== Reporting problems
|
53
|
+
|
54
|
+
The support forum is here[http://rubyforge.org/forum/forum.php?forum_id=13984].
|
55
|
+
|
56
|
+
Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC.
|
57
|
+
|
58
|
+
== Further resources
|
59
|
+
|
60
|
+
* http://blog.evanweaver.com/articles/2007/01/04/kirby-spies-your-svn
|
61
|
+
* http://blog.evanweaver.com/articles/2007/01/06/kirby-gets-a-del-icio-us-account
|
62
|
+
* http://blog.evanweaver.com/articles/2007/01/02/a-ruby-eval-bot-for-irc-kirby
|
data/bin/kirby
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
=begin rdoc
|
4
|
+
Run <tt>kirby [nick] [channel] [server] [optional del.icio.us name] [optional del.icio.us password]</tt>.
|
5
|
+
|
6
|
+
Optional post-parameters:
|
7
|
+
<tt>--daemon</tt>:: Daemonize.
|
8
|
+
<tt>--silent</tt>:: Never speak, even for errors.
|
9
|
+
<tt>--log</tt>:: Log channel chatter to a file.
|
10
|
+
<tt>--debug</tt>:: Debug mode.
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'daemons'
|
15
|
+
|
16
|
+
begin
|
17
|
+
require "#{File.dirname(__FILE__)}/../lib/kirby"
|
18
|
+
rescue LoadError
|
19
|
+
require 'kirby'
|
20
|
+
end
|
21
|
+
|
22
|
+
def option?(opt)
|
23
|
+
ARGV.include?("--#{opt}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def param(arg)
|
27
|
+
arg unless arg =~ /^--/
|
28
|
+
end
|
29
|
+
|
30
|
+
@kirby = Kirby.new(
|
31
|
+
:nick => param(ARGV[0]),
|
32
|
+
:channel => param(ARGV[1]),
|
33
|
+
:server => param(ARGV[2]),
|
34
|
+
:delicious_user => param(ARGV[3]),
|
35
|
+
:delicious_pass => param(ARGV[4]),
|
36
|
+
:silent => option?("silent"),
|
37
|
+
:debug => option?("debug"),
|
38
|
+
:log => option?("log")
|
39
|
+
)
|
40
|
+
|
41
|
+
pid = open(@kirby.config[:pidfile]).gets.chomp rescue nil
|
42
|
+
|
43
|
+
if !pid or `ps #{pid}`.split("\n").size < 2
|
44
|
+
Daemons.daemonize if option? "daemon"
|
45
|
+
open(@kirby.config[:pidfile], 'w') {|f| f.puts $$}
|
46
|
+
@kirby.restart
|
47
|
+
end
|
data/kirby.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{kirby}
|
3
|
+
s.version = "4.2.1"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Patched by Ben Sandofsky"]
|
7
|
+
s.date = %q{2008-01-30}
|
8
|
+
s.default_executable = %q{kirby}
|
9
|
+
s.description = %q{A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us.}
|
10
|
+
s.email = %q{sandofsky@gmail.com}
|
11
|
+
s.executables = ["kirby"]
|
12
|
+
s.files = ["lib/kirby.rb", "bin/kirby", "README", "LICENSE", "CHANGELOG", "kirby.gemspec"]
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/kirby/}
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.rubyforge_project = %q{fauna}
|
17
|
+
s.rubygems_version = %q{1.3.0}
|
18
|
+
s.summary = %q{A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us.}
|
19
|
+
|
20
|
+
if s.respond_to? :specification_version then
|
21
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
+
s.specification_version = 2
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
25
|
+
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
|
26
|
+
s.add_runtime_dependency(%q<daemons>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<hpricot>, [">= 0"])
|
29
|
+
s.add_dependency(%q<daemons>, [">= 0"])
|
30
|
+
end
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<hpricot>, [">= 0"])
|
33
|
+
s.add_dependency(%q<daemons>, [">= 0"])
|
34
|
+
end
|
35
|
+
end
|
data/lib/kirby.rb
ADDED
@@ -0,0 +1,201 @@
|
|
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>>> CODE</tt>:: evaluate code in IRB.
|
6
|
+
<tt>reset_irb</tt>:: get a clean IRB session.
|
7
|
+
<tt>add_svn [repository_url]</tt>:: watch an SVN repository.
|
8
|
+
<tt>add_atom [atom_feed_url]</tt>:: watch an atom feed, such as a Git repository
|
9
|
+
|
10
|
+
To remove a repository, manually kill the bot and delete the line from <tt>nick.svns</tt> or <tt>nick.atoms</tt> in the bot's working directory. Then restart the bot.
|
11
|
+
=end
|
12
|
+
|
13
|
+
class Kirby
|
14
|
+
|
15
|
+
attr_reader :config
|
16
|
+
|
17
|
+
# Make a new Kirby. Will not connect to the server until you call connect().
|
18
|
+
def initialize(opts = {})
|
19
|
+
|
20
|
+
# Defaults
|
21
|
+
path = File.expand_path(".").to_s
|
22
|
+
nick = opts[:nick] || config[:nick] || "kirby-dev"
|
23
|
+
|
24
|
+
@config ||= {
|
25
|
+
:svns => "#{path}/#{nick}.svns",
|
26
|
+
:atoms => "#{path}/#{nick}.atoms",
|
27
|
+
:pidfile => "#{path}/#{nick}.pid",
|
28
|
+
:nick => nick,
|
29
|
+
:channel => 'kirby-dev',
|
30
|
+
:server => "irc.freenode.org",
|
31
|
+
:delicious_user => nil,
|
32
|
+
:delicious_pass => nil,
|
33
|
+
:silent => false,
|
34
|
+
:log => false,
|
35
|
+
:logfile => "#{path}/#{nick}.log",
|
36
|
+
:time_format => '%Y/%m/%d %H:%M:%S',
|
37
|
+
:debug => false
|
38
|
+
}
|
39
|
+
|
40
|
+
# Nicely merge current options
|
41
|
+
opts.each do |key, value|
|
42
|
+
config[key] = value if value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Connect and reconnect to the server
|
47
|
+
def restart
|
48
|
+
log "Restarting"
|
49
|
+
puts config.inspect if config[:debug]
|
50
|
+
|
51
|
+
@svns = (YAML.load_file config[:svns] rescue {})
|
52
|
+
@atoms = (YAML.load_file config[:atoms] rescue {})
|
53
|
+
|
54
|
+
@socket.close if @socket
|
55
|
+
connect
|
56
|
+
listen
|
57
|
+
end
|
58
|
+
|
59
|
+
# Connect to the IRC server.
|
60
|
+
def connect
|
61
|
+
log "Connecting"
|
62
|
+
@socket = TCPSocket.new(config[:server], 6667)
|
63
|
+
write "USER #{config[:nick]} #{config[:nick]} #{config[:nick]} :#{config[:nick]}"
|
64
|
+
write "NICK #{config[:nick]}"
|
65
|
+
# Wait on PING
|
66
|
+
@socket.each do |line|
|
67
|
+
case line.strip
|
68
|
+
when /^PING/
|
69
|
+
write line.sub("PING", "PONG")[0..-3]
|
70
|
+
break
|
71
|
+
else
|
72
|
+
puts "GOT: #{line.inspect}" if config[:debug]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
write "JOIN ##{config[:channel]}"
|
76
|
+
end
|
77
|
+
|
78
|
+
# 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).
|
79
|
+
def listen
|
80
|
+
@socket.each do |line|
|
81
|
+
puts "GOT: #{line.inspect}" if config[:debug]
|
82
|
+
poll if !config[:silent]
|
83
|
+
case line.strip
|
84
|
+
when /^PING/
|
85
|
+
write line.sub("PING", "PONG")[0..-3]
|
86
|
+
when /^ERROR/, /KICK ##{config[:channel]} #{config[:nick]} /
|
87
|
+
restart unless line =~ /PRIVMSG/
|
88
|
+
when /:(.+?)!.* PRIVMSG ##{config[:channel]} \:\001ACTION (.+)\001/
|
89
|
+
log "* #{$1} #{$2}"
|
90
|
+
when /:(.+?)!.* PRIVMSG ##{config[:channel]} \:(.+)/
|
91
|
+
nick, msg = $1, $2
|
92
|
+
log "<#{nick}> #{msg}"
|
93
|
+
if !config[:silent]
|
94
|
+
case msg
|
95
|
+
when /^>>\s*(.+)/ then try $1
|
96
|
+
when /^#{config[:nick]}:/
|
97
|
+
["Usage:", " '>> CODE': evaluate code in IRB", " 'reset_irb': get a clean IRB session", " 'add_svn [repository_url]': watch an SVN repository", " 'add_atom [atom_feed_url]': watch an atom feed, such as a Git repository"].each {|s| say s}
|
98
|
+
when /^reset_irb/ then reset_irb
|
99
|
+
when /^add_svn (.+?)(\s|\r|\n|$)/ then @svns[$1] = 0 and say @svns.inspect
|
100
|
+
when /^add_atom (.+?)(\s|\r|\n|$)/ then @atoms[$1] = '' and say @atoms.inspect
|
101
|
+
when /(http:\/\/.*?)(\s|\r|\n|$)/ then post($1) if config[:delicious_pass]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Send a raw string to the server.
|
109
|
+
def write s
|
110
|
+
raise RuntimeError, "No socket" unless @socket
|
111
|
+
@socket.puts s += "\r\n"
|
112
|
+
puts "WROTE: #{s.inspect}" if config[:debug]
|
113
|
+
end
|
114
|
+
|
115
|
+
# Write a string to the log, if the logfile is open.
|
116
|
+
def log s
|
117
|
+
# Open log, if necessary
|
118
|
+
if config[:log]
|
119
|
+
puts "LOG: #{s}" if config[:debug]
|
120
|
+
File.open(config[:logfile], 'a') do |f|
|
121
|
+
f.puts "#{Time.now.strftime(config[:time_format])} #{s}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Eval a piece of code in the <tt>irb</tt> environment.
|
127
|
+
def try s
|
128
|
+
reset_irb unless @session
|
129
|
+
try_eval(s).select{|e| e !~ /^\s+from .+\:\d+(\:|$)/}.each {|e| say e} rescue say "session error"
|
130
|
+
end
|
131
|
+
|
132
|
+
# Say something in the channel.
|
133
|
+
def say s
|
134
|
+
write "PRIVMSG ##{config[:channel]} :#{s[0..450]}"
|
135
|
+
log "<#{config[:nick]}> #{s}"
|
136
|
+
sleep 1
|
137
|
+
end
|
138
|
+
|
139
|
+
# Get a new <tt>irb</tt> session.
|
140
|
+
def reset_irb
|
141
|
+
say "Began new irb session"
|
142
|
+
@session = try_eval("!INIT!IRB!")
|
143
|
+
end
|
144
|
+
|
145
|
+
# Inner loop of the try method.
|
146
|
+
def try_eval s
|
147
|
+
reset_irb and return [] if s.strip == "exit"
|
148
|
+
result = open("http://tryruby.hobix.com/irb?cmd=#{CGI.escape(s)}",
|
149
|
+
{'Cookie' => "_session_id=#{@session}"}).read
|
150
|
+
result[/^Your session has been closed/] ? (reset_irb and try_eval s) : result.split("\n")
|
151
|
+
end
|
152
|
+
|
153
|
+
# Look for SVN changes. Note that Rubyforge polls much better if you use the http:// protocol instead of the svn:// protocol for your repository.
|
154
|
+
def poll
|
155
|
+
return unless (Time.now - $last_poll > 60 rescue true)
|
156
|
+
$last_poll = Time.now
|
157
|
+
@svns.each do |repo, last|
|
158
|
+
puts "POLL: #{repo}" if config[:debug]
|
159
|
+
(Hpricot(`svn log #{repo} -rHEAD:#{last} --limit 10 --xml`)/:logentry).reverse[1..-1].each do |ci|
|
160
|
+
@svns[repo] = rev = ci.attributes['revision'].to_i
|
161
|
+
project = repo.split(/\.|\//).reject do |path|
|
162
|
+
['trunk', 'rubyforge', 'svn', 'org', 'com', 'net', 'http:', nil].include? path
|
163
|
+
end.last
|
164
|
+
say "Commit #{rev} to #{project || repo} by #{(ci/:author).text}: #{(ci/:msg).text}"
|
165
|
+
end rescue nil
|
166
|
+
end
|
167
|
+
File.open(config[:svns], 'w') {|f| f.puts YAML.dump(@svns)}
|
168
|
+
|
169
|
+
@atoms.each do |feed, last|
|
170
|
+
puts "POLL: #{feed}" if config[:debug]
|
171
|
+
begin
|
172
|
+
e = (Hpricot(open(feed))/:entry).first
|
173
|
+
@atoms[feed] = link = e.at("link")['href']
|
174
|
+
say "Commit #{link} by #{((e/:author)/:name).text}: #{(e/:title).text}" unless link == last
|
175
|
+
rescue
|
176
|
+
end
|
177
|
+
end
|
178
|
+
File.open(config[:atoms], 'w') {|f| f.puts YAML.dump(@atoms)}
|
179
|
+
end
|
180
|
+
|
181
|
+
# Post a url to the del.icio.us account.
|
182
|
+
def post url
|
183
|
+
puts "POST: #{url}" if config[:debug]
|
184
|
+
query = {:url => url,
|
185
|
+
:description => (((Hpricot(open(url))/:title).first.innerHTML or url) rescue url),
|
186
|
+
:tags => (Hpricot(open("http://del.icio.us/url/check?url=#{CGI.escape(url)}"))/'.alphacloud'/:a).map{|s| s.innerHTML}.join(" "),
|
187
|
+
:replace => 'yes' }
|
188
|
+
begin
|
189
|
+
http = Net::HTTP.new('api.del.icio.us', 443)
|
190
|
+
http.use_ssl = true
|
191
|
+
response = http.start do |http|
|
192
|
+
req = Net::HTTP::Get.new('/v1/posts/add?' + query.map{|k,v| "#{k}=#{CGI.escape(v)}"}.join('&'))
|
193
|
+
req.basic_auth config[:delicious_user], config[:delicious_pass]
|
194
|
+
http.request(req)
|
195
|
+
end.body
|
196
|
+
puts "POST: #{response.inspect}" if config[:debug]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sandofsky-kirby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patched by Ben Sandofsky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-30 00:00:00 -08:00
|
13
|
+
default_executable: kirby
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: daemons
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
description: A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us.
|
34
|
+
email: sandofsky@gmail.com
|
35
|
+
executables:
|
36
|
+
- kirby
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- lib/kirby.rb
|
43
|
+
- bin/kirby
|
44
|
+
- README
|
45
|
+
- LICENSE
|
46
|
+
- CHANGELOG
|
47
|
+
- kirby.gemspec
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://blog.evanweaver.com/files/doc/fauna/kirby/
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: fauna
|
70
|
+
rubygems_version: 1.2.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: A super-clean IRC bot with sandboxed Ruby evaluation, svn watching, and link-logging to del.icio.us.
|
74
|
+
test_files: []
|
75
|
+
|