cinch-karma 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cinch-karma.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brian Haberer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Cinch::Plugins::Karma
2
+
3
+ Cinch PLugin to track Karma.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cinch-karma'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cinch-karma
18
+
19
+ ## Usage
20
+
21
+ Just add the plugin to your list:
22
+
23
+ @bot = Cinch::Bot.new do
24
+ configure do |c|
25
+ c.plugins.plugins = [Cinch::Plugins::Karma]
26
+ end
27
+ end
28
+
29
+ Then in channel use the following commands:
30
+
31
+ item++ || item--
32
+
33
+ .karma item
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cinch/plugins/karma/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "cinch-karma"
8
+ gem.version = Cinch::Plugins::Karma::VERSION
9
+ gem.authors = ["Brian Haberer"]
10
+ gem.email = ["bhaberer@gmail.com"]
11
+ gem.description = %q{Cinch Plugin to track karma (item++ / item--) in the channel}
12
+ gem.summary = %q{Cinch Plugin to Track Karma}
13
+ gem.homepage = "https://github.com/bhaberer/cinch-karma"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'cinch', '>= 2.0.0'
21
+ gem.add_dependency 'cinch-cooldown'
22
+ gem.add_dependency 'cinch-storage'
23
+ end
@@ -0,0 +1,2 @@
1
+ require 'cinch/plugins/karma/version'
2
+ require 'cinch/plugins/karma/karma'
@@ -0,0 +1,68 @@
1
+ require 'cinch-cooldown'
2
+ require 'cinch-storage'
3
+
4
+ module Cinch::Plugins
5
+ class Karma
6
+ include Cinch::Plugin
7
+
8
+ enforce_cooldown
9
+
10
+ self.help = 'Use .karma <item> to see it\'s karma level. You can use <item>++ or <item>-- [or (something with spaces)++] to alter karma for an item'
11
+
12
+ listen_to :channel
13
+
14
+ match /karma (.+)/
15
+ match /k (.+)/
16
+
17
+ def initialize(*args)
18
+ super
19
+ @storage = CinchStorage.new(config[:filename] || 'yaml/karma.yml')
20
+ end
21
+
22
+ def listen(m)
23
+ if m.message.match(/\S+[\+\-]{2}/)
24
+ channel = m.channel.name
25
+ @storage.data[channel] = Hash.new unless @storage.data.key?(channel)
26
+ updated = false
27
+
28
+ m.message.scan(/.*?((\w+)|\((.+?)\))(\+\+|--)(\s|\z)/).each do |karma|
29
+ debug "#{karma}"
30
+
31
+ if karma[0]
32
+ item = karma[1] || karma[2]
33
+ item.downcase!
34
+
35
+ @storage.data[channel][item] = 0 unless @storage.data[channel].key?(item)
36
+
37
+ if karma[3] == '++'
38
+ @storage.data[channel][item] += 1
39
+ updated = true
40
+ elsif karma[3] == '--'
41
+ @storage.data[channel][item] -= 1
42
+ updated = true
43
+ else
44
+ debug 'something went wrong matching karma!'
45
+ end
46
+ end
47
+ end
48
+
49
+ if updated
50
+ synchronize(:karma_save) do
51
+ @storage.save
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def execute(m, item)
58
+ if m.channel.nil?
59
+ m.user.msg "You must use that command in the main channel."
60
+ return
61
+ end
62
+
63
+ @storage.data[m.channel.name] = Hash.new unless @storage.data.key?(m.channel.name)
64
+ karma = @storage.data[m.channel.name][item.downcase] || 0
65
+ m.reply "Karma for #{item} is #{karma}"
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ module Cinch
2
+ module Plugins
3
+ class Karma
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-karma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Haberer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cinch
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: cinch-cooldown
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: cinch-storage
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Cinch Plugin to track karma (item++ / item--) in the channel
63
+ email:
64
+ - bhaberer@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - cinch-karma.gemspec
75
+ - lib/cinch-karma.rb
76
+ - lib/cinch/plugins/karma/karma.rb
77
+ - lib/cinch/plugins/karma/version.rb
78
+ homepage: https://github.com/bhaberer/cinch-karma
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Cinch Plugin to Track Karma
102
+ test_files: []