Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed up the extension examples

  • Loading branch information...
commit 696428dbca86dc44b81249c62198852fb2a7649f 1 parent 7e24664
@andrewhavens authored
View
2  lib/mad_chatter.rb
@@ -95,7 +95,7 @@ def message_received(json)
begin
message_listeners.each do |listener|
- listener.message = message
+ listener.message = message if listener.respond_to?('message=')
listener.handle(message)
end
send_message(message)
View
10 lib/mad_chatter/extension.rb
@@ -29,16 +29,20 @@ def stop_message_handling
def send_message(text, from = nil)
m = MadChatter::Message.new('message', text)
- m.username = from
+ m.username = from || @message.username
+ m.channel = @message.channel
MadChatter.send_message(m)
end
def send_status_message(text)
- MadChatter.send_message MadChatter::Message.new('status', text)
+ MadChatter.send_message MadChatter::Message.new('status', text, nil, @message.channel)
end
def send_action(action, *args)
- MadChatter.send_message MadChatter::Message.new('action', {function: action, args: args})
+ m = MadChatter::Message.new('action')
+ m.json = {function: action, args: args}
+ m.channel = @message.channel
+ MadChatter.send_message(m)
end
end
end
View
3  lib/mad_chatter/message.rb
@@ -3,7 +3,7 @@
module MadChatter
class Message
- attr_accessor :type, :original_text, :filtered_text, :html, :token, :channel, :growl, :add_to_history, :timestamp
+ attr_accessor :type, :original_text, :filtered_text, :html, :json, :token, :channel, :growl, :add_to_history, :timestamp
def initialize(type, text = nil, token = nil, channel_id = nil)
@type = type
@@ -46,6 +46,7 @@ def to_json
type: @type,
text: @original_text,
html: @html,
+ json: @json,
username: username,
channel: @channel,
growl: @growl,
View
1  templates/extensions/earthquake.rb
@@ -2,7 +2,6 @@ class Earthquake < MadChatter::Extension
def handle(message)
if message.text == '/earthquake'
- puts 'earthquaking!!'
send_status_message "#{message.username} has just caused an earthquake!"
send_action 'earthquake' # call a javascript function named 'earthquake'
stop_message_handling
Please sign in to comment.
Something went wrong with that request. Please try again.