lita-irc 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1dda3d72d7f84dbdca6634ffe3c0a7f81f921b7
4
- data.tar.gz: 19412c2a25b7f5ad4e2425deba288befe116aed5
3
+ metadata.gz: e0a865facace3feffa91ae8cc81287d681fe3c61
4
+ data.tar.gz: 809a00601267a205bdf791477f72747ec7131544
5
5
  SHA512:
6
- metadata.gz: 5d762ba6efad744c31edbd794cb754e3d428169e7f2819cce642fc6832d7c6c6d85e8d2a62c34d123050e621d31d5d22a67da1d6acf9dd2dd3245e08f7249768
7
- data.tar.gz: 41add8b7a2cfd4c0f8ee4a90fdbd196c54d9c4fd64da644053ff6de4f59608fd5337838c648f0aee1e9ef5e9377455f08f8bc0d5c7e3cef80183431fc8854573
6
+ metadata.gz: 56cab612f6ea4f500d32b3b18d4145c2bb64188140453241e02f97baa6d0e8dcc7fc43bdae29d32255b5a4a402a8cdc94e2ded85a406f55fa579133c77c14d1e
7
+ data.tar.gz: 998b501189c377bf9122dafad0ecf8abf0b4d70954617346f693f059c62e1c059417bb04ae91a9a56fb8d6ae473946e01a4959a94a44a4c3435879da3ab775ad
data/README.md CHANGED
@@ -60,11 +60,14 @@ end
60
60
 
61
61
  The IRC adapter will trigger these events:
62
62
 
63
- | Event | When | Payload |
64
- |------------------------|---------------------------|----------------------------------------|
65
- | `:connected` | connected to IRC | None |
66
- | `:disconnected` | disconnected from IRC | None |
67
- | `:user_joined_room` | a user joins a room | `user: Lita::User`, `room: Lita::Room` |
63
+ | Event | When | Payload |
64
+ |------------------------|---------------------------|---------------------------------------------|
65
+ | `:connected` | connected to IRC | None |
66
+ | `:disconnected` | disconnected from IRC | None |
67
+ | `:user_joined_room` | a user joins a room | `user: Lita::User`, `room: Lita::Room` |
68
+ | `:user_parted_room` | a user parts a room | `user: Lita::User`, `room: Lita::Room` |
69
+ | `:user_disconnected` | a user disconnects | `user: Lita::User` |
70
+ | `:user_nick_changed` | a user changes nick | `user: Lita::User`, `old_user: Lita::User` |
68
71
 
69
72
  ## License
70
73
 
@@ -10,6 +10,9 @@ module Lita
10
10
  listen_to :connect, method: :on_connect
11
11
  listen_to :invite, method: :on_invite
12
12
  listen_to :join, method: :on_room_join
13
+ listen_to :part, method: :on_room_part
14
+ listen_to :quit, method: :on_quit
15
+ listen_to :nick, method: :on_nick_change
13
16
 
14
17
  def execute(m)
15
18
  body = get_body(m)
@@ -36,6 +39,29 @@ module Lita
36
39
  )
37
40
  end
38
41
 
42
+ def on_room_part(m)
43
+ robot.trigger(
44
+ :user_parted_room,
45
+ user: user_by_nick(m.user.nick),
46
+ room: Lita::Room.create_or_update(m.channel.name, name: m.channel.name),
47
+ )
48
+ end
49
+
50
+ def on_quit(m)
51
+ robot.trigger(
52
+ :user_disconnected,
53
+ user: user_by_nick(m.user.nick),
54
+ )
55
+ end
56
+
57
+ def on_nick_change(m)
58
+ robot.trigger(
59
+ :user_nick_changed,
60
+ old_user: user_by_nick(m.prefix.gsub(/!.*/, '')),
61
+ user: user_by_nick(m.user.nick),
62
+ )
63
+ end
64
+
39
65
  private
40
66
 
41
67
  def dispatch(message)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-irc"
3
- spec.version = "2.1.0"
3
+ spec.version = "2.2.0"
4
4
  spec.authors = ["Jimmy Cuadra"]
5
5
  spec.email = ["jimmy@jimmycuadra.com"]
6
6
  spec.description = %q{An IRC adapter for Lita.}
@@ -7,6 +7,8 @@ describe Lita::Adapters::IRC::CinchPlugin do
7
7
  let(:robot) { double("Lita::Robot", auth: authorization) }
8
8
  let(:cinch) { double("Cinch::Bot").as_null_object }
9
9
  let(:user) { double("Lita::User", name: "Carl") }
10
+ let(:old_user) { double("Lita::User", name: "Dora") }
11
+ let(:prefix) { "#{old_user.name}!#{old_user.name.downcase}@localhost" }
10
12
  let(:message) { double("Lita::Message", command!: nil, source: source) }
11
13
  let(:source) { double("Lita::Source", room: "#channel", user: user) }
12
14
  let(:room) { double("Lita::Room", name: "#channel") }
@@ -17,6 +19,7 @@ describe Lita::Adapters::IRC::CinchPlugin do
17
19
  message: "bar",
18
20
  action?: false,
19
21
  channel: cinch_channel,
22
+ prefix: prefix,
20
23
  user: cinch_user
21
24
  )
22
25
  end
@@ -98,4 +101,51 @@ describe Lita::Adapters::IRC::CinchPlugin do
98
101
  subject.on_room_join(m)
99
102
  end
100
103
  end
104
+
105
+ describe "#on_room_part" do
106
+ before do
107
+ allow(Lita::Room).to receive(:create_or_update).and_return(room)
108
+ allow(Lita::User).to receive(:find_by_name).and_return(user)
109
+ end
110
+
111
+ it "triggers a part event when someone parts a channel" do
112
+ expect(robot).to receive(:trigger).with(
113
+ :user_parted_room,
114
+ user: user,
115
+ room: room,
116
+ )
117
+ subject.on_room_part(m)
118
+ end
119
+ end
120
+
121
+ describe "#on_quit" do
122
+ before do
123
+ allow(Lita::User).to receive(:find_by_name).and_return(user)
124
+ end
125
+
126
+ it "triggers a disconnect event when someone quits from the IRC server" do
127
+ expect(robot).to receive(:trigger).with(
128
+ :user_disconnected,
129
+ user: user,
130
+ )
131
+ subject.on_quit(m)
132
+ end
133
+ end
134
+
135
+ describe "#on_nick_change" do
136
+ before do
137
+ allow(Lita::User).to receive(:find_by_name).with(user.name).and_return(user)
138
+ allow(Lita::User).to receive(:find_by_name).with(old_user.name).and_return(old_user)
139
+ end
140
+
141
+ it "triggers a nick changed event when someone changes nick" do
142
+ expect(robot).to receive(:trigger).with(
143
+ :user_nick_changed,
144
+ old_user: old_user,
145
+ user: user,
146
+ )
147
+ expect(old_user.name).to eq("Dora")
148
+ subject.on_nick_change(m)
149
+ end
150
+ end
101
151
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-irc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-09 00:00:00.000000000 Z
11
+ date: 2017-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita