del 0.1.1 → 0.1.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 +4 -4
- data/exe/del +1 -2
- data/lib/del/connection.rb +5 -4
- data/lib/del/default_router.rb +7 -0
- data/lib/del/repository.rb +16 -0
- data/lib/del/robot.rb +7 -17
- data/lib/del/version.rb +1 -1
- data/lib/del.rb +12 -4
- metadata +3 -4
- data/lib/del/room_repository.rb +0 -11
- data/lib/del/user.rb +0 -7
- data/lib/del/user_repository.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c574a58daf5543a9f5d1f49c78d7fd78f67864eb1050e7188dcb4e14b7039c24
|
4
|
+
data.tar.gz: d55ed1168a7a9b1aaeb5a0acc6fa250660e91d0911620a6a9f58ac1a0f0dada4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7a6b876e15aa871a6269535dad1a5c2fbdd8271aa65bef32ae6b24f57bc300c482619351e03484aaff40cadbaa89a743242e6f653481105469a707c08ed9421
|
7
|
+
data.tar.gz: c9033ec43b82049cc6c5adbb1a77236f7c615929139a9b4493221840860aeb85000cdf13cb795d9e71f14c69e27ab65c10cc341af7b8a29cd456a2642afed6d0
|
data/exe/del
CHANGED
data/lib/del/connection.rb
CHANGED
@@ -2,14 +2,15 @@ module Del
|
|
2
2
|
class Connection
|
3
3
|
attr_reader :configuration, :rooms, :users
|
4
4
|
|
5
|
-
def initialize(configuration
|
5
|
+
def initialize(configuration:)
|
6
6
|
@configuration = configuration
|
7
|
-
@rooms = rooms
|
8
|
-
@users = users
|
7
|
+
@rooms = configuration[:rooms]
|
8
|
+
@users = configuration[:users]
|
9
9
|
end
|
10
10
|
|
11
11
|
def connect(robot)
|
12
12
|
client.on_exception do |error, connection, error_source|
|
13
|
+
Del.logger.error(error)
|
13
14
|
disconnect
|
14
15
|
end
|
15
16
|
client.connect(configuration[:host])
|
@@ -17,7 +18,7 @@ module Del
|
|
17
18
|
client.auth(configuration[:password])
|
18
19
|
roster = Jabber::Roster::Helper.new(client, false)
|
19
20
|
roster.add_update_callback do |old_item, item|
|
20
|
-
users.
|
21
|
+
users.upsert(item['jid'], item.attributes.to_h) if item
|
21
22
|
end
|
22
23
|
roster.get_roster
|
23
24
|
roster.wait_for_roster
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Del
|
2
|
+
class Repository
|
3
|
+
def initialize(storage = {})
|
4
|
+
@storage = storage
|
5
|
+
end
|
6
|
+
|
7
|
+
def find_by(id)
|
8
|
+
@storage[id]
|
9
|
+
end
|
10
|
+
|
11
|
+
def upsert(id, attributes = {})
|
12
|
+
Del.logger.debug([id, attributes].inspect)
|
13
|
+
@storage[id] = attributes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/del/robot.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Del
|
2
2
|
class Robot
|
3
|
-
attr_reader :connection
|
3
|
+
attr_reader :connection, :router
|
4
|
+
attr_reader :users, :rooms
|
4
5
|
|
5
6
|
def initialize(configuration:)
|
6
|
-
@connection = Connection.new(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
)
|
7
|
+
@connection = Connection.new(configuration: configuration)
|
8
|
+
@router = configuration[:router]
|
9
|
+
@users = configuration[:users]
|
10
|
+
@rooms = configuration[:rooms]
|
11
11
|
end
|
12
12
|
|
13
13
|
def get_funky!
|
@@ -18,21 +18,11 @@ module Del
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def receive(message)
|
21
|
-
|
21
|
+
router.route(message)
|
22
22
|
end
|
23
23
|
|
24
24
|
def send_message(jid, message)
|
25
25
|
connection.deliver(jid, message)
|
26
26
|
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def users
|
31
|
-
@users ||= UserRepository.new
|
32
|
-
end
|
33
|
-
|
34
|
-
def rooms
|
35
|
-
@rooms ||= RoomRepository.new
|
36
|
-
end
|
37
27
|
end
|
38
28
|
end
|
data/lib/del/version.rb
CHANGED
data/lib/del.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require "dotenv"
|
2
|
+
require "logger"
|
2
3
|
require "xmpp4r"
|
3
4
|
require "xmpp4r/muc/helper/mucbrowser"
|
4
5
|
require "xmpp4r/muc/helper/simplemucclient"
|
5
6
|
require "xmpp4r/roster/helper/roster"
|
6
7
|
|
7
8
|
require "del/connection"
|
9
|
+
require "del/default_router"
|
8
10
|
require "del/robot"
|
9
|
-
require "del/
|
10
|
-
require "del/user"
|
11
|
-
require "del/user_repository"
|
11
|
+
require "del/repository"
|
12
12
|
require "del/version"
|
13
13
|
|
14
14
|
module Del
|
15
15
|
def self.start(dotenv_file:)
|
16
16
|
puts "Loading... #{dotenv_file}"
|
17
|
-
Dotenv.load(dotenv_file)
|
17
|
+
Dotenv.load(dotenv_file.to_s)
|
18
18
|
puts "It's fire! 🔥"
|
19
19
|
del = Robot.new(configuration: configuration)
|
20
20
|
del.get_funky!
|
@@ -28,8 +28,16 @@ module Del
|
|
28
28
|
@configuration ||= {
|
29
29
|
host: ENV.fetch("DEL_HOST"),
|
30
30
|
jid: ENV.fetch("DEL_JID"),
|
31
|
+
logger: Logger.new(STDOUT),
|
31
32
|
muc_domain: ENV.fetch("DEL_MUC_DOMAIN"),
|
32
33
|
password: ENV.fetch("DEL_PASSWORD"),
|
34
|
+
rooms: Repository.new,
|
35
|
+
router: DefaultRouter.new,
|
36
|
+
users: Repository.new,
|
33
37
|
}
|
34
38
|
end
|
39
|
+
|
40
|
+
def self.logger
|
41
|
+
@logger ||= configuration[:logger]
|
42
|
+
end
|
35
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: del
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo
|
@@ -101,10 +101,9 @@ files:
|
|
101
101
|
- exe/del
|
102
102
|
- lib/del.rb
|
103
103
|
- lib/del/connection.rb
|
104
|
+
- lib/del/default_router.rb
|
105
|
+
- lib/del/repository.rb
|
104
106
|
- lib/del/robot.rb
|
105
|
-
- lib/del/room_repository.rb
|
106
|
-
- lib/del/user.rb
|
107
|
-
- lib/del/user_repository.rb
|
108
107
|
- lib/del/version.rb
|
109
108
|
homepage: https://www.mokhan.ca
|
110
109
|
licenses:
|
data/lib/del/room_repository.rb
DELETED
data/lib/del/user.rb
DELETED