activematrix 0.0.10 → 0.0.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42674d998c74cf3d641f2ae9e6b0b607e4a0756f012203cc905cc41ca6f0c5cc
4
- data.tar.gz: 4570f0a311401c51339171efa0fb45080e7539829fa9704838b6df52b8070a77
3
+ metadata.gz: bd316a48de85336049741c73b39c6876ac20b5366f4e680d4507cafe734c8300
4
+ data.tar.gz: 6a80ba9a3dc0096f2a0ce9634def8f0b74f8763819f021bbca32fb875e8b3ff1
5
5
  SHA512:
6
- metadata.gz: 58b199a4db7035498f38c1b0c67634fbfc8f0e1897a28b4a1b43cf05c8c96e889e05b19c0a2fac510d7dcff115c4d81a87ec288b3ac328982b0d87fb32156626
7
- data.tar.gz: 233c93feb4984cdb41f47e98dd4f467ee8904a80eb76105d7ea3564d771ec211c14c4015c80d0a70a0821dcfa546563431f622543f51a78ad736ba557bc8ad22
6
+ metadata.gz: 305ffacaf0e9830f9c84c77d69c12ea8548831a0d03095650bb4a25a0de7322f4b2f5565b18c4cf04b65f0f43b9b7ef08a88d4a3e56ccd98da66e3bdae6130a3
7
+ data.tar.gz: 5e6005ff8af8e50e5b0865a9b0757372d6cfe3ea197db1fea13005f07d35068fb524183864ae4ac4ea8b8f43391d4a98cb1f0bcb3bcc255fad889bfc89eed9fd
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveMatrix
4
- VERSION = '0.0.10'
4
+ VERSION = '0.0.11'
5
5
  end
@@ -11,28 +11,38 @@ module ActiveMatrix
11
11
 
12
12
  argument :commands, type: :array, default: [], banner: 'command1 command2'
13
13
 
14
+ check_class_collision suffix: 'Bot'
15
+
14
16
  def create_bot_file
15
17
  template 'bot.rb.erb', "app/bots/#{file_name}_bot.rb"
16
18
  end
17
19
 
18
- def create_bot_spec
19
- template 'bot_spec.rb.erb', "spec/bots/#{file_name}_bot_spec.rb"
20
+ def create_bot_test
21
+ template 'bot_test.rb.erb', "test/bots/#{file_name}_bot_test.rb"
20
22
  end
21
23
 
22
24
  def display_usage
23
25
  say "\nBot created! To use your bot:\n\n"
24
26
  say '1. Create an agent in Rails console:'
25
- say ' agent = MatrixAgent.create!('
26
- say " name: '#{file_name}',"
27
- say " homeserver: 'https://matrix.org',"
28
- say " username: 'your_bot_username',"
29
- say " password: 'your_bot_password',"
27
+ say ' agent = ActiveMatrix::Agent.create!('
28
+ say " name: '#{file_name.dasherize}',"
29
+ say " matrix_connection: 'primary',"
30
30
  say " bot_class: '#{class_name}Bot'"
31
31
  say ' )'
32
- say "\n2. Start the agent:"
33
- say ' ActiveMatrix::AgentManager.instance.start_agent(agent)'
32
+ say "\n2. Start the daemon:"
33
+ say ' bundle exec activematrix start'
34
34
  say "\n"
35
35
  end
36
+
37
+ private
38
+
39
+ def file_name
40
+ @_file_name ||= remove_possible_suffix(super)
41
+ end
42
+
43
+ def remove_possible_suffix(name)
44
+ name.sub(/_?bot$/i, '')
45
+ end
36
46
  end
37
47
  end
38
48
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class <%= class_name %>BotTest < ActiveSupport::TestCase
6
+ setup do
7
+ @agent = ActiveMatrix::Agent.create!(
8
+ name: '<%= file_name %>_test',
9
+ homeserver: 'https://matrix.example.com',
10
+ username: 'test_bot',
11
+ bot_class: '<%= class_name %>Bot'
12
+ )
13
+ end
14
+
15
+ test 'bot class is valid' do
16
+ assert_equal '<%= class_name %>Bot', @agent.bot_class
17
+ assert @agent.valid?
18
+ end
19
+ <% if commands.any? %>
20
+ <% commands.each do |command| %>
21
+ test '<%= command %> command is defined' do
22
+ bot_class = @agent.bot_class.constantize
23
+ assert bot_class.commands.key?(:<%= command %>)
24
+ end
25
+ <% end %>
26
+ <% else %>
27
+ test 'hello command is defined' do
28
+ bot_class = @agent.bot_class.constantize
29
+ assert bot_class.commands.key?(:hello)
30
+ end
31
+
32
+ test 'broadcast command is defined' do
33
+ bot_class = @agent.bot_class.constantize
34
+ assert bot_class.commands.key?(:broadcast)
35
+ end
36
+ <% end %>
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activematrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -476,7 +476,7 @@ files:
476
476
  - lib/activematrix.rb
477
477
  - lib/generators/active_matrix/bot/bot_generator.rb
478
478
  - lib/generators/active_matrix/bot/templates/bot.rb.erb
479
- - lib/generators/active_matrix/bot/templates/bot_spec.rb.erb
479
+ - lib/generators/active_matrix/bot/templates/bot_test.rb.erb
480
480
  - lib/generators/active_matrix/install/install_generator.rb
481
481
  - lib/generators/active_matrix/install/templates/README
482
482
  - lib/generators/active_matrix/install/templates/active_matrix.rb
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe <%= class_name %>Bot do
6
- let(:agent) do
7
- MatrixAgent.create!(
8
- name: '<%= file_name %>_test',
9
- homeserver: 'https://matrix.example.com',
10
- username: 'test_bot',
11
- password: 'password',
12
- bot_class: '<%= class_name %>Bot'
13
- )
14
- end
15
-
16
- let(:client) { instance_double(ActiveMatrix::Client) }
17
- let(:room) { instance_double(ActiveMatrix::Room) }
18
- let(:bot) { described_class.new(agent) }
19
-
20
- before do
21
- allow(agent).to receive(:client).and_return(client)
22
- allow(client).to receive(:mxid).and_return('@test_bot:example.com')
23
- allow(bot).to receive(:room).and_return(room)
24
- end
25
-
26
- <% if commands.any? %>
27
- <% commands.each do |command| %>
28
- describe '#<%= command %>' do
29
- it 'responds to the <%= command %> command' do
30
- expect(room).to receive(:send_notice).twice
31
- bot.send(:<%= command %>)
32
- end
33
- end
34
-
35
- <% end %>
36
- <% else %>
37
- describe '#hello' do
38
- it 'responds with a greeting' do
39
- expect(room).to receive(:send_notice).with('Hello there!')
40
- bot.hello
41
- end
42
-
43
- it 'greets by name when provided' do
44
- expect(room).to receive(:send_notice).with('Hello, Alice!')
45
- bot.hello('Alice')
46
- end
47
- end
48
- <% end %>
49
-
50
- describe 'inter-agent communication' do
51
- let(:other_bot) { instance_double(ActiveMatrix::Bot::MultiInstanceBase, agent_name: 'other_bot') }
52
-
53
- it 'responds to ping messages' do
54
- expect(bot).to receive(:send_to_agent).with('other_bot', hash_including(type: 'pong'))
55
- bot.receive_message({ type: 'ping' }, from: other_bot)
56
- end
57
- end
58
-
59
- describe 'memory access' do
60
- it 'has access to agent memory' do
61
- expect(bot.memory).to be_a(ActiveMatrix::Memory::AgentMemory)
62
- end
63
-
64
- it 'has access to global memory' do
65
- expect(bot.global_memory).to be_a(ActiveMatrix::Memory::GlobalMemory)
66
- end
67
- end
68
- end