cinch-quotes 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/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Cinch-Quotes - Quotes plugin
2
+
3
+ ## Description
4
+
5
+ This is a quotes plugin for Cinch bots.
6
+
7
+ ## Installation
8
+
9
+ ### RubyGems
10
+
11
+ You can install the latest Cinch-Quotes gem using RubyGems
12
+
13
+ gem install cinch-quotes
14
+
15
+ ### GitHub
16
+
17
+ Alternatively you can check out the latest code directly from Github
18
+
19
+ git clone http://github.com/caitlin/cinch-quotes.git
20
+
21
+ ## Usage
22
+
23
+ Install the gem and load it in your Cinch bot:
24
+
25
+ require "cinch"
26
+ require "cinch/plugins/quotes"
27
+
28
+ bot = Cinch::Bot.new do
29
+ configure do |c|
30
+ # add all required options here
31
+ c.plugins.plugins = [Cinch::Plugins::Quotes] # optionally add more plugins
32
+ end
33
+ end
34
+
35
+ bot.start
36
+
37
+
38
+ ## Commands
39
+
40
+ ### !quote
41
+
42
+ The bot will reply with a random quote. You can optionally provide an ID or a search term for the bot to return a specific quote.
43
+
44
+ ### !addquote
45
+
46
+ Add a quote to the bot.
47
+
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "cinch-quotes"
5
+ s.version = "0.0.1"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Caitlin Woodward"]
8
+ s.email = ["caitlin@caitlinwoodward.me"]
9
+ s.homepage = "https://github.com/caitlin/cinch-quotes"
10
+ s.summary = %q{Gives Cinch IRC bots ability to manage quotes}
11
+ s.description = %q{Gives Cinch IRC bots ability to manage quotes}
12
+
13
+ s.add_dependency("cinch", "~> 2.0")
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.require_paths = ["lib"]
17
+ end
@@ -0,0 +1,76 @@
1
+ require 'cinch'
2
+ require 'yaml'
3
+
4
+ module Cinch
5
+ module Plugins
6
+ class Quotes
7
+ include Cinch::Plugin
8
+
9
+ QUOTES_FILE = "data/quotes.yml"
10
+
11
+ match /addquote (.+)/i, method: :addquote
12
+ match /quote (.+)/i, method: :quote
13
+ match "quote", method: :quote
14
+
15
+ def addquote(m, quote)
16
+ # make the quote
17
+ new_quote = { "quote" => quote, "added_by" => m.user.nick, "created_at" => Time.now, "deleted" => false }
18
+
19
+ # add it to the list
20
+ existing_quotes = get_quotes || []
21
+ existing_quotes << new_quote
22
+
23
+ # find the id of the new quote and set it based on where it was placed in the quote list
24
+ new_quote_index = existing_quotes.index(new_quote)
25
+ existing_quotes[new_quote_index]["id"] = new_quote_index + 1
26
+
27
+ # write it to the file
28
+ output = File.new(QUOTES_FILE, 'w')
29
+ output.puts YAML.dump(existing_quotes)
30
+ output.close
31
+
32
+ # send reply that quote was added
33
+ m.reply "#{m.user.nick}: Quote successfully added as ##{new_quote_index + 1}."
34
+ end
35
+
36
+ def quote(m, search = nil)
37
+ quotes = get_quotes.delete_if{ |q| q["deleted"] == true }
38
+ if search.nil? # we are pulling random
39
+ quote = quotes.sample
40
+ m.reply "#{m.user.nick}: ##{quote["id"]} - #{quote["quote"]}"
41
+ elsif search.to_i != 0 # then we are searching be id
42
+ quote = quotes[(search.to_i - 1)]
43
+ if quote.nil?
44
+ m.reply "#{m.user.nick}: No quotes found."
45
+ else
46
+ m.reply "#{m.user.nick}: ##{quote["id"]} - #{quote["quote"]}"
47
+ end
48
+ else
49
+ quotes.keep_if{ |q| q["quote"].downcase.include?(search.downcase) }
50
+ if quotes.empty?
51
+ m.reply "#{m.user.nick}: No quotes found."
52
+ else
53
+ quote = quotes.first
54
+ m.reply "#{m.user.nick}: ##{quote["id"]} - #{quote["quote"]}"
55
+ m.reply "The search term also matched on quote IDs: #{quotes.map{|q| q["id"]}.join(", ")}" if quotes.size > 1
56
+ end
57
+ end
58
+ end
59
+
60
+ #--------------------------------------------------------------------------------
61
+ # Protected
62
+ #--------------------------------------------------------------------------------
63
+
64
+ protected
65
+
66
+ def get_quotes
67
+ output = File.new(QUOTES_FILE, 'r')
68
+ quotes = YAML.load(output.read)
69
+ output.close
70
+
71
+ quotes
72
+ end
73
+
74
+ end
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-quotes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Caitlin Woodward
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cinch
16
+ requirement: &70140338101780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70140338101780
25
+ description: Gives Cinch IRC bots ability to manage quotes
26
+ email:
27
+ - caitlin@caitlinwoodward.me
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - README.md
33
+ - cinch-quotes.gemspec
34
+ - lib/cinch/plugins/quotes.rb
35
+ homepage: https://github.com/caitlin/cinch-quotes
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.6
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Gives Cinch IRC bots ability to manage quotes
59
+ test_files: []