rivescript 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 14789bd36c582ca744be88d8b762b3cf847ead692646caa8f107c911069b1ad5
4
+ data.tar.gz: da1e1ec25b54649951f4e426da08b895884b3e5753d3961e22cb3ac6da867da9
5
+ SHA512:
6
+ metadata.gz: b9744e1364266843b4b18a6ae8319fa24e9eec7969c7ed2e3fb3fc2811ab044720de93a0cd83054b50d8ad77c1d0d14e55efc6c19b603340cf100e9060ef4d26
7
+ data.tar.gz: a536b6e990beac8a900c35f65c00033870cad0f64b5b0ddc66d2d0ac9c49c8a156dafb4de05ef7b936975a9b33ac9888eea971036c56d10783dfd2b31d7a4219
data/Changes.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changes
2
+
3
+ ## 0.1.1
4
+
5
+ - Ship the sample brain (`eg/brain`) inside the gem
6
+ - Add `RiveScript.brain_path` so any app can load the bundled replies
7
+ - `riveshell` uses the bundled brain when no path is given
8
+ - CI builds the gem and checks that the brain files are included
9
+ - Release workflow publishes to RubyGems.org via Trusted Publishing
10
+
11
+ ## 0.1.0
12
+
13
+ - First Ruby 3.3 port of the RiveScript interpreter
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Noah Petherbridge
4
+ Copyright (c) 2026 Byte <byte@jvmlab.org> (https://jvmlab.org/)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # RiveScript-RB
2
+
3
+ A [RiveScript](https://www.rivescript.com/) interpreter for Ruby 3.3+.
4
+
5
+ Maintained at [jvmlab.org](https://jvmlab.org/) by Byte (`byte@jvmlab.org`).
6
+ Derived from the MIT-licensed [rivescript-js](https://github.com/aichaos/rivescript-js)
7
+ implementation.
8
+
9
+ ## Requirements
10
+
11
+ * Ruby `>= 3.3.0` (developed on **3.3.8**)
12
+
13
+ ## Install (recommended)
14
+
15
+ ### In an application (Bundler)
16
+
17
+ Add to your `Gemfile`:
18
+
19
+ ```ruby
20
+ gem "rivescript", "~> 0.1.1"
21
+ ```
22
+
23
+ Then:
24
+
25
+ ```bash
26
+ bundle install
27
+ ```
28
+
29
+ Use it only through Bundler:
30
+
31
+ ```bash
32
+ bundle exec ruby app.rb
33
+ bundle exec riveshell
34
+ ```
35
+
36
+ ### System / user gem (CLI and scripts)
37
+
38
+ ```bash
39
+ gem install rivescript
40
+ ```
41
+
42
+ Put Ruby gem binaries on your `PATH` if needed:
43
+
44
+ ```bash
45
+ export PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"
46
+ ```
47
+
48
+ Then:
49
+
50
+ ```bash
51
+ riveshell
52
+ ```
53
+
54
+ ### From GitHub or this repository
55
+
56
+ ```ruby
57
+ # Gemfile (development / unreleased tip)
58
+ gem "rivescript",
59
+ git: "https://github.com/LilOleByte/rivescript-rb.git",
60
+ tag: "v0.1.1"
61
+ ```
62
+
63
+ ```bash
64
+ bundle install
65
+ bundle exec rake package # builds pkg/rivescript-0.1.1.gem + verifies contents
66
+ gem install --user-install pkg/rivescript-0.1.1.gem
67
+ ```
68
+
69
+ ## Usage
70
+
71
+ ```ruby
72
+ require "rivescript"
73
+
74
+ bot = RiveScript.new
75
+ bot.load_directory(RiveScript.brain_path) # bundled sample brain
76
+ # or: bot.load_directory("./my-custom-brain")
77
+ bot.sort_replies
78
+
79
+ puts bot.reply("localuser", "Hello bot")
80
+ ```
81
+
82
+ Load from a string:
83
+
84
+ ```ruby
85
+ bot = RiveScript.new
86
+ bot.stream(<<~RIVE)
87
+ + hello bot
88
+ - Hello, human!
89
+ RIVE
90
+ bot.sort_replies
91
+ puts bot.reply("user", "hello bot")
92
+ ```
93
+
94
+ ## Interactive shell
95
+
96
+ ```bash
97
+ bundle exec riveshell # Bundler apps
98
+ riveshell # after gem install
99
+ riveshell /path/to/custom-brain # your own replies
100
+ ```
101
+
102
+ Options: `--debug`, `--utf8`.
103
+
104
+ ## Object macros (Ruby)
105
+
106
+ ```rive
107
+ > object setname ruby
108
+ return args[0]
109
+ < object
110
+
111
+ + my name is *
112
+ - <set name=<call>setname <star></call>>Nice to meet you, <get name>.
113
+ ```
114
+
115
+ Object macros run real Ruby. Only load brains you trust.
116
+ Disable with `RiveScript.new(enable_object_macros: false)`.
117
+
118
+ ## Develop / test this gem
119
+
120
+ ```bash
121
+ bundle install
122
+ bundle exec rake test
123
+ bundle exec rake package
124
+ ```
125
+
126
+ ## License
127
+
128
+ MIT — see [LICENSE](LICENSE).
129
+
130
+ Original RiveScript copyright (c) Noah Petherbridge / AiChaos.
131
+ Ruby port copyright (c) 2026 Byte \<byte@jvmlab.org\> ([jvmlab.org](https://jvmlab.org/)).
data/bin/riveshell ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Interactive RiveScript shell for Ruby.
5
+ # Copyright (c) Byte <byte@jvmlab.org> (https://jvmlab.org/)
6
+ # MIT License
7
+
8
+ require "optparse"
9
+ require_relative "../lib/rivescript"
10
+
11
+ opts = {
12
+ debug: false,
13
+ utf8: false,
14
+ brain: nil
15
+ }
16
+
17
+ parser = OptionParser.new do |o|
18
+ o.banner = "Usage: riveshell [options] [path/to/brain]"
19
+ o.separator ""
20
+ o.separator "If no brain path is given, the bundled sample brain is used."
21
+ o.on("--debug", "Enable debug mode") { opts[:debug] = true }
22
+ o.on("--utf8", "Enable UTF-8 mode") { opts[:utf8] = true }
23
+ o.on("-h", "--help", "Show help") do
24
+ puts o
25
+ exit
26
+ end
27
+ end
28
+ parser.parse!
29
+
30
+ opts[:brain] = ARGV.shift || RiveScript.brain_path
31
+
32
+ bot = RiveScript.new(
33
+ debug: opts[:debug],
34
+ utf8: opts[:utf8],
35
+ concat: "newline"
36
+ )
37
+
38
+ puts " . ."
39
+ puts " .:...:: RiveScript Interpreter (Ruby)"
40
+ puts " .:: ::. Library Version: v#{bot.version}"
41
+ puts " .:: . ::. https://jvmlab.org/"
42
+ puts " :. :."
43
+ puts " :. . :"
44
+ puts " ::: Type '/quit' or Ctrl-D to exit."
45
+ puts " :"
46
+ puts
47
+ puts "Brain: #{opts[:brain]}"
48
+ puts
49
+
50
+ begin
51
+ bot.load_directory(opts[:brain])
52
+ bot.sort_replies
53
+ rescue StandardError => e
54
+ warn "Error loading brain: #{e.message}"
55
+ exit 1
56
+ end
57
+
58
+ username = "localuser"
59
+ print "You> "
60
+ $stdout.flush
61
+
62
+ while (line = $stdin.gets)
63
+ line = line.strip
64
+ break if line == "/quit" || line == "/exit"
65
+
66
+ if line == "/help"
67
+ puts "Commands: /quit /exit /help"
68
+ elsif !line.empty?
69
+ begin
70
+ reply = bot.reply(username, line)
71
+ puts "Bot> #{reply}"
72
+ rescue StandardError => e
73
+ warn "Error: #{e.message}"
74
+ end
75
+ end
76
+
77
+ print "You> "
78
+ $stdout.flush
79
+ end
80
+
81
+ puts
@@ -0,0 +1,15 @@
1
+ // Administrative functions.
2
+
3
+ + shutdown{weight=10000}
4
+ * <id> eq <bot master> => Shutting down... <call>shutdown</call>
5
+ - {@botmaster only}
6
+
7
+ + botmaster only
8
+ - This command can only be used by my botmaster. <id> != <bot master>
9
+
10
+ > object shutdown perl
11
+ my ($rs) = @_;
12
+
13
+ # Shut down.
14
+ exit(0);
15
+ < object
@@ -0,0 +1,190 @@
1
+ ! version = 2.0
2
+
3
+ > begin
4
+ + request // This trigger is tested first.
5
+ - {ok} // An {ok} in the response means it's okay to get a real reply
6
+ < begin
7
+
8
+ // The Botmaster's Name
9
+ ! var master = localuser
10
+
11
+ // Bot Variables
12
+ ! var name = Aiden
13
+ ! var fullname = Aiden Rive
14
+ ! var age = 5
15
+ ! var birthday = October 12
16
+ ! var sex = male
17
+ ! var location = Michigan
18
+ ! var city = Detroit
19
+ ! var eyes = blue
20
+ ! var hair = light brown
21
+ ! var hairlen = short
22
+ ! var color = blue
23
+ ! var band = Nickelback
24
+ ! var book = Myst
25
+ ! var author = Stephen King
26
+ ! var job = robot
27
+ ! var website = www.rivescript.com
28
+
29
+ // Substitutions
30
+ ! sub &quot; = "
31
+ ! sub &apos; = '
32
+ ! sub &amp; = &
33
+ ! sub &lt; = <
34
+ ! sub &gt; = >
35
+ ! sub + = plus
36
+ ! sub - = minus
37
+ ! sub / = divided
38
+ ! sub * = times
39
+ ! sub i'm = i am
40
+ ! sub i'd = i would
41
+ ! sub i've = i have
42
+ ! sub i'll = i will
43
+ ! sub don't = do not
44
+ ! sub isn't = is not
45
+ ! sub you'd = you would
46
+ ! sub you're = you are
47
+ ! sub you've = you have
48
+ ! sub you'll = you will
49
+ ! sub he'd = he would
50
+ ! sub he's = he is
51
+ ! sub he'll = he will
52
+ ! sub she'd = she would
53
+ ! sub she's = she is
54
+ ! sub she'll = she will
55
+ ! sub they'd = they would
56
+ ! sub they're = they are
57
+ ! sub they've = they have
58
+ ! sub they'll = they will
59
+ ! sub we'd = we would
60
+ ! sub we're = we are
61
+ ! sub we've = we have
62
+ ! sub we'll = we will
63
+ ! sub whats = what is
64
+ ! sub what's = what is
65
+ ! sub what're = what are
66
+ ! sub what've = what have
67
+ ! sub what'll = what will
68
+ ! sub can't = can not
69
+ ! sub whos = who is
70
+ ! sub who's = who is
71
+ ! sub who'd = who would
72
+ ! sub who'll = who will
73
+ ! sub don't = do not
74
+ ! sub didn't = did not
75
+ ! sub it's = it is
76
+ ! sub could've = could have
77
+ ! sub couldn't = could not
78
+ ! sub should've = should have
79
+ ! sub shouldn't = should not
80
+ ! sub would've = would have
81
+ ! sub wouldn't = would not
82
+ ! sub when's = when is
83
+ ! sub when're = when are
84
+ ! sub when'd = when did
85
+ ! sub y = why
86
+ ! sub u = you
87
+ ! sub ur = your
88
+ ! sub r = are
89
+ ! sub n = and
90
+ ! sub im = i am
91
+ ! sub wat = what
92
+ ! sub wats = what is
93
+ ! sub ohh = oh
94
+ ! sub becuse = because
95
+ ! sub becasue = because
96
+ ! sub becuase = because
97
+ ! sub practise = practice
98
+ ! sub its a = it is a
99
+ ! sub fav = favorite
100
+ ! sub fave = favorite
101
+ ! sub yesi = yes i
102
+ ! sub yetit = yet it
103
+ ! sub iam = i am
104
+ ! sub welli = well i
105
+ ! sub wellit = well it
106
+ ! sub amfine = am fine
107
+ ! sub aman = am an
108
+ ! sub amon = am on
109
+ ! sub amnot = am not
110
+ ! sub realy = really
111
+ ! sub iamusing = i am using
112
+ ! sub amleaving = am leaving
113
+ ! sub yuo = you
114
+ ! sub youre = you are
115
+ ! sub didnt = did not
116
+ ! sub ain't = is not
117
+ ! sub aint = is not
118
+ ! sub wanna = want to
119
+ ! sub brb = be right back
120
+ ! sub bbl = be back later
121
+ ! sub gtg = got to go
122
+ ! sub g2g = got to go
123
+ ! sub lyl = love you lots
124
+ ! sub gf = girlfriend
125
+ ! sub g/f = girlfriend
126
+ ! sub bf = boyfriend
127
+ ! sub b/f = boyfriend
128
+ ! sub b/f/f = best friend forever
129
+ ! sub :-) = smile
130
+ ! sub :) = smile
131
+ ! sub :d = grin
132
+ ! sub :-d = grin
133
+ ! sub :-p = tongue
134
+ ! sub :p = tongue
135
+ ! sub ;-) = wink
136
+ ! sub ;) = wink
137
+ ! sub :-( = sad
138
+ ! sub :( = sad
139
+ ! sub :'( = cry
140
+ ! sub :-[ = shy
141
+ ! sub :-\ = uncertain
142
+ ! sub :-/ = uncertain
143
+ ! sub :-s = uncertain
144
+ ! sub 8-) = cool
145
+ ! sub 8) = cool
146
+ ! sub :-* = kissyface
147
+ ! sub :-! = foot
148
+ ! sub o:-) = angel
149
+ ! sub >:o = angry
150
+ ! sub :@ = angry
151
+ ! sub 8o| = angry
152
+ ! sub :$ = blush
153
+ ! sub :-$ = blush
154
+ ! sub :-[ = blush
155
+ ! sub :[ = bat
156
+ ! sub (a) = angel
157
+ ! sub (h) = cool
158
+ ! sub 8-| = nerdy
159
+ ! sub |-) = tired
160
+ ! sub +o( = ill
161
+ ! sub *-) = uncertain
162
+ ! sub ^o) = raised eyebrow
163
+ ! sub (6) = devil
164
+ ! sub (l) = love
165
+ ! sub (u) = broken heart
166
+ ! sub (k) = kissyface
167
+ ! sub (f) = rose
168
+ ! sub (w) = wilted rose
169
+
170
+ // Person substitutions
171
+ ! person i am = you are
172
+ ! person you are = I am
173
+ ! person i'm = you're
174
+ ! person you're = I'm
175
+ ! person my = your
176
+ ! person your = my
177
+ ! person you = I
178
+ ! person i = you
179
+
180
+ // Set arrays
181
+ ! array malenoun = male guy boy dude boi man men gentleman gentlemen
182
+ ! array femalenoun = female girl chick woman women lady babe
183
+ ! array mennoun = males guys boys dudes bois men gentlemen
184
+ ! array womennoun = females girls chicks women ladies babes
185
+ ! array lol = lol lmao rofl rotfl haha hahaha
186
+ ! array colors = white black orange red blue green yellow cyan fuchsia gray grey brown turquoise pink purple gold silver navy
187
+ ! array height = tall long wide thick
188
+ ! array measure = inch in centimeter cm millimeter mm meter m inches centimeters millimeters meters
189
+ ! array yes = yes yeah yep yup ya yea
190
+ ! array no = no nah nope nay
@@ -0,0 +1,72 @@
1
+ // Learn stuff about our users.
2
+
3
+ + my name is *
4
+ - <set name=<formal>>Nice to meet you, <get name>.
5
+ - <set name=<formal>><get name>, nice to meet you.
6
+
7
+ + my name is <bot master>
8
+ - <set name=<bot master>>That's my master's name too.
9
+
10
+ + my name is <bot name>
11
+ - <set name=<bot name>>What a coincidence! That's my name too!
12
+ - <set name=<bot name>>That's my name too!
13
+
14
+ + call me *
15
+ - <set name=<formal>><get name>, I will call you that from now on.
16
+
17
+ + i am * years old
18
+ - <set age=<star>>A lot of people are <get age>, you're not alone.
19
+ - <set age=<star>>Cool, I'm <bot age> myself.{weight=49}
20
+
21
+ + i am a (@malenoun)
22
+ - <set sex=male>Alright, you're a <star>.
23
+
24
+ + i am a (@femalenoun)
25
+ - <set sex=female>Alright, you're female.
26
+
27
+ + i (am from|live in) *
28
+ - <set location={formal}<star2>{/formal}>I've spoken to people from <get location> before.
29
+
30
+ + my favorite * is *
31
+ - <set fav<star1>=<star2>>Why is it your favorite?
32
+
33
+ + i am single
34
+ - <set status=single><set spouse=nobody>I am too.
35
+
36
+ + i have a girlfriend
37
+ - <set status=girlfriend>What's her name?
38
+
39
+ + i have a boyfriend
40
+ - <set status=boyfriend>What's his name?
41
+
42
+ + *
43
+ % what is her name
44
+ - <set spouse=<formal>>That's a pretty name.
45
+
46
+ + *
47
+ % what is his name
48
+ - <set spouse=<formal>>That's a cool name.
49
+
50
+ + my (girlfriend|boyfriend)* name is *
51
+ - <set spouse=<formal>>That's a nice name.
52
+
53
+ + (what is my name|who am i|do you know my name|do you know who i am){weight=10}
54
+ - Your name is <get name>.
55
+ - You told me your name is <get name>.
56
+ - Aren't you <get name>?
57
+
58
+ + (how old am i|do you know how old i am|do you know my age){weight=10}
59
+ - You are <get age> years old.
60
+ - You're <get age>.
61
+
62
+ + am i a (@malenoun) or a (@femalenoun){weight=10}
63
+ - You're a <get sex>.
64
+
65
+ + am i (@malenoun) or (@femalenoun){weight=10}
66
+ - You're a <get sex>.
67
+
68
+ + what is my favorite *{weight=10}
69
+ - Your favorite <star> is <get fav<star>>
70
+
71
+ + who is my (boyfriend|girlfriend|spouse){weight=10}
72
+ - <get spouse>