Skip to content

Commit 9c2463f

Browse files
committed
Rename channel to room to be more in line with Campfire and it's API
1 parent a59ec60 commit 9c2463f

File tree

9 files changed

+146
-145
lines changed

9 files changed

+146
-145
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Matchers are tested in order and all that satisfy the match and conditions will
3030
end
3131
3232
#
33-
# A special user and channel method is available in match blocks.
33+
# A special user and room method is available in match blocks.
3434
#
3535
match "a user said" do
36-
say "#{user} said something in channel #{channel}"
36+
say "#{user} said something in room #{room}"
3737
end
3838
3939
match "Hello!" do
@@ -48,17 +48,17 @@ Matchers are tested in order and all that satisfy the match and conditions will
4848
end
4949
5050
#
51-
# Limit the match to certain channels, users or both.
51+
# Limit the match to certain rooms, users or both.
5252
#
53-
match /^Lets match (.+)$/, :conditions => {:channel => "Some Channel"} do
54-
say "Only said if channel name mathces /someregex/"
53+
match /^Lets match (.+)$/, :conditions => {:room => "Some Room"} do
54+
say "Only said if room name mathces /someregex/"
5555
end
5656
5757
match "some text", :conditions => {:user => "Some User"} do
5858
say "Only said if user name mathces /someregex/"
5959
end
6060
61-
match /some other text/, :conditions => {:user => "Some User", :channel => 123456} do
61+
match /some other text/, :conditions => {:user => "Some User", :room => 123456} do
6262
say "You can mix conditions"
6363
end
6464
@@ -70,13 +70,13 @@ Matchers are tested in order and all that satisfy the match and conditions will
7070
end
7171
7272
#
73-
# You can say multiple times, and you can specify an alternate channel.
74-
# Default behaviour is to 'say' in the channel that caused the match.
73+
# You can say multiple times, and you can specify an alternate room.
74+
# Default behaviour is to 'say' in the room that caused the match.
7575
#
7676
match "something" do
77-
say "#{user} said something in channel #{channel}"
78-
say "#{user} said something in channel #{channel}", 237872
79-
say "#{user} said something in channel #{channel}", "System Administration"
77+
say "#{user} said something in room #{room}"
78+
say "#{user} said something in room #{room}", 237872
79+
say "#{user} said something in room #{room}", "System Administration"
8080
end
8181
8282
#
@@ -95,27 +95,27 @@ Matchers are tested in order and all that satisfy the match and conditions will
9595
end
9696
end
9797
98-
# Connect and join some channels
98+
# Connect and join some rooms
9999
scamp.connect!([293788, "Monitoring"])
100100

101-
In the channel/user conditions you can use the name, regex or ID of a user or channel, in say you can ise a string or ID, eg:
101+
In the room/user conditions you can use the name, regex or ID of a user or room, in say you can ise a string or ID, eg:
102102

103-
:conditions => {:channel => /someregex/}
104-
:conditions => {:channel => "some string"}
105-
:conditions => {:channel => 123456}
103+
:conditions => {:room => /someregex/}
104+
:conditions => {:room => "some string"}
105+
:conditions => {:room => 123456}
106106

107107
:conditions => {:user => /someregex/}
108108
:conditions => {:user => "some string"}
109109
:conditions => {:user => 123456}
110110

111-
say "#{user} said something in channel #{channel}", 237872
112-
say "#{user} said something in channel #{channel}", "System Administration"
111+
say "#{user} said something in room #{room}", 237872
112+
say "#{user} said something in room #{room}", "System Administration"
113113

114114
By default Scamp listens to itself. This could either be fun, or dangerous, you decide. You can turn this off by passing :first\_match\_only => true in the initialisation options
115115

116116
scamp = Scamp.new(:api_key => "YOUR API KEY", :subdomain => "yoursubdomain", :first_match_only => true)
117117

118-
Scamp will listen to all messages that are sent on the channels it is listening on and doesn't need to be addressed by name. If you prefer to only trigger bot commands when you address your bot directly add the :required\_prefix initialisation option:
118+
Scamp will listen to all messages that are sent on the rooms it is listening on and doesn't need to be addressed by name. If you prefer to only trigger bot commands when you address your bot directly add the :required\_prefix initialisation option:
119119

120120
scamp = Scamp.new(:api_key => "YOUR API KEY", :subdomain => "yoursubdomain", :required_prefix => 'Bot: ')
121121

@@ -124,7 +124,7 @@ Scamp will now require commands to begin with 'Bot: ' (or whatever you have spec
124124
## TODO
125125

126126
* Write more tests
127-
* Allow multiple values for conditions, eg: :conditions => {:channel => ["This channel", "Some channel"]}
127+
* Allow multiple values for conditions, eg: :conditions => {:room => ["This room", "Some room"]}
128128
* Add paste support
129129

130130
## Known issues

examples/bot.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
scamp = Scamp.new(:api_key => "YOUR API KEY", :subdomain => "37s")
88

99
scamp.behaviour do
10-
# Match some regex limited to a channel condition based on a channel id
11-
match /^channel id (.+)$/, :conditions => {:channel => 401839} do
12-
# Reply in the current channel
13-
say "Match some regex limited to a channel condition based on a channel id"
10+
# Match some regex limited to a room condition based on a room id
11+
match /^room id (.+)$/, :conditions => {:room => 401839} do
12+
# Reply in the current room
13+
say "Match some regex limited to a room condition based on a room id"
1414
end
1515

16-
# Limit a match to a channel condition based on a string
17-
match "channel name check", :conditions => {:channel => "Monitoring"} do
18-
say "Limit a match to a channel condition based on a string"
16+
# Limit a match to a room condition based on a string
17+
match "room name check", :conditions => {:room => "Monitoring"} do
18+
say "Limit a match to a room condition based on a string"
1919
end
2020

2121
# Limit a match to a user condition based on a string
@@ -28,10 +28,10 @@
2828
say "Limit a match to a user condition based on an ID"
2929
end
3030

31-
# Limit a match to a channel & user condition combined
32-
match /^something (.+)$/, :conditions => {:channel => "Monitoring", :user => "Will Jessop"} do
33-
# Reply in the current channel
34-
say "Limit a match to a channel & user condition combined"
31+
# Limit a match to a room & user condition combined
32+
match /^something (.+)$/, :conditions => {:room => "Monitoring", :user => "Will Jessop"} do
33+
# Reply in the current room
34+
say "Limit a match to a room & user condition combined"
3535
end
3636

3737
# Match text with a regex, access the captures from the match object
@@ -44,16 +44,16 @@
4444
say "You said #{yousaid}"
4545
end
4646

47-
# Simple string match, interpolating the channel and user in response.
47+
# Simple string match, interpolating the room and user in response.
4848
match "something" do |data|
49-
# Send the response to a different channel
50-
say "#{user} said something in channel #{channel}", "Robot Army"
49+
# Send the response to a different room
50+
say "#{user} said something in room #{room}", "Robot Army"
5151

52-
# Send the response to a different channel, using the channel ID
53-
say "#{user} said something in channel #{channel}", 293788
52+
# Send the response to a different room, using the room ID
53+
say "#{user} said something in room #{room}", 293788
5454

55-
# Send the response to the originating channel
56-
say "#{user} said something in channel #{channel}"
55+
# Send the response to the originating room
56+
say "#{user} said something in room #{room}"
5757
end
5858

5959
# Play some sounds
@@ -62,11 +62,11 @@
6262
play "drama"
6363
end
6464

65-
match "multi-condition match", :conditions => {:channel => [401839, "Monitoring"], :user => ["Will Jessop", "Noah Lorang"]} do
66-
# Reply in the current channel
65+
match "multi-condition match", :conditions => {:room => [401839, "Monitoring"], :user => ["Will Jessop", "Noah Lorang"]} do
66+
# Reply in the current room
6767
say "multi-condition match"
6868
end
6969
end
7070

71-
# FIXME: this does if the channel doesn't exist. Need a better error.
71+
# FIXME: this does if the room doesn't exist. Need a better error.
7272
scamp.connect!([293788, "Monitoring"])

lib/scamp.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55

66
require "scamp/version"
77
require 'scamp/connection'
8-
require 'scamp/channels'
8+
require 'scamp/rooms'
99
require 'scamp/users'
1010
require 'scamp/matcher'
1111
require 'scamp/action'
1212
require 'scamp/messages'
1313

1414
class Scamp
1515
include Connection
16-
include Channels
16+
include Rooms
1717
include Users
1818
include Messages
1919

20-
attr_accessor :channels, :user_cache, :channel_cache, :matchers, :api_key, :subdomain,
21-
:logger, :verbose, :first_match_only, :required_prefix, :channels_to_join
20+
attr_accessor :rooms, :user_cache, :room_cache, :matchers, :api_key, :subdomain,
21+
:logger, :verbose, :first_match_only, :required_prefix, :rooms_to_join
2222

2323
def initialize(options = {})
2424
options ||= {}
@@ -34,20 +34,20 @@ def initialize(options = {})
3434
end
3535
end
3636

37-
@channels_to_join = []
38-
@channels = {}
37+
@rooms_to_join = []
38+
@rooms = {}
3939
@user_cache = {}
40-
@channel_cache = {}
40+
@room_cache = {}
4141
@matchers ||= []
4242
end
4343

4444
def behaviour &block
4545
instance_eval &block
4646
end
4747

48-
def connect!(channel_list)
48+
def connect!(room_list)
4949
logger.info "Starting up"
50-
connect(api_key, channel_list)
50+
connect(api_key, room_list)
5151
end
5252

5353
def command_list

lib/scamp/action.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Actions are run in the context of a Scamp::Action.
3-
# This allows us to make channel, user etc. methods
3+
# This allows us to make room, user etc. methods
44
# available on a per-message basis
55
#
66

@@ -27,12 +27,12 @@ def matches=(match)
2727
end if match.respond_to?(:names) # 1.8 doesn't support named captures
2828
end
2929

30-
def channel_id
30+
def room_id
3131
@message[:room_id]
3232
end
3333

34-
def channel
35-
bot.channel_name_for @message[:room_id]
34+
def room
35+
bot.room_name_for @message[:room_id]
3636
end
3737

3838
def user
@@ -57,12 +57,12 @@ def command_list
5757
bot.command_list
5858
end
5959

60-
def say(msg, channel_id_or_name = channel_id)
61-
bot.say(msg, channel_id_or_name)
60+
def say(msg, room_id_or_name = room_id)
61+
bot.say(msg, room_id_or_name)
6262
end
6363

64-
def play(sound, channel_id_or_name = channel_id)
65-
bot.play(sound, channel_id_or_name)
64+
def play(sound, room_id_or_name = room_id)
65+
bot.play(sound, room_id_or_name)
6666
end
6767
end
6868
end

lib/scamp/connection.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ class Scamp
22
module Connection
33
private
44

5-
def connect(api_key, channel_list)
5+
def connect(api_key, room_list)
66
EventMachine.run do
77

8-
# Check for channels to join, and join them
8+
# Check for rooms to join, and join them
99
EventMachine::add_periodic_timer(5) do
10-
while id = @channels_to_join.pop
10+
while id = @rooms_to_join.pop
1111
join_and_stream(id)
1212
end
1313
end
1414

15-
populate_channel_list do
16-
logger.debug "Adding #{channel_list.join ', '} to list of channels to join"
17-
@channels_to_join = channel_list.map{|c| channel_id(c) }
15+
populate_room_list do
16+
logger.debug "Adding #{room_list.join ', '} to list of rooms to join"
17+
@rooms_to_join = room_list.map{|c| room_id(c) }
1818
end
1919

2020
end

lib/scamp/matcher.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ def run(msg, match = nil)
6868
def conditions_satisfied_by(msg)
6969
bot.logger.debug "Checking message against #{conditions.inspect}"
7070

71-
# item will be :user or :channel
71+
# item will be :nick or :room
7272
# cond is the int or string value.
7373
conditions.each do |item, cond|
7474
bot.logger.debug "Checking #{item} against #{cond}"
7575
bot.logger.debug "msg is #{msg.inspect}"
7676
if cond.is_a? Integer
77-
# bot.logger.debug "item is #{msg[{:channel => :room_id, :user => :user_id}[item]]}"
78-
return false unless msg[{:channel => :room_id, :user => :user_id}[item]] == cond
77+
# bot.logger.debug "item is #{msg[{:room => :room_id, :user => :user_id}[item]]}"
78+
return false unless msg[{:room => :room_id, :user => :user_id}[item]] == cond
7979
elsif cond.is_a? String
8080
case item
81-
when :channel
82-
return false unless bot.channel_name_for(msg[:room_id]) == cond
81+
when :room
82+
return false unless bot.room_name_for(msg[:room_id]) == cond
8383
when :user
8484
return false unless bot.username_for(msg[:user_id]) == cond
8585
end

lib/scamp/messages.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
class Scamp
22
module Messages
33

4-
def say(message, channel_id_or_name)
5-
send_message(channel_id_or_name, message, "Textmessage")
4+
def say(message, room_id_or_name)
5+
send_message(room_id_or_name, message, "Textmessage")
66
end
77

8-
def play(sound, channel_id_or_name)
9-
send_message(channel_id_or_name, sound, "SoundMessage")
8+
def play(sound, room_id_or_name)
9+
send_message(room_id_or_name, sound, "SoundMessage")
1010
end
1111

1212
private
1313

1414
# curl -vvv -H 'Content-Type: application/json' -d '{"message":{"body":"Yeeeeeaaaaaahh", "type":"Textmessage"}}' -u API_KEY:X https://37s.campfirenow.com/room/293788/speak.json
15-
def send_message(channel_id_or_name, payload, type)
15+
def send_message(room_id_or_name, payload, type)
1616
# post 'speak', :body => {:message => {:body => message, :type => type}}.to_json
17-
url = "https://#{subdomain}.campfirenow.com/room/#{channel_id(channel_id_or_name)}/speak.json"
17+
url = "https://#{subdomain}.campfirenow.com/room/#{room_id(room_id_or_name)}/speak.json"
1818
http = EventMachine::HttpRequest.new(url).post :head => {'Content-Type' => 'application/json', 'authorization' => [api_key, 'X']}, :body => Yajl::Encoder.encode({:message => {:body => payload, :type => type}})
19-
http.errback { logger.error "Error speaking: '#{message}' to #{channel_id(channel_id_or_name)}" }
19+
http.errback { logger.error "Error speaking: '#{message}' to #{room_id(room_id_or_name)}" }
2020
end
2121

2222
end

0 commit comments

Comments
 (0)