lita-diceman 1.0.0
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/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/lib/lita-diceman.rb +68 -0
- data/lita-diceman.gemspec +24 -0
- data/spec/lita/handlers/diceman_spec.rb +22 -0
- data/spec/spec_helper.rb +6 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 897c2243661df98b4daa266781582700d08e34c0
|
4
|
+
data.tar.gz: 28e9920092c0496792a89f365656e0481830103d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bdd293e4c410ea462dc7f3b63369ae44817cf7da3a337aec7983d0ef213251e5e1f512b06fc97de3e2382c5ed3dad8292c2ee14a593ef24ef5017f597eea2450
|
7
|
+
data.tar.gz: 5703d0543f49429ebe4053a3b49e810338a3b524dfe01139ac00e944e327803497cd6cfad44a2546efee429432bcc0fd0f5866d01c19c54dd6625c0684e9b16d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2015-, Simon Lundström <simmel@soy.se>
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# lita-diceman
|
2
|
+
|
3
|
+
> <q>It's the way a person chooses to limit themself that determines their character.</q>
|
4
|
+
>
|
5
|
+
> — <cite>Luke Rhinehart, The Dice Man</cite>
|
6
|
+
|
7
|
+
`diceman` is a handler which you can give options and it decides for you what
|
8
|
+
to do.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add lita-diceman to your Lita instance's Gemfile:
|
13
|
+
|
14
|
+
``` ruby
|
15
|
+
gem "lita-diceman"
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
### `!dice`
|
21
|
+
returns one of the answers that you specify, randomly. You can add as many answers as you want.
|
22
|
+
|
23
|
+
```
|
24
|
+
You: !dice answer one;answer two
|
25
|
+
Lita: the dice commands: answer two
|
26
|
+
```
|
27
|
+
|
28
|
+
### `?dice`
|
29
|
+
returns an answer to your question.
|
30
|
+
|
31
|
+
```
|
32
|
+
You: ?dice Who is the smartest? Answer one;Answer two
|
33
|
+
Lita: Answer one is the smartest
|
34
|
+
```
|
data/Rakefile
ADDED
data/lib/lita-diceman.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "lita"
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Handlers
|
6
|
+
class Diceman < Handler
|
7
|
+
|
8
|
+
route(/^!dice\s+(.*)/, :dice!, help: { "!dice answer one;answer two[;…]" => "Gives you a random answer." })
|
9
|
+
route(/^?dice\s+(.+?)\? (.*)/, :dice?, help: { "?dice Which is the correct answer? answer one;answer two[;…]" => "Gives you a random answer to your question." })
|
10
|
+
|
11
|
+
def dice!(response)
|
12
|
+
answers = response.match_data.captures.join.split(/ ?; ?/)
|
13
|
+
response.reply("the dice commands: " + answers[SecureRandom.random_number(answers.size)])
|
14
|
+
end
|
15
|
+
|
16
|
+
def dice?(response)
|
17
|
+
question = response.match_data.captures[0]
|
18
|
+
answers = response.match_data.captures[1].split(/ ?; ?/)
|
19
|
+
answer = answers[SecureRandom.random_number(answers.size)]
|
20
|
+
|
21
|
+
# TODO Put this in translation files?
|
22
|
+
interrogative_words = [
|
23
|
+
# Swedish
|
24
|
+
"bör",
|
25
|
+
"hur mycket",
|
26
|
+
"hur många",
|
27
|
+
"hur",
|
28
|
+
"när",
|
29
|
+
"ska",
|
30
|
+
"skall",
|
31
|
+
"vad",
|
32
|
+
"var",
|
33
|
+
"varför",
|
34
|
+
"varifrån",
|
35
|
+
"vem",
|
36
|
+
"vilka",
|
37
|
+
"vilken",
|
38
|
+
"vilket",
|
39
|
+
"är",
|
40
|
+
# English
|
41
|
+
"how many",
|
42
|
+
"how much",
|
43
|
+
"how",
|
44
|
+
"what",
|
45
|
+
"when",
|
46
|
+
"where",
|
47
|
+
"which",
|
48
|
+
"who",
|
49
|
+
"why",
|
50
|
+
]
|
51
|
+
question.sub!(/\b(?:#{interrogative_words.join("|")})\b/i, answer)
|
52
|
+
|
53
|
+
pronoun = {
|
54
|
+
"jag" => "du",
|
55
|
+
"dig" => "mig",
|
56
|
+
"me" => "you",
|
57
|
+
"i" => "you",
|
58
|
+
}
|
59
|
+
question.sub!(/\b(?:#{pronoun.keys.join("|")})\b/) {|p| pronoun[p] }
|
60
|
+
|
61
|
+
response.reply(question)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
Lita.register_handler(Diceman)
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-diceman"
|
3
|
+
spec.version = "1.0.0"
|
4
|
+
spec.authors = ["Simon Lundström"]
|
5
|
+
spec.email = ["simmel@soy.se"]
|
6
|
+
spec.description = "Roll the dice and live by it"
|
7
|
+
spec.summary = "It's the way a person chooses to limit themself that determines their character"
|
8
|
+
spec.homepage = "https://github.com/simmel/lita-diceman"
|
9
|
+
spec.license = "ISC license"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "lita", ">= 4.3"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "pry-byebug"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rack-test"
|
23
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::Diceman, lita_handler: true do
|
4
|
+
|
5
|
+
it { is_expected.to route_command("!dice answer one;answer two").to(:dice!) }
|
6
|
+
it { is_expected.to route_command("?dice Which is the correct answer? answer one;answer two").to(:dice?) }
|
7
|
+
|
8
|
+
it "gives an random answer when using !dice" do
|
9
|
+
answers = ["answer one", "answer two", "answer three"]
|
10
|
+
send_message("!dice " + answers.join(";"))
|
11
|
+
reply = $1 if replies.last =~ /^the dice commands: (.*)/
|
12
|
+
expect(answers.include?(reply))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "gives an random answer when using ?dice" do
|
16
|
+
answers = ["answer one", "answer two", "answer three"]
|
17
|
+
question = "Which is the correct answer"
|
18
|
+
send_message("?dice #{question}? " + answers.join(";"))
|
19
|
+
expect(replies.last.to_s).to match(/^(?:#{answers.map { |i| i.capitalize }.join("|")}) #{question.sub(/^\w+ /, "")}/)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-diceman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Lundström
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.3'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
description: Roll the dice and live by it
|
98
|
+
email:
|
99
|
+
- simmel@soy.se
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/lita-diceman.rb
|
110
|
+
- lita-diceman.gemspec
|
111
|
+
- spec/lita/handlers/diceman_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
homepage: https://github.com/simmel/lita-diceman
|
114
|
+
licenses:
|
115
|
+
- ISC license
|
116
|
+
metadata:
|
117
|
+
lita_plugin_type: handler
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.0.14
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: It's the way a person chooses to limit themself that determines their character
|
138
|
+
test_files:
|
139
|
+
- spec/lita/handlers/diceman_spec.rb
|
140
|
+
- spec/spec_helper.rb
|