cinch-last_seen 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +19 -0
- data/README.md +46 -0
- data/lib/cinch/plugins/last_seen.rb +54 -0
- metadata +82 -0
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.
|
data/README.md
ADDED
@@ -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,54 @@
|
|
1
|
+
require "time"
|
2
|
+
|
3
|
+
# TODO a permanent store, to keep messages even after a restart of the bot
|
4
|
+
|
5
|
+
module Cinch
|
6
|
+
module Plugins
|
7
|
+
class LastSeen
|
8
|
+
include Cinch::Plugin
|
9
|
+
|
10
|
+
LoggedMessage = Struct.new(:nick, :channel, :message, :time)
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
super
|
14
|
+
@logged_messages = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
listen_to :channel, method: :log_message
|
18
|
+
def log_message(m)
|
19
|
+
return unless log_channel?(m.channel)
|
20
|
+
@logged_messages[m.user.nick] = LoggedMessage.new(m.user.nick, m.channel.to_s, m.message, Time.now)
|
21
|
+
end
|
22
|
+
|
23
|
+
match(/seen (.+)/, method: :check_nick)
|
24
|
+
def check_nick(m, nick)
|
25
|
+
message = @logged_messages[nick]
|
26
|
+
if message
|
27
|
+
m.reply "I've last seen #{nick} at #{message.time} in #{message.channel} saying: #{message.message}", true
|
28
|
+
else
|
29
|
+
m.reply "I haven't seen #{nick}, sorry.", true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def log_channel?(channel)
|
35
|
+
# we log a channel if:
|
36
|
+
# - we have an explicit list of allowed channels and the
|
37
|
+
# channel is included
|
38
|
+
# - we have an explicit list of disallowed channels and the
|
39
|
+
# channel is not included
|
40
|
+
# - we don't have either list
|
41
|
+
channel = channel.to_s
|
42
|
+
our_config = config[:channels] || {}
|
43
|
+
|
44
|
+
if our_config[:include]
|
45
|
+
return our_config[:include].include?(channel)
|
46
|
+
elsif our_config[:exclude]
|
47
|
+
return !our_config[:exclude].include?(channel)
|
48
|
+
else
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch-last_seen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dominik Honnef
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-29 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: cinch
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
version: "1.0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: A "last seen" plugin for the Cinch framework
|
35
|
+
email:
|
36
|
+
- dominikh@fork-bomb.org
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- README.md
|
46
|
+
- lib/cinch/plugins/last_seen.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://rubydoc.info/github/cinchrb/cinch-last_seen
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 9
|
64
|
+
- 1
|
65
|
+
version: 1.9.1
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: A "last seen" plugin for the Cinch framework
|
81
|
+
test_files: []
|
82
|
+
|