vk_cozy 0.3.8 → 0.3.9

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: 88f8d21019678635297581f40f48e83e71cc79bfe2db701cd3c6b6815df8c5d0
4
- data.tar.gz: 2a3e5cfce38ec22b4d20f36b3f50e6c2d5b508a09e854186c5aeb90fa858ff80
3
+ metadata.gz: 3f3e335ff0f9eb232d5a3f259a79592723ee5d5cb785bfb619cd4eb81be11f5a
4
+ data.tar.gz: 6c95df5ab9e7c6bd4ae7dd672786526bbfa4d8aa974ecea4cf564caa6859f627
5
5
  SHA512:
6
- metadata.gz: b02bf27e35dd324d7497ff0d2bd7f4a952b313cb94fc897c3e190b510881d870efe4e17c1c912dcdf5a596aaf2842608d94d44f6b6432c8cbae7778cb38340e9
7
- data.tar.gz: f2b9dbac5adb7488dcf8db32189ab9d80c514ed8acefc20782ba9ded4275ea6214c8023747e0d5dee8bef70f9bdb804911a31c58f856d8ffce100a4d2160401e
6
+ metadata.gz: b7305aa9a7a4da1fb754d4115d6087274e11e7139b56a4028cb557fbc9a98e89b5fc78aad0ab55522094cba6125c18a9865a72728b6509891e3324227b5a9cc3
7
+ data.tar.gz: e3b6b8a3ce259097d50c3fce526474f6564dae1c74c25803903b68759643b12a81669ffc6c5fd5ac6e89bbfc8ebbc1517632743f632434b95b36067ff9562905
@@ -44,7 +44,7 @@ module VkCozy
44
44
  end
45
45
 
46
46
  def filter(event)
47
- for handler in get_handlers(event.type) + @handlers['*']
47
+ for handler in get_handlers(event.type) + get_handlers('*')
48
48
  if handler.check(event)
49
49
  return true
50
50
  end
@@ -55,9 +55,11 @@ module VkCozy
55
55
  if func.is_a?(Symbol)
56
56
  func = method(func)
57
57
  end
58
+
58
59
  if @handlers[type].nil?
59
60
  @handlers[type] = []
60
61
  end
62
+
61
63
  @handlers[type] << Bothandler.new(filter, func)
62
64
  end
63
65
 
@@ -1,40 +1,74 @@
1
1
  module VkCozy
2
+
3
+ class UserHandler
4
+ def initialize(filter, func, stop: true)
5
+ @filter = filter
6
+ @func = func
7
+ @stop = stop
8
+ end
9
+
10
+ def check(event)
11
+ check_user = @filter.check_user(event)
12
+ if check_user
13
+ if check_user.is_a?(Symbol)
14
+ return true
15
+ elsif check_user.is_a?(Hash)
16
+ @func.call(event, check_user)
17
+ else
18
+ @func.call(event)
19
+ end
20
+
21
+ if @stop
22
+ return true
23
+ end
24
+ end
25
+ end
26
+ end
27
+
2
28
  class UserLabeler
3
29
  attr_reader :api
4
30
 
5
31
  def initialize(api)
6
32
  @api = api
7
- @rules = []
33
+ @handlers = {'*' => []}
34
+ end
35
+
36
+ def get_handlers(type)
37
+ if @handlers[type].nil?
38
+ return []
39
+ else
40
+ return @handlers[type]
41
+ end
8
42
  end
9
43
 
10
44
  def filter(event_raw)
11
45
  event = VkCozy::UserEvent.new(@api, event_raw)
12
- for i in @rules
13
- f = i[:filter]
14
- check = f.check_user(event)
15
- if check
16
- if check.is_a?(Symbol)
17
- check = [Symbol]
18
- elsif check.is_a?(Array)
19
- i[:func].call(event, *check)
20
- elsif check.is_a?(Hash)
21
- i[:func].call(event, **check)
22
- else
23
- i[:func].call(event)
24
- end
46
+ puts event
47
+ for handler in get_handlers(event.type) + get_handlers('*')
48
+ if handler.check(event)
25
49
  return true
26
50
  end
27
51
  end
28
52
  end
29
53
 
30
- def message_handler(filter, func)
54
+ def add_handler(filter, func, type: '*')
31
55
  if func.is_a?(Symbol)
32
56
  func = method(func)
33
57
  end
34
- @rules << {
35
- :func => func,
36
- :filter => filter
37
- }
58
+
59
+ if @handlers[type].nil?
60
+ @handlers[type] = []
61
+ end
62
+
63
+ @handlers[type] << UserHandler.new(filter, func)
64
+ end
65
+
66
+ def message_handler(filter, func)
67
+ add_handler(filter, func, type: VkCozy::UserEventType::MESSAGE_NEW)
68
+ end
69
+
70
+ def handler(filter, func)
71
+ add_handler(filter, func)
38
72
  end
39
73
  end
40
74
  end
@@ -53,12 +53,22 @@ module VkCozy
53
53
  VkCozy::UserEventType::RESET_MESSAGE_FLAGS => [MSGID, 'mask'] + MESSAGE_EXTRA_FIELDS,
54
54
  VkCozy::UserEventType::MESSAGE_NEW => [MSGID, 'flags'] + MESSAGE_EXTRA_FIELDS,
55
55
  VkCozy::UserEventType::MESSAGE_EDIT => [MSGID, 'mask'] + MESSAGE_EXTRA_FIELDS,
56
+
56
57
  VkCozy::UserEventType::IN_READ => ['peer_id', 'local_id'],
57
58
  VkCozy::UserEventType::OUT_READ => ['peer_id', 'local_id'],
59
+
58
60
  VkCozy::UserEventType::FRIEND_ONLINE => ['user_id', 'extra', 'timestamp'],
59
61
  VkCozy::UserEventType::FRIEND_OFFLINE => ['user_id', 'flags', 'timestamp'],
60
- VkCozy::UserEventType::DIALOG_TYPING_STATE => ['user_id', 'flags']
62
+
63
+ VkCozy::UserEventType::CHAT_EDIT => ['chat_id', 'self'],
64
+ VkCozy::UserEventType::CHAT_INFO_EDIT => ['type_id', 'peer_id', 'info'],
65
+
66
+ VkCozy::UserEventType::DIALOG_TYPING_STATE => ['user_id', 'flags'],
67
+ VkCozy::UserEventType::CHAT_TYPING_STATE => ['user_id', 'chat_id'],
68
+
69
+ VkCozy::UserEventType::COUNTER => ['count']
61
70
  }
71
+
62
72
  PARSE_PEER_ID_EVENTS = EVENT_ATTRS_MAPPING.map{|k, v| if v.include?('peer_id') then k end}.select{ |i| not i.nil? }
63
73
  PARSE_MESSAGE_FLAGS_EVENTS = [
64
74
  VkCozy::UserEventType::REPLACE_MESSAGE_FLAGS,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vk_cozy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danil Konenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-13 00:00:00.000000000 Z
11
+ date: 2022-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inum