-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9168f93
Showing
11 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'celluloid', :git => 'https://github.com/tarcieri/celluloid.git' | ||
|
||
# Specify your gem's dependencies in cellulon.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012 Tony Arcieri | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Cellulon | ||
|
||
TODO: Write a gem description | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
gem 'cellulon' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install cellulon | ||
|
||
## Usage | ||
|
||
TODO: Write usage instructions here | ||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Added some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'rubygems' | ||
require 'bundler/setup' | ||
|
||
require 'cinch' | ||
require 'celluloid' | ||
|
||
# The colors, Duke! The colors!1! | ||
module Tty extend self | ||
def escape(n); "\033[#{n}m" if STDOUT.tty? end | ||
def bold(n); escape "1;#{n}" end | ||
def blue; bold 34; end | ||
def white; bold 39; end | ||
def underline(n); escape "4;#{n}" end | ||
def red; underline 31; end | ||
def reset; escape 0; end | ||
def ohai(something) | ||
puts "#{Tty.blue}*** #{Tty.white}#{something}#{Tty.reset}" if STDOUT.tty? | ||
end | ||
end | ||
|
||
class Worker | ||
include Celluloid | ||
|
||
ROOT = File.expand_path '../..', __FILE__ | ||
TIMEOUT = 900 | ||
HOOK = /^![a-z][a-z0-9\-]*[a-z0-9]*/ | ||
|
||
def handle_message(msg) | ||
p msg | ||
hook = msg.message[HOOK] | ||
return unless hook | ||
|
||
|
||
args = msg.message.split(/\w+/) | ||
args.shift # remove the hook as an argument | ||
|
||
run hook, msg.user.nick, args do |response| | ||
msg.reply response | ||
end | ||
end | ||
|
||
def run(hook, user, args) | ||
script = File.join(ROOT, 'scripts', 'hooks', hook.sub(/^!/, '')) | ||
return unless File.executable?(script) | ||
|
||
Tty.ohai "Running #{hook} #{args.join(' ')}" | ||
|
||
Timeout.timeout TIMEOUT do | ||
Open3.popen2e({'CALLED_BY' => user}, script, *args) do |stdin, stdout| | ||
while line = stdout.gets | ||
line.force_encoding("UTF-8") if line.respond_to? :force_encoding | ||
line.strip! | ||
yield line | ||
end | ||
end | ||
end | ||
end | ||
|
||
alias_method :<<, :handle_message | ||
end | ||
|
||
pool = Celluloid::Pool.new Worker, :max_size => 10 | ||
|
||
bot = Cinch::Bot.new do | ||
configure do |c| | ||
c.nick = "cellulon" | ||
c.server = "irc.freenode.net" | ||
c.channels = ["#celluloid"] | ||
end | ||
|
||
on(:message) { |msg| pool.get! { |worker| worker << msg } } | ||
end | ||
|
||
bot.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- encoding: utf-8 -*- | ||
require File.expand_path('../lib/cellulon/version', __FILE__) | ||
|
||
Gem::Specification.new do |gem| | ||
gem.authors = ["Tony Arcieri"] | ||
gem.email = ["tony.arcieri@gmail.com"] | ||
gem.description = %q{TODO: Write a gem description} | ||
gem.summary = %q{TODO: Write a gem summary} | ||
gem.homepage = "" | ||
|
||
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
gem.files = `git ls-files`.split("\n") | ||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
gem.name = "cellulon" | ||
gem.require_paths = ["lib"] | ||
gem.version = Cellulon::VERSION | ||
|
||
gem.add_dependency 'cinch' | ||
gem.add_dependency 'celluloid' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "cellulon/version" | ||
|
||
module Cellulon | ||
# Your code goes here... | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Cellulon | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
echo "Hello there, $CALLED_BY" |