cinch-yaml-score 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +14 -0
  2. data/README.md +3 -0
  3. data/lib/cinch/plugins/yamlscore.rb +62 -0
  4. metadata +64 -0
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2012 Michal Papis
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Cinch YAML score plugin
2
+
3
+ A Cinch plugin to count +1, scores are saved in yaml file for persistence.
@@ -0,0 +1,62 @@
1
+ # source: https://github.com/telemachus/antinoos/blob/master/memo.rb
2
+ # license: https://github.com/telemachus/antinoos/blob/master/LICENSE
3
+
4
+ require 'yaml'
5
+
6
+ module Cinch
7
+ module Plugins
8
+ class YamlScore
9
+ include Cinch::Plugin
10
+
11
+ def initialize(*args)
12
+ super
13
+ if File.exist?('scores.yaml')
14
+ @scores = YAML.load_file('scores.yaml')
15
+ else
16
+ @scores = {}
17
+ end
18
+ end
19
+
20
+ match(/scores/, method: :scores)
21
+ def scores(m)
22
+ m.reply "Scores: #{@scores.sort_by{|k,v| -v }.map{|k,v| "#{k}: #{v}" }*", "}."
23
+ end
24
+
25
+ match(/score (\S+)/, method: :score)
26
+ def score(m, nick)
27
+ if @scores[nick]
28
+ m.reply "Score for #{nick}: #{@scores[nick]}."
29
+ else
30
+ m.reply "No score for #{nick}."
31
+ end
32
+ end
33
+
34
+ match(/(\S+) ([-+]1)/, use_prefix: false, use_suffix: false, method: :change)
35
+ match(/(\S+) ?([-+]{2})/, use_prefix: false, use_suffix: false, method: :change)
36
+ def change(m, nick, score)
37
+ if nick == m.user.nick
38
+ m.reply "You can't score for yourself..."
39
+ elsif nick == bot.nick
40
+ m.reply "You can't score for me..."
41
+ elsif m.channel.has_user?(nick)
42
+ score.sub!(/([+-]){2}/,'\11')
43
+ @scores[nick] ||= 0
44
+ @scores[nick] += score.to_i
45
+ @scores.delete(nick) if @scores[nick] == 0
46
+ m.reply "#{m.user.nick}(#{@scores[m.user.nick]}) gave #{score} for #{nick}(#{@scores[nick]})."
47
+ update_store
48
+ else
49
+ m.reply "User #{nick} is not in the channel, who do you want to score?"
50
+ end
51
+ end
52
+
53
+ def update_store
54
+ synchronize(:update) do
55
+ File.open('scores.yaml', 'w') do |fh|
56
+ YAML.dump(@scores, fh)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-yaml-score
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michal Papis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-27 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'
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'
30
+ description: A Cinch plugin to count +1, scores are saved in yaml file for persistence.
31
+ email:
32
+ - mpapis@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - LICENSE
38
+ - README.md
39
+ - lib/cinch/plugins/yamlscore.rb
40
+ homepage: https://github.com/mpapis/cinch-yaml-score
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: 1.9.1
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.24
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: A Cinch plugin to count +1, scores are saved in yaml file for persistence.
64
+ test_files: []