ruboty-hugekarma 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 40023e222739a085cc32251e1b87213ba277764f6eea8b4734be163bfa76afcf
4
+ data.tar.gz: affd078230b31e831c773d3c40d05da923ec93f9518d738d313cc8c54c3bc014
5
+ SHA512:
6
+ metadata.gz: 6b929b37e4b5ecc3799be559df8a9d341416aa8fc614426f988abe9f85821b40fc44bb1c39430018b3346f66a7d0e0124cbf3e23197dd853933cf096c4487557
7
+ data.tar.gz: 0d677b322c80cb4b210206a25759a930decb638b682548cd0c1b9921523e9aced1d15823b663897192748edd1ede48f9f6f46b082c0d6ed63a5ac06863b291a1
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ruboty-pick.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 osyoyu
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ Ruboty::HugeKarma
2
+ =================
3
+
4
+ ## Installation
5
+
6
+ Add this line to your ruboty's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'ruboty-hugekarma'
10
+ ```
11
+
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ > ruboty name++
17
+ Incremented name's karma (current: 1)
18
+
19
+ > ruboty name +5000兆
20
+ Incremented name's karma by 5000000000000000 (current: 5000000000000000)
21
+ ```
22
+
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+
28
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruboty-pick.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module HugeKarma
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,47 @@
1
+ require 'ruboty'
2
+ require 'ruboty/hugekarma/version'
3
+ require 'japanese_numbers'
4
+
5
+ module Ruboty
6
+ module Handlers
7
+ class HugeKarma < Base
8
+ BRAIN_KEY = 'hugekarma'
9
+
10
+ on /(?<name>.+)\+\+$/, name: 'increment', description: "Increment <name>'s karma by 1"
11
+ on /(?<name>.+) \+(?<value>[\d万億兆京]+)$/, name: 'super_increment', description: "Increment <name>'s score by specified value"
12
+ on /karma list$/, name: 'list_karma', description: "Show karma ranking"
13
+ # on /karma set (?<name>.+) \+[\d万億兆京]+$/, name: 'set_karma', description: "Set <name>'s karma to specified value"
14
+
15
+ def increment(message)
16
+ brain = message.robot.brain
17
+ data = brain.data[BRAIN_KEY] || {}
18
+ data[message[:name]] ||= 0
19
+ data[message[:name]] += 1
20
+ brain.data[BRAIN_KEY] = data
21
+
22
+ message.reply("Incremented #{message[:name]}'s karma (current: #{data[message[:name]]})")
23
+ end
24
+
25
+ def super_increment(message)
26
+ incr_value = JapaneseNumbers::Parser.parse(message[:value])
27
+
28
+ brain = message.robot.brain
29
+ data = brain.data[BRAIN_KEY] || {}
30
+ data[message[:name]] ||= 0
31
+ data[message[:name]] += incr_value
32
+ brain.data[BRAIN_KEY] = data
33
+
34
+ message.reply("Incremented #{message[:name]}'s karma by #{incr_value} (current: #{data[message[:name]]})")
35
+ end
36
+
37
+ def list_karma(message)
38
+ brain = message.robot.brain
39
+ data = brain.data[BRAIN_KEY] || {}
40
+ sorted = data.sort_by {|name, karma| karma}.reverse
41
+
42
+ reply = sorted.map {|d| "#{d[0]}: #{d[1]}"}
43
+ message.reply(reply.join("\n"))
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ruboty/hugekarma/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-hugekarma"
7
+ spec.version = Ruboty::HugeKarma::VERSION
8
+ spec.authors = ["osyoyu"]
9
+ spec.email = ["osyoyu@osyoyu.com"]
10
+
11
+ spec.summary = %q{A Ruboty plugin for recording huge amounts of karma.}
12
+ spec.homepage = "https://github.com/osyoyu/ruboty-hugekarma"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = []
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "japanese_numbers", "~> 0.1.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-hugekarma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - osyoyu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: japanese_numbers
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ description:
42
+ email:
43
+ - osyoyu@osyoyu.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - lib/ruboty/hugekarma.rb
53
+ - lib/ruboty/hugekarma/version.rb
54
+ - ruboty-hugekarma.gemspec
55
+ homepage: https://github.com/osyoyu/ruboty-hugekarma
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.7.3
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: A Ruboty plugin for recording huge amounts of karma.
79
+ test_files: []