cinch-seen 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,9 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Cinch
2
3
  module Plugins
4
+ # Versioning Info
3
5
  class Seen
4
- VERSION = "1.0.1"
6
+ VERSION = '1.0.2'
5
7
  end
6
8
  end
7
9
  end
@@ -6,12 +6,19 @@ require 'cinch/cooldown'
6
6
  require 'time-lord'
7
7
 
8
8
  module Cinch::Plugins
9
+ # plugin to allow users to see when other users were last active
9
10
  class Seen
10
11
  include Cinch::Plugin
11
12
 
13
+ class Activity < Struct.new(:nick, :time, :message)
14
+ def to_yaml
15
+ { nick: nick, time: time, message: message }
16
+ end
17
+ end
18
+
12
19
  enforce_cooldown
13
20
 
14
- self.help = "Use .seen <name> to see the last time that nick was active."
21
+ self.help = 'Use .seen <name> to see the last time that nick was active.'
15
22
 
16
23
  listen_to :channel
17
24
 
@@ -25,8 +32,10 @@ module Cinch::Plugins
25
32
 
26
33
  def listen(m)
27
34
  channel = m.channel.name
28
- @storage.data[channel] ||= Hash.new
29
- @storage.data[channel][m.user.nick.downcase] = Time.now
35
+ nick = m.user.nick
36
+ @storage.data[channel] ||= {}
37
+ @storage.data[channel][nick.downcase] =
38
+ Activity.new(nick, Time.now, m.message)
30
39
  @storage.synced_save(@bot)
31
40
  end
32
41
 
@@ -40,19 +49,20 @@ module Cinch::Plugins
40
49
  private
41
50
 
42
51
  def last_seen(channel, nick)
43
- @storage.data[channel] ||= Hash.new
44
- time = @storage.data[channel][nick.downcase]
52
+ @storage.data[channel] ||= {}
53
+ activity = @storage.data[channel][nick.downcase]
45
54
 
46
- if time.nil?
55
+ if activity.nil?
47
56
  "I've never seen #{nick} before, sorry!"
48
57
  else
49
- "I last saw #{nick} #{time.ago.to_words}"
58
+ "I last saw #{activity.nick} #{activity.time.ago.to_words} " +
59
+ "saying '#{activity.message}'"
50
60
  end
51
61
  end
52
62
 
53
63
  def sent_via_pm?(m)
54
64
  return false unless m.channel.nil?
55
- m.reply "You must use that command in the main channel."
65
+ m.reply 'You must use that command in the main channel.'
56
66
  true
57
67
  end
58
68
  end
data/lib/cinch-seen.rb CHANGED
@@ -1,2 +1,3 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'cinch/plugins/seen/version'
2
- require 'cinch/plugins/seen/seen'
3
+ require 'cinch/plugins/seen'
@@ -16,6 +16,14 @@ describe Cinch::Plugins::Seen do
16
16
  should match(/baz: I last saw foo \d seconds? ago/)
17
17
  end
18
18
 
19
+ it 'should allow show the last said thing' do
20
+ get_replies(make_message(@bot, 'hello, world!', { :nick => 'foo', :channel => '#bar' }))
21
+ sleep 1 # time-lord hack
22
+ msg = make_message(@bot, '!seen foo', { :nick => 'baz', :channel => '#bar' })
23
+ get_replies(msg).last.text.
24
+ should match(/saying 'hello, world!'/)
25
+ end
26
+
19
27
  it 'should not respond to a users seen request for themselves' do
20
28
  msg = make_message(@bot, '!seen foo', { :nick => 'foo', :channel => '#bar' })
21
29
  get_replies(msg).
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  require 'coveralls'
2
- Coveralls.wear!
2
+ require 'simplecov'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
3
10
  require 'cinch-seen'
4
11
  require 'cinch/test'
5
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-seen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-10 00:00:00.000000000 Z
12
+ date: 2014-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -171,7 +171,7 @@ files:
171
171
  - Rakefile
172
172
  - cinch-seen.gemspec
173
173
  - lib/cinch-seen.rb
174
- - lib/cinch/plugins/seen/seen.rb
174
+ - lib/cinch/plugins/seen.rb
175
175
  - lib/cinch/plugins/seen/version.rb
176
176
  - spec/cinch-seen_spec.rb
177
177
  - spec/spec_helper.rb
@@ -202,3 +202,4 @@ summary: Cinch Plugin for Seen
202
202
  test_files:
203
203
  - spec/cinch-seen_spec.rb
204
204
  - spec/spec_helper.rb
205
+ has_rdoc: