ceiling_cat 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -96,4 +96,4 @@ module CeilingCat
96
96
  end
97
97
  end
98
98
  end
99
- end
99
+ end
@@ -4,8 +4,10 @@ module CeilingCat
4
4
  def handle
5
5
  if !super && event.type == :chat
6
6
  if match = self.class.list.find{|car| body =~ Regexp.new(car[:call],true) }
7
- response = [match[:response]].flatten # Support old responses which are strings, not arrays
8
- reply response[Kernel.rand(response.size)]
7
+ if Kernel.rand(10) >= (match[:frequency] || 0)
8
+ response = [match[:response]].flatten # Support old responses which are strings, not arrays
9
+ reply response[Kernel.rand(response.size)]
10
+ end
9
11
  return nil
10
12
  end
11
13
  end
@@ -13,8 +15,9 @@ module CeilingCat
13
15
 
14
16
  def self.commands
15
17
  [{:command => "list calls", :description => "List current calls and their responses", :method => "list"},
16
- {:command => "add call", :description => "Add an response to display when a phrase is said, split by a | - '!add call I see what you did there... | You caught me! | Oh no I'm busted!'", :method => "add"},
17
- {:command => "remove call", :description => "Remove an call and response by call '!remove call I see what you did there...'", :method => "remove"}]
18
+ {:command => "add call", :description => "Add a response to display when a phrase is said, split by a | - '!add call I see what you did there... | You caught me! | Oh no I'm busted!'", :method => "add"},
19
+ {:command => "add random call", :description => "Add a response to display a phrase X of every 10 times, split by a | - '!add random call 5 I see what you did there... | You caught me! | Oh no I'm busted!'", :method => "add_random"},
20
+ {:command => "remove call", :description => "Remove a call and response by call '!remove call I see what you did there...'", :method => "remove"}]
18
21
  end
19
22
 
20
23
  def self.description
@@ -36,7 +39,7 @@ module CeilingCat
36
39
  messages << "Current Calls and Responses"
37
40
  messages += store["call_and_responses"].collect{|car| "-- #{car[:call]} | #{[car[:response]].flatten.join(" | ")}"} # Support old responses which are strings, not arrays
38
41
  else
39
- messages << "There are no call and respones set up yet! You should add one with '!add call When someone says this | I say this | or this'"
42
+ messages << "There are no call and responses set up yet! You should add one with '!add call When someone says this | I say this | or this'"
40
43
  end
41
44
  reply messages
42
45
  end
@@ -47,7 +50,17 @@ module CeilingCat
47
50
  if self.class.add(:call => call.strip,:response => response.map(&:strip))
48
51
  reply "Call and Response added."
49
52
  else
50
- reply "Unable to add that call. A call and a response are required, split by a | - 'When someones says this | I say this | or this'"
53
+ reply "Unable to add that call. A call and a response are required, split by a | - '!add call When someone says this | I say this | or this'"
54
+ end
55
+ end
56
+
57
+ def add_random
58
+ message = body_without_nick_or_command("add random call")
59
+ x, frequency, call, *response = message.split(/(\d)\s+([^|]+)\|\s+(.+)/)
60
+ if self.class.add(:call => call.strip,:response => response.map(&:strip), :frequency => frequency.to_i)
61
+ reply "Call and Response added."
62
+ else
63
+ reply "Unable to add that call. A frequency, call, and response are required, split by a | - '!add random call 5 When someone says this | I say this | or this'"
51
64
  end
52
65
  end
53
66
 
@@ -63,7 +76,7 @@ module CeilingCat
63
76
  def self.add(opts={})
64
77
  return false unless opts[:call] && opts[:response]
65
78
  store["call_and_responses"] ||= []
66
- store["call_and_responses"] = (store["call_and_responses"] + [{:call => opts[:call], :response => opts[:response]}]).uniq
79
+ store["call_and_responses"] = (store["call_and_responses"] + [{:call => opts[:call], :response => opts[:response], :frequency => opts[:frequency]}]).uniq
67
80
  end
68
81
 
69
82
  def self.remove(call)
@@ -1,3 +1,3 @@
1
1
  module CeilingCat
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ceiling_cat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Warren
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-14 00:00:00 Z
18
+ date: 2012-05-01 00:00:00 -07:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: tinder
@@ -183,6 +184,7 @@ files:
183
184
  - setup/Chatfile
184
185
  - setup/Rakefile
185
186
  - bin/ceiling_cat
187
+ has_rdoc: true
186
188
  homepage: http://zencoder.com
187
189
  licenses: []
188
190
 
@@ -212,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
214
  requirements: []
213
215
 
214
216
  rubyforge_project:
215
- rubygems_version: 1.8.8
217
+ rubygems_version: 1.4.2
216
218
  signing_key:
217
219
  specification_version: 3
218
220
  summary: Ceiling Cat is watching you chat. A Campfire and IRC chat bot.