Cinch-Tell 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.
- checksums.yaml +7 -0
- data/Cinch-Tell.gemspec +47 -0
- data/LICENSE +21 -0
- data/README.md +43 -0
- data/Sun_02-28-2016_19-34-28.png +0 -0
- data/lib/cinch/plugins/tell/version.rb +5 -0
- data/lib/cinch/plugins/tell.rb +116 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 024a837e5b67c8db300aa782e99cbcb45fc785ab
|
4
|
+
data.tar.gz: 8f44584f6c4e661578316e04f76e7e8239848f68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 08f6cacfc6b42682bd7183357cabf0da92a7343a5b8d3bd775cc63bed70ad7e42cd6505e87f1b5d1c5f9e123376317488d9823497bdc18a6226a30d4ffce44d8
|
7
|
+
data.tar.gz: d1a61153a1479bacde04fec5b4da853051fcae633e6d75385132db413659f303294c3faf4e64d9e9039a3002fb6b53a564e74e2a8fd007c275ded8c17de6243f
|
data/Cinch-Tell.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
$LOAD_PATH.push('lib')
|
4
|
+
require 'cinch/plugins/tell/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'Cinch-Tell'
|
8
|
+
s.version = Cinch::Tell::VERSION.dup
|
9
|
+
s.date = '2016-02-28'
|
10
|
+
s.summary = 'Cinch plugin to leave memos for people on IRC'
|
11
|
+
s.email = 'lilian.jonsdottir@gmail.com'
|
12
|
+
s.homepage = 'https://github.com/lilyseki/Cinch-Tell'
|
13
|
+
s.authors = ['Lily J']
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.description = <<-EOF
|
17
|
+
Leave a message for someone on IRC who is not in the current
|
18
|
+
channel. They will recieve the message upon joining the channel
|
19
|
+
or changing their nick to the one that the message was left for.
|
20
|
+
Messages have a default lifespan of six months before they are
|
21
|
+
purged from the database.
|
22
|
+
EOF
|
23
|
+
|
24
|
+
dependencies = [
|
25
|
+
[:runtime, 'sequel', '~> 0'],
|
26
|
+
[:runtime, 'time_diff', '~> 0'],
|
27
|
+
[:runtime, 'facets', '~> 0']
|
28
|
+
]
|
29
|
+
|
30
|
+
s.files = Dir['**/*']
|
31
|
+
s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
|
32
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
33
|
+
s.require_paths = ['lib']
|
34
|
+
|
35
|
+
## Make sure you can build the gem on older versions of RubyGems too:
|
36
|
+
s.rubygems_version = '2.5.1'
|
37
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
38
|
+
s.specification_version = 3 if s.respond_to? :specification_version
|
39
|
+
|
40
|
+
dependencies.each do |type, name, version|
|
41
|
+
if s.respond_to?("add_#{type}_dependency")
|
42
|
+
s.send("add_#{type}_dependency", name, version)
|
43
|
+
else
|
44
|
+
s.add_dependency(name, version)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Lily Jónsdottír / Lily Seki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Tell/Memo Plugin for Cinch
|
2
|
+
========================
|
3
|
+
Leave a note for someone not in an IRC channel, to be relayed when they rejoin
|
4
|
+
the channel
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
Until I figure out how to make it into a gem, download the .rb file, and place
|
10
|
+
it in a subdirectory of your bot entitled
|
11
|
+
`plugins` then require it via `require_relative`.
|
12
|
+
Add it to your bot like so:
|
13
|
+
|
14
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ruby
|
15
|
+
require 'cinch'
|
16
|
+
require_relative 'plugins/tell.rb'
|
17
|
+
|
18
|
+
bot = Cinch::Bot.new do
|
19
|
+
configure do |c|
|
20
|
+
c.server = 'your server'
|
21
|
+
c.nick = 'your nick'
|
22
|
+
c.realname = 'your realname'
|
23
|
+
c.user = 'your user'
|
24
|
+
c.channels = ['#yourchannel']
|
25
|
+
c.plugins.plugins = [Cinch::Plugins::Tell]
|
26
|
+
end
|
27
|
+
|
28
|
+
bot.start
|
29
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
30
|
+
|
31
|
+
Contained Commands
|
32
|
+
------------------
|
33
|
+
|
34
|
+
**[tell user message]**
|
35
|
+
|
36
|
+
Leave note #{message} for #{user}. They must not be in the channel. Messages
|
37
|
+
expire after a default of six months.
|
38
|
+
|
39
|
+
License
|
40
|
+
-------
|
41
|
+
|
42
|
+
Licensed under The MIT License (MIT)
|
43
|
+
Please see LICENSE
|
Binary file
|
@@ -0,0 +1,116 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding=utf-8
|
3
|
+
|
4
|
+
require 'sequel'
|
5
|
+
require 'time'
|
6
|
+
require 'time_diff'
|
7
|
+
require 'facets/time/shift'
|
8
|
+
|
9
|
+
# These are all very annoying.
|
10
|
+
# rubocop:disable Metrics/LineLength, Metrics/ClassLength, Metrics/CyclomaticComplexity
|
11
|
+
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize
|
12
|
+
|
13
|
+
module Cinch
|
14
|
+
module Plugins
|
15
|
+
# Leaving messages and things
|
16
|
+
class Tell
|
17
|
+
include Cinch::Plugin
|
18
|
+
# set :prefix, /^\./
|
19
|
+
listen_to :join, method: :check_tells
|
20
|
+
listen_to :nick, method: :check_tells
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def initialize(*args)
|
25
|
+
super
|
26
|
+
@db = Sequel.sqlite('riria.db')
|
27
|
+
# Create the tables if they don't exist
|
28
|
+
@db.create_table? :tells do
|
29
|
+
primary_key :id
|
30
|
+
String :from_user
|
31
|
+
String :to_user
|
32
|
+
String :message
|
33
|
+
Float :time
|
34
|
+
end
|
35
|
+
@db = purge_ancients(@db)
|
36
|
+
end
|
37
|
+
|
38
|
+
def header(title)
|
39
|
+
puts '=' * 5 + " #{title} " + '=' * 5
|
40
|
+
end
|
41
|
+
|
42
|
+
def read_tells(nick)
|
43
|
+
tells = @db[:tells]
|
44
|
+
ret = tells.where(to_user: nick).all
|
45
|
+
return [] if ret.empty?
|
46
|
+
ret
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_tells(tell)
|
50
|
+
# ready tell for telling
|
51
|
+
to_nick = tell[:to_user]
|
52
|
+
from_nick = tell[:from_user]
|
53
|
+
msg = tell[:message]
|
54
|
+
msg_when = tell[:time]
|
55
|
+
timediff = Time.diff(Time.at(msg_when), Time.now)
|
56
|
+
output = "#{from_nick} wanted to tell you '#{msg}' about "
|
57
|
+
# lots of unless, could use timediff[:diff] but it's ugly
|
58
|
+
ago_str = ''
|
59
|
+
ago_str = "#{timediff[:year]} years, " unless timediff[:year].zero?
|
60
|
+
ago_str << "#{timediff[:month]} months, " unless timediff[:month].zero?
|
61
|
+
ago_str << "#{timediff[:week]} weeks, " unless timediff[:week].zero?
|
62
|
+
ago_str << "#{timediff[:hour]} hours, " unless timediff[:hour].zero?
|
63
|
+
ago_str << "#{timediff[:minute]} minutes, " unless timediff[:minute].zero?
|
64
|
+
ago_str << 'and ' unless ago_str.empty?
|
65
|
+
ago_str << "#{timediff[:second]} seconds " unless timediff[:second].zero?
|
66
|
+
ago_str << 'ago.' unless ago_str.empty?
|
67
|
+
ago_str = 'an undetermined amount of time ago.' if ago_str.empty?
|
68
|
+
output << ago_str
|
69
|
+
# feels odd without "return output" but I guess that's Ruby
|
70
|
+
end
|
71
|
+
|
72
|
+
def purge_ancients(db)
|
73
|
+
# purge any messages older than x date
|
74
|
+
purge_date = Time.now.shift(-6, :months)
|
75
|
+
db[:tells].where('time < ?', purge_date.to_f).delete
|
76
|
+
db
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_tell(nick, msg, from)
|
80
|
+
t = Time.now.to_f
|
81
|
+
@db[:tells].insert(to_user: nick, from_user: from, message: msg, time: t)
|
82
|
+
end
|
83
|
+
|
84
|
+
public
|
85
|
+
|
86
|
+
def check_tells(m)
|
87
|
+
tells = read_tells(m.user.nick.downcase)
|
88
|
+
return if tells.empty?
|
89
|
+
r = parse_tells(tells.first)
|
90
|
+
r = r.prepend("#{m.user.nick}: ") unless m.channel.nil?
|
91
|
+
m.reply(r)
|
92
|
+
if tells.length > 1
|
93
|
+
tells.each_with_index do |i, j|
|
94
|
+
next if j == 0 # Skip the first message because it was already sent
|
95
|
+
User(i[:to_user]).send(parse_tells(i))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
@db[:tells].where(to_user: m.user.nick).delete
|
99
|
+
end
|
100
|
+
|
101
|
+
match(/tell(?: (.+))?/, method: :irc_tell)
|
102
|
+
def irc_tell(m, q)
|
103
|
+
nick = q.split(' ')[0]
|
104
|
+
msg = q.split(' ')[1..-1].join(' ')
|
105
|
+
if m.channel.has_user?(nick)
|
106
|
+
m.reply("#{nick} is here right now, tell them yourself!")
|
107
|
+
return
|
108
|
+
end
|
109
|
+
add_tell(nick.downcase, msg, m.user.nick)
|
110
|
+
m.reply("Okay I'll let #{nick} know the next time they join the channel.")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# vim:tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab foldmethod=syntax:
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Cinch-Tell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lily J
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sequel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: time_diff
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: facets
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |
|
56
|
+
Leave a message for someone on IRC who is not in the current
|
57
|
+
channel. They will recieve the message upon joining the channel
|
58
|
+
or changing their nick to the one that the message was left for.
|
59
|
+
Messages have a default lifespan of six months before they are
|
60
|
+
purged from the database.
|
61
|
+
email: lilian.jonsdottir@gmail.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- Cinch-Tell.gemspec
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Sun_02-28-2016_19-34-28.png
|
70
|
+
- lib/cinch/plugins/tell.rb
|
71
|
+
- lib/cinch/plugins/tell/version.rb
|
72
|
+
homepage: https://github.com/lilyseki/Cinch-Tell
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.5.1
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Cinch plugin to leave memos for people on IRC
|
96
|
+
test_files: []
|