vk_cozy 0.3.1 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vk_cozy/bot.rb +3 -1
- data/lib/vk_cozy/dev/keyboard/action.rb +72 -0
- data/lib/vk_cozy/dev/keyboard/button.rb +34 -0
- data/lib/vk_cozy/dev/keyboard/color.rb +10 -0
- data/lib/vk_cozy/dev/keyboard/keyboard.rb +48 -0
- data/lib/vk_cozy.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ff934ed3de889cad7691093027e24648bd20cbc8bfcc7302c0fbcc53a34e79e
|
4
|
+
data.tar.gz: e824e451aa36108fb9b5fee80c7e0c289aefc65cb9c0afb65e23e9d371c79421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7b7b564065b60f8e789e56c82ed9da73600650a05c7a71bc9057d966e04262ecf683d24c2304e7570c284e94209b37fb5166c5ea94ac3e13e094e344c759510
|
7
|
+
data.tar.gz: b076661eaab47055f6e7ee4f705892dbbc1c1f02d9069858b06c42361cae86a38139639a61072a33736eab2f7e4a524b4b2cfa3e5d9b511d37b8e3d94279a7cc
|
data/lib/vk_cozy/bot.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative 'types/events/bot_events'
|
|
2
2
|
require_relative 'dispatch/views/bot/event'
|
3
3
|
require_relative 'framework/labeler/bot'
|
4
4
|
require_relative 'polling/bot_polling'
|
5
|
+
require_relative 'dev/keyboard/keyboard'
|
5
6
|
|
6
7
|
module VkCozy
|
7
8
|
class Bot
|
@@ -42,7 +43,8 @@ module VkCozy
|
|
42
43
|
@polling.listen do |event|
|
43
44
|
for event_raw in event['updates']
|
44
45
|
begin
|
45
|
-
|
46
|
+
event_raw = parse_event(event_raw)
|
47
|
+
if @labeler.filter(event_raw)
|
46
48
|
next
|
47
49
|
end
|
48
50
|
rescue Exception => e
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Keyboard
|
2
|
+
class BaseAction
|
3
|
+
attr_reader :type
|
4
|
+
|
5
|
+
def get_data
|
6
|
+
instance_variables.each_with_object({}) do |k, h|
|
7
|
+
var = instance_variable_get("#{k}")
|
8
|
+
if not var.nil?
|
9
|
+
h[k.to_s.gsub('@', '')] = var
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Text < BaseAction
|
16
|
+
def initialize(label, payload: nil)
|
17
|
+
@type = 'text'
|
18
|
+
|
19
|
+
@label = label
|
20
|
+
@payload = payload
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class OpenLink < BaseAction
|
25
|
+
def initialize(label, link, payload: nil)
|
26
|
+
@type = 'open_link'
|
27
|
+
|
28
|
+
@label = label
|
29
|
+
@link = link
|
30
|
+
@payload = payload
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Location < BaseAction
|
35
|
+
def initialize(payload: nil)
|
36
|
+
@type = 'location'
|
37
|
+
|
38
|
+
@payload = payload
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class VkPay < BaseAction
|
43
|
+
def initialize(payload: nil, hash: nil)
|
44
|
+
@type = 'vkpay'
|
45
|
+
|
46
|
+
@payload = payload
|
47
|
+
@hash = hash
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class VkApps < BaseAction
|
52
|
+
def initialize(app_id, owner_id, payload: nil, label: nil, hash: nil)
|
53
|
+
@type = 'open_app'
|
54
|
+
|
55
|
+
@app_id = app_id
|
56
|
+
@owner_id = owner_id
|
57
|
+
@payload = payload
|
58
|
+
@label = label
|
59
|
+
@hash = hash
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
class Callback < BaseAction
|
65
|
+
def initialize(label, payload)
|
66
|
+
@type = 'callback'
|
67
|
+
|
68
|
+
@label = label
|
69
|
+
@payload = payload
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Keyboard
|
2
|
+
class KeyboardButton
|
3
|
+
def initialize(action, color: nil, data: nil)
|
4
|
+
@action = action
|
5
|
+
@color = color
|
6
|
+
@data = data
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.from_typed(action, color: nil)
|
10
|
+
return self.new(action, color: color, data: nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from_hash(data)
|
14
|
+
color = data.key('color')
|
15
|
+
keyboard_data = {'action' => data}
|
16
|
+
if color.nil?
|
17
|
+
keyboard_data['action'].delete('color')
|
18
|
+
keyboard_data['color'] = color
|
19
|
+
end
|
20
|
+
return self.new(self.action, self.color, keyboard_data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_data
|
24
|
+
if not @data.nil?
|
25
|
+
return @data
|
26
|
+
end
|
27
|
+
data = {'action' => @action.get_data()}
|
28
|
+
if ['text', 'callback'].include?(@action.type) and not @color.nil?
|
29
|
+
data['color'] = @color
|
30
|
+
end
|
31
|
+
return data
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative 'action'
|
2
|
+
require_relative 'button'
|
3
|
+
require_relative 'color'
|
4
|
+
|
5
|
+
module Keyboard
|
6
|
+
class Keyboard
|
7
|
+
def initialize(one_time: false, inline: false)
|
8
|
+
@one_time = one_time
|
9
|
+
@inline = inline
|
10
|
+
@buttons = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def row()
|
14
|
+
@buttons << []
|
15
|
+
return self
|
16
|
+
end
|
17
|
+
|
18
|
+
def add(action, color=nil)
|
19
|
+
if @buttons.length == 0
|
20
|
+
row()
|
21
|
+
end
|
22
|
+
button = KeyboardButton.from_typed(action, color: color)
|
23
|
+
@buttons[-1] << button
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_json()
|
28
|
+
_buttons = []
|
29
|
+
for row in @buttons
|
30
|
+
buttons = []
|
31
|
+
for button in row
|
32
|
+
buttons << button.get_data()
|
33
|
+
end
|
34
|
+
_buttons << buttons
|
35
|
+
end
|
36
|
+
data = {
|
37
|
+
'one_time' => @one_time,
|
38
|
+
'inline' => @inline,
|
39
|
+
'buttons' => _buttons
|
40
|
+
}
|
41
|
+
return data
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
return JSON.generate(get_json())
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/vk_cozy.rb
CHANGED
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.
|
4
|
+
version: 0.3.6
|
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-
|
11
|
+
date: 2022-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inum
|
@@ -62,6 +62,10 @@ files:
|
|
62
62
|
- lib/vk_cozy.rb
|
63
63
|
- lib/vk_cozy/api/api.rb
|
64
64
|
- lib/vk_cozy/bot.rb
|
65
|
+
- lib/vk_cozy/dev/keyboard/action.rb
|
66
|
+
- lib/vk_cozy/dev/keyboard/button.rb
|
67
|
+
- lib/vk_cozy/dev/keyboard/color.rb
|
68
|
+
- lib/vk_cozy/dev/keyboard/keyboard.rb
|
65
69
|
- lib/vk_cozy/dispatch/views/bot/event.rb
|
66
70
|
- lib/vk_cozy/dispatch/views/user/event.rb
|
67
71
|
- lib/vk_cozy/framework/labeler/bot.rb
|