bemurphy-cinch-last_seen 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Dominik Honnef
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # Last seen plugin
2
+
3
+ This plugin provides the traditional _last seen_ functionality for Cinch bots.
4
+
5
+ ## Installation
6
+ First install the gem by running:
7
+ [sudo] gem install cinch-last_seen
8
+
9
+ Then load it in your bot:
10
+ require "cinch"
11
+ require "cinch/plugins/last_seen"
12
+
13
+ bot = Cinch::Bot.new do
14
+ configure do |c|
15
+ # add all required options here
16
+ c.plugins.plugins = [Cinch::Plugins::LastSeen] # optionally add more plugins
17
+ end
18
+ end
19
+
20
+ bot.start
21
+
22
+ ## Commands
23
+ ### !seen <nick>
24
+ This checks if and when someone was last seen. The plugin will either
25
+ respond with the time, channel and message or state that it has never
26
+ seen the person before.
27
+
28
+ ## Options
29
+ ### :channels
30
+ #### :include
31
+ Specify a list of channels the bot should log messages for. If this
32
+ option is set, `:exclude` will be ignored.
33
+
34
+ #### :exclude
35
+ Specify a list of channels the bot should not log messages for. All
36
+ other channels will be logged.
37
+
38
+ #### A note
39
+ If neither `:include` nor `:exclude` are set, all channels will be logged.
40
+
41
+ #### Example configuration
42
+ # ...
43
+ configure do |c|
44
+ # only log messages for #cinch-bots
45
+ c.plugins.options[Cinch::Plugins::LastSeen][:channels] = {:include => ["#cinch-bots"]}
46
+ end
@@ -0,0 +1,10 @@
1
+ require 'cinch'
2
+
3
+ module Cinch
4
+ module Plugins
5
+ module LastSeen
6
+ autoload :Base, File.expand_path('./lib/cinch/plugins/last_seen/base.rb')
7
+ autoload :RedisStorage, File.expand_path('./lib/cinch/plugins/last_seen/storage/redis_storage.rb')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ module Cinch
2
+ module Plugins
3
+ module LastSeen
4
+ class Base
5
+ include Cinch::Plugin
6
+ attr_accessor :backend
7
+
8
+ def initialize(*args)
9
+ super
10
+ # TODO config this
11
+ self.backend = RedisStorage.new
12
+ end
13
+
14
+ listen_to :channel, :method => :log_message
15
+
16
+ def log_message(m)
17
+ return unless log_channel?(m.channel)
18
+ backend.record_time m.channel, m.user.nick
19
+ end
20
+
21
+ match /seen (.+)/, :method => :check_nick
22
+
23
+ def check_nick(m, nick)
24
+ return unless log_channel?(m.channel)
25
+
26
+ if time = backend.get_time(m.channel, nick)
27
+ readable_time = Time.at time.to_i
28
+ m.reply "I've last seen #{nick} at #{readable_time}", true
29
+ else
30
+ m.reply "I haven't seen #{nick}, sorry.", true
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def log_channel?(channel)
37
+ channel = channel.to_s
38
+ our_config = config[:channels] || {}
39
+
40
+ if our_config[:include]
41
+ our_config[:include].include?(channel)
42
+ elsif our_config[:exclude]
43
+ !our_config[:exclude].include?(channel)
44
+ else
45
+ true
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,28 @@
1
+ require 'redis'
2
+ require 'redis-namespace'
3
+
4
+ # TODO extract this into a gem so we can reuse across cinch plugins,
5
+ # or just general config a redis connection at toplevel for re-use
6
+
7
+ module Cinch
8
+ module Plugins
9
+ module LastSeen
10
+ class RedisStorage
11
+ attr_reader :redis
12
+
13
+ def initialize
14
+ @redis = ::Redis::Namespace.new("cinch-seen_last", :redis => ::Redis.new(:thread_safe => true))
15
+ end
16
+
17
+ def record_time(set, key)
18
+ redis.zadd(set.to_s, Time.now.to_i, key.to_s)
19
+ end
20
+
21
+ def get_time(set, key)
22
+ time = redis.zscore(set, key)
23
+ Time.at(time.to_i) if time
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ module Cinch
2
+ module Plugins
3
+ module LastSeen
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
8
+
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bemurphy-cinch-last_seen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dominik Honnef
9
+ - Brendon Murphy
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-09-09 00:00:00.000000000 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: cinch
18
+ requirement: &2165643460 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '1.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *2165643460
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: &2165643000 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.2.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *2165643000
38
+ - !ruby/object:Gem::Dependency
39
+ name: redis-namespace
40
+ requirement: &2165642540 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *2165642540
49
+ - !ruby/object:Gem::Dependency
50
+ name: minitest
51
+ requirement: &2165642160 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *2165642160
60
+ - !ruby/object:Gem::Dependency
61
+ name: mocha
62
+ requirement: &2165641700 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *2165641700
71
+ - !ruby/object:Gem::Dependency
72
+ name: timecop
73
+ requirement: &2165641280 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *2165641280
82
+ description: A "last seen" plugin for the Cinch framework
83
+ email:
84
+ - xternal1+github@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - LICENSE
90
+ - README.md
91
+ - lib/cinch/plugins/last_seen/base.rb
92
+ - lib/cinch/plugins/last_seen/storage/redis_storage.rb
93
+ - lib/cinch/plugins/last_seen/version.rb
94
+ - lib/cinch/plugins/last_seen.rb
95
+ has_rdoc: true
96
+ homepage: https://github.com/bemurphy/cinch-last_seen
97
+ licenses: []
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: 1.9.1
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.6.2
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: A "last seen" plugin for the Cinch framework
120
+ test_files: []