Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Send actions when a message starts with /me. Closes #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Dec 24, 2014
1 parent 4bae196 commit 1548503
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/lita/adapters/irc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,24 @@ def register_plugin
end
end

def send_message_to_target(target, string)
string_without_action = string.gsub(/^\/me\s+/i, "")

if string == string_without_action
target.msg(string)
else
target.action(string_without_action)
end
end

def send_messages_to_channel(target, strings)
channel = Cinch::Channel.new(target.room, cinch)
strings.each { |s| channel.msg(s) }
strings.each { |string| send_message_to_target(channel, string) }
end

def send_messages_to_user(target, strings)
user = Cinch::User.new(target.user.name, cinch)
strings.each { |s| user.msg(s) }
strings.each { |string| send_message_to_target(user, string) }
end
end

Expand Down
17 changes: 17 additions & 0 deletions spec/lita/adapters/irc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
subject.send_messages(source, ["Hello!", "How are you?"])
end

it "sends actions to rooms" do
source = instance_double("Lita::Source", room: "#foo", private_message?: false)
channel = instance_double("Cinch::Channel")
allow(Cinch::Channel).to receive(:new).with("#foo", subject.cinch).and_return(channel)
expect(channel).to receive(:action).with("greets you")
subject.send_messages(source, ["/me greets you"])
end

it "sends messages to users" do
user = instance_double("Lita::User", name: "Carl")
source = instance_double("Lita::Source", user: user, private_message?: true)
Expand All @@ -86,6 +94,15 @@
expect(user).to receive(:msg).with("How are you?")
subject.send_messages(source, ["Hello!", "How are you?"])
end

it "sends actions to users" do
user = instance_double("Lita::User", name: "Carl")
source = instance_double("Lita::Source", user: user, private_message?: true)
user = instance_double("Cinch::User")
allow(Cinch::User).to receive(:new).with("Carl", subject.cinch).and_return(user)
expect(user).to receive(:action).with("greets you")
subject.send_messages(source, ["/me greets you"])
end
end

describe "#set_topic" do
Expand Down

0 comments on commit 1548503

Please sign in to comment.