jabot 0.1 → 0.2

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
  SHA1:
3
- metadata.gz: ff021f217c892d1015fe7791c05bc2bf095997cc
4
- data.tar.gz: 902785b742bd60b0f56f1b1d973f608a33de684d
3
+ metadata.gz: 115cb996f99108b9fc761fe4bef7f03f26a0b6ee
4
+ data.tar.gz: 4141684ea21bd308543c594acffe4d290841a95a
5
5
  SHA512:
6
- metadata.gz: 82fe2c43436564e7c89020ee325f69bd7ff051a93ed66be9ae8cd9f7dfdf108b2d130225b421c28423047a8f20a0cd236b3b787a5af4baaec08399efa39fe4d0
7
- data.tar.gz: 94ef967101953ade0fe2258cca734d45bc7d4910e9ba7cd38889c646e1397fca2807d5b41eb7b04768b4eb2634a9a1e49fcc19bfef4e7cec6e014148201dc863
6
+ metadata.gz: e4aa4e355c67f4ca36cc3c8b8c11fb148b8d98a50dc8ad9284745ff9cb0445022272f59f9a333c7f97ea249793b2f9db140ca355c7012ca7cae2ee757996b537
7
+ data.tar.gz: 26d8f741a7a19b5a59077fc4e52736de6bb2c440f5c98a1865433e3b409f5894843e04bc3f52bb3cb2d292c931441bfbe8b163c578c77170e4187d33d6b15af2
data/lib/jabot.rb CHANGED
@@ -6,23 +6,23 @@ require 'jabot/dsl'
6
6
 
7
7
  module Jabot
8
8
 
9
- class Base
9
+ class Base
10
10
  include Jabot::DSL
11
11
 
12
- attr_reader :jabber, :commands
13
- attr_accessor :config
12
+ attr_reader :jabber, :commands
13
+ attr_accessor :config
14
14
 
15
- def initialize
16
- @config = {
17
- username: '',
18
- password: '',
15
+ def initialize
16
+ @config = {
17
+ username: '',
18
+ password: '',
19
19
  clients: []
20
- }
20
+ }
21
21
  @standalone_mode = false
22
22
  end
23
23
 
24
- def configure(&block)
25
- @commands = Commands.new
24
+ def configure(&block)
25
+ @commands = Commands.new
26
26
  standard_commands
27
27
  instance_eval(&block)
28
28
 
@@ -32,7 +32,7 @@ module Jabot
32
32
  end
33
33
  end
34
34
 
35
- def start_listen
35
+ def start_listen
36
36
  @jabber.listen do |message, sender_id|
37
37
  begin
38
38
  result = @commands.run(message)
@@ -52,11 +52,11 @@ module Jabot
52
52
 
53
53
  #add standard commands
54
54
  def standard_commands
55
- command :quit do
56
- @jabber.stop
55
+ command :stop do
56
+ @jabber.disconnect
57
57
  end
58
58
  end
59
- end
59
+ end
60
60
 
61
61
  #start jabot
62
62
  #
@@ -76,10 +76,10 @@ module Jabot
76
76
  # 'Hello!'
77
77
  # end
78
78
  #end
79
- def self.start(&block)
80
- @base = Base.new
79
+ def self.start(&block)
80
+ @base = Base.new
81
81
  @base.configure(&block)
82
- @base.start_listen
82
+ @base.start_listen
83
83
  end
84
84
 
85
85
  end
@@ -1,42 +1,42 @@
1
1
  #encoding: utf-8
2
2
 
3
3
  module Jabot
4
- class Commands
4
+ class Commands
5
5
 
6
6
  class CommandNotExists < StandardError; end
7
7
 
8
- def initialize
9
- @commands_list = {}
10
- end
8
+ def initialize
9
+ @commands_list = {}
10
+ end
11
11
 
12
- def add_command(name, &block)
13
- @commands_list[name] = block unless command_exists? name
14
- end
12
+ def add_command(name, &block)
13
+ @commands_list[name] = block unless command_exists? name
14
+ end
15
15
 
16
- def command_exists?(command_name)
17
- @commands_list.include? command_name
16
+ def command_exists?(command_name)
17
+ @commands_list.include? command_name
18
18
  end
19
19
 
20
- def run(command_line)
20
+ def run(command_line)
21
21
  c = parse command_line
22
22
  unless command_exists? c[:name].downcase
23
23
  raise CommandNotExists, "command '#{c[:name]}' not found"
24
24
  end
25
25
 
26
26
  begin
27
- @commands_list[ c[:name].downcase ].call( *c[:args] )
27
+ @commands_list[c[:name].downcase].call(*c[:args])
28
28
  rescue
29
29
  'Error while executing command'
30
30
  end
31
- end
32
-
33
- def parse(command_line)
34
- args = command_line.split
35
- {
36
- :name => args.shift.to_sym,
37
- :args => args
38
- }
39
31
  end
40
32
 
41
- end
33
+ def parse(command_line)
34
+ args = command_line.split
35
+ {
36
+ :name => args.shift.to_sym,
37
+ :args => args
38
+ }
39
+ end
40
+
41
+ end
42
42
  end
data/lib/jabot/dsl.rb CHANGED
@@ -1,25 +1,24 @@
1
-
2
1
  module Jabot
3
- module DSL
4
- def command(name, &block)
2
+ module DSL
3
+ def command(name, &block)
5
4
  @commands.add_command(name, &block)
6
- end
5
+ end
7
6
 
8
- def username(value)
9
- @config[:username] = value
10
- end
7
+ def username(value)
8
+ @config[:username] = value
9
+ end
11
10
 
12
- def password(value)
13
- @config[:password] = value
14
- end
11
+ def password(value)
12
+ @config[:password] = value
13
+ end
15
14
 
16
- def clients(list)
17
- raise StandardError, 'Clients list must be an array' unless list.is_a?(Array)
18
- @config[:clients] = list
15
+ def clients(list)
16
+ raise StandardError, 'Clients list must be an array' unless list.is_a?(Array)
17
+ @config[:clients] = list
19
18
  end
20
19
 
21
20
  def standalone_mode
22
21
  @standalone_mode = true
23
22
  end
24
- end
23
+ end
25
24
  end
data/lib/jabot/jabber.rb CHANGED
@@ -4,19 +4,19 @@ require 'xmpp4r/client'
4
4
 
5
5
  module Jabot
6
6
 
7
- class Jabber
8
- include ::Jabber
7
+ class Jabber
8
+ include ::Jabber
9
9
  ::Jabber.debug = false
10
10
 
11
- attr_reader :remote_clients
11
+ attr_reader :remote_clients
12
12
  attr_reader :is_listen
13
13
 
14
- def initialize(options)
15
- @client_id = options[:client_id]
16
- @client_password = options[:client_password]
14
+ def initialize(options)
15
+ @client_id = options[:client_id]
16
+ @client_password = options[:client_password]
17
17
 
18
- @remote_clients = []
19
- @is_listen = false
18
+ @remote_clients = []
19
+ @is_listen = false
20
20
 
21
21
  @client = Client::new JID::new(@client_id + '/bot')
22
22
  #@client.on_exception do
@@ -24,44 +24,44 @@ module Jabot
24
24
  # connect
25
25
  #end
26
26
 
27
- connect
27
+ connect
28
28
  end
29
29
 
30
- def connect
31
- @client.connect
32
- @client.auth @client_password
30
+ def connect
31
+ @client.connect
32
+ @client.auth @client_password
33
33
 
34
- presence = Presence.new(:dnd, 'server running')
35
- @client.send presence
36
- end
34
+ presence = Presence.new(:dnd, 'server running')
35
+ @client.send presence
36
+ end
37
37
 
38
- def disconnect
38
+ def disconnect
39
39
  @is_listen = false
40
- @client.close
41
- end
40
+ @client.close
41
+ end
42
42
 
43
- def add_remote_client(id)
44
- @remote_clients << id unless @remote_clients.include?(id)
45
- end
43
+ def add_remote_client(id)
44
+ @remote_clients << id unless @remote_clients.include?(id)
45
+ end
46
46
 
47
- def send_to_all(text)
48
- @remote_clients.each do |to|
49
- send to, text
50
- end
51
- end
47
+ def send_to_all(text)
48
+ @remote_clients.each do |to|
49
+ send to, text
50
+ end
51
+ end
52
52
 
53
- def send(to, text)
54
- message = Message::new to, text
55
- @client.send message
56
- end
53
+ def send(to, text)
54
+ message = Message::new to, text
55
+ @client.send message
56
+ end
57
57
 
58
- def listen
59
- @is_listen = true
58
+ def listen
59
+ @is_listen = true
60
60
 
61
61
  @message_callback = @client.add_message_callback 0, @message_callback do |m|
62
- if m.type != :error
63
- sender_id = "#{m.from.node}@#{m.from.domain}"
64
- #puts' "Message received from "' + sender_id# + ": " + m.body
62
+ if m.type != :error
63
+ sender_id = "#{m.from.node}@#{m.from.domain}"
64
+ #puts' "Message received from "' + sender_id# + ": " + m.body
65
65
  unless m.body.nil?
66
66
  if @remote_clients.include?(sender_id)
67
67
  yield(m.body, sender_id) if block_given?
@@ -73,10 +73,6 @@ module Jabot
73
73
  end
74
74
  end
75
75
 
76
- def stop
77
- @is_listen = false
78
- end
79
-
80
- end
76
+ end
81
77
 
82
78
  end
data/lib/jabot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jabot
2
- VERSION = '0.1'
2
+ VERSION = '0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jabot
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Skat