circus 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,79 @@ An event driven IRC gem without a DSL or any EOF magick
6
6
 
7
7
  Tim Sjoberg (bedlamp AT gmail.com)
8
8
 
9
+ == Quick How-to
10
+
11
+ Install the gem
12
+ gem install circus
13
+
14
+ How to connect
15
+ require 'circus'
16
+
17
+ irc = Circus::IRC.new
18
+ irc.connect
19
+
20
+ IRC#connect is a blocking call. It will only return when you're disconnected
21
+
22
+ IRC#new takes a bunch of config parameters in the form of a hash, their names should be self explanatory
23
+ :server
24
+ :port
25
+ :nick
26
+ :username
27
+ :realname
28
+ :sendspeed #length of time between messages. this is for flood protection. default is 0.5 seconds
29
+ :timeout #If this amount of time, in seconds, is reached, circus considers itself disconnected
30
+ :eol #the line delimiter. you should hopefully never need to change this
31
+ :debug #if this is set to true, circus will output everything it does in stdout
32
+ :password #this is the password for the irc server if there is one. default is unset
33
+
34
+ For example
35
+ irc = Circus::IRC.new :server => "irc.freenode.org", :nick => "Circus-IRC"
36
+
37
+ Alternatively, you can set the values after instantiation by calling #config_value=, for example
38
+ irc = Circus::IRC.new
39
+ irc.nick = "NewNick"
40
+ irc.server = "another.server.com"
41
+
42
+ To send stuff, you have a bunch of methods at your disposal. Each given with example parameters
43
+ irc.action "#circus", "jumps up and down" #does a ctcp ACTION, or /me in your irc client
44
+ irc.ctcp "user", "VERSION" #does a normal ctcp and puts in the \001s for you
45
+ irc.ctcp_reply "user", "VERSION Ruby using Circus-IRC 0.0.0"
46
+ irc.join "#circus"
47
+ irc.kick "#circus", "user", "no noobs allowed" #third parameter can be left out
48
+ irc.mode "#circus", "+o", "awesome_user" #third parameter optional. For example
49
+ irc.mode "Circus-IRC", "+B"
50
+ irc.nick "Circus-IRC"
51
+ irc.notice "user", "message"
52
+ irc.part "#circus"
53
+ irc.pass "password" #you shouldn't need to use this. use the password config value
54
+ irc.pong "value" #you also never need to use this. this is already handled
55
+ irc.privmsg "#circus", "Hello"
56
+ irc.quit "reason"
57
+ irc.raw "DCCALLOW +user" #for all those pesky additions
58
+ irc.topic "#circus", "New topic for channel #circus"
59
+ irc.user "user 0 * realname" #again, you shouldn't need this. use the config values
60
+
61
+ As previously mentioned, it is event driven. Before calling connect, you can subscribe to any number of events, or multiple times to the same event. For a full list look in lib/irc/commands.rb. You can pass subscribe the string or the symbol version, for example
62
+ irc.subscribe(:ENDOFMOTD) do
63
+ irc.join "#circus"
64
+ end
65
+
66
+ or
67
+ irc.subscribe("376") do
68
+ irc.join "#circus"
69
+ end
70
+
71
+ You are going to need to know how many arguments a block is expecting if you are going to use them. Unfortunately the only way to this is to know the irc protocol, or trial and error. As an example, to create an echo bot (in channels only):
72
+ irc.subscribe(:PRIVMSG) do |message, sender, receiver|
73
+ if receiver =~ /^#/
74
+ irc.privmsg receiver, message
75
+ end
76
+ end
77
+
78
+ ==Disclaimer
79
+
80
+ This gem is not designed to make it really easy to write irc bots, its designed to make it really easy to build a framework to create irc bots. This gem has been tested working in ruby 1.9
81
+
9
82
  == License
10
83
 
11
84
  This software is distributed under the BEER-WARE license. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{circus}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tim Sjoberg"]
12
- s.date = %q{2010-07-01}
12
+ s.date = %q{2010-07-02}
13
13
  s.description = %q{A relatively simple event driven irc gem without a DSL or any EOF magick}
14
14
  s.email = %q{bedlamp@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
48
48
  "lib/irc/messages/user.rb",
49
49
  "lib/irc/parser.rb",
50
50
  "spec/circus_spec.rb",
51
+ "spec/irc_spec.rb",
51
52
  "spec/spec.opts",
52
53
  "spec/spec_helper.rb"
53
54
  ]
@@ -57,7 +58,8 @@ Gem::Specification.new do |s|
57
58
  s.rubygems_version = %q{1.3.7}
58
59
  s.summary = %q{A relatively simple event driven irc gem}
59
60
  s.test_files = [
60
- "spec/circus_spec.rb",
61
+ "spec/irc_spec.rb",
62
+ "spec/circus_spec.rb",
61
63
  "spec/spec_helper.rb"
62
64
  ]
63
65
 
data/lib/irc.rb CHANGED
@@ -13,7 +13,7 @@ module Circus
13
13
  class IRC
14
14
 
15
15
  def initialize(options = {})
16
- @default = { :server => "za.shadowfire.org",
16
+ @default = { :server => "irc.freenode.net",
17
17
  :port => 6667,
18
18
  :nick => "Circus-IRC",
19
19
  :username => "circus",
@@ -43,6 +43,12 @@ module Circus
43
43
  @event_manager.subscribe(type, &block)
44
44
  end
45
45
 
46
+ %w(server port nick username realname send_speed timeout eol debug password).each do |config_value|
47
+ define_method("#{config_value}=".to_sym) do |new_value|
48
+ @config[config_value.to_sym] = new_value
49
+ end
50
+ end
51
+
46
52
  def method_missing(name, *args)
47
53
  message_class = "Circus::Messages::#{name.to_s.downcase.classify}"
48
54
  message_class = message_class.constantize
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Circus::IRC, "#new without parameters" do
4
+ before(:each) do
5
+ @irc = Circus::IRC.new
6
+ end
7
+
8
+ it "defines default values if none are given" do
9
+ config = @irc.instance_variable_get("@config")
10
+ config[:server].should == "irc.freenode.net"
11
+ config[:port].should == 6667
12
+ config[:nick].should == "Circus-IRC"
13
+ config[:username].should == "circus"
14
+ config[:realname].should == "Using ruby with Circus IRC"
15
+ config[:send_speed].should == 0.5
16
+ config[:timeout].should == 15*60
17
+ config[:eol].should == "\r\n"
18
+ config[:debug].should == false
19
+ end
20
+
21
+ it "should not define a password if none is given" do
22
+ @irc.instance_variable_get("@config")[:password].should be_nil
23
+ end
24
+
25
+ it "should update the config value when calling .param=" do
26
+ @irc.instance_variable_get("@config")[:nick].should == "Circus-IRC"
27
+ @irc.nick = "NewNick"
28
+ @irc.instance_variable_get("@config")[:nick].should == "NewNick"
29
+
30
+ @irc.instance_variable_get("@config")[:password].should be_nil
31
+ @irc.password = "secret"
32
+ @irc.instance_variable_get("@config")[:password].should == "secret"
33
+
34
+ #if nick and password work, they should all work. now we just need to check that the methods exist
35
+ %w(server port nick username realname send_speed timeout eol debug password).each do |config_value|
36
+ fail "no method #{config_value}= defined" unless @irc.respond_to?("#{config_value}=".to_sym)
37
+ end
38
+ end
39
+ end
@@ -1,10 +1,9 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
1
  require 'rubygems'
4
- require 'circus'
5
2
  require 'spec'
6
3
  require 'spec/autorun'
7
4
 
5
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'circus')
6
+
8
7
  Spec::Runner.configure do |config|
9
8
 
10
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 0.0.0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Sjoberg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-01 00:00:00 +02:00
18
+ date: 2010-07-02 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -91,6 +91,7 @@ files:
91
91
  - lib/irc/messages/user.rb
92
92
  - lib/irc/parser.rb
93
93
  - spec/circus_spec.rb
94
+ - spec/irc_spec.rb
94
95
  - spec/spec.opts
95
96
  - spec/spec_helper.rb
96
97
  has_rdoc: true
@@ -128,5 +129,6 @@ signing_key:
128
129
  specification_version: 3
129
130
  summary: A relatively simple event driven irc gem
130
131
  test_files:
132
+ - spec/irc_spec.rb
131
133
  - spec/circus_spec.rb
132
134
  - spec/spec_helper.rb