icqbot 0.1.3 → 0.1.4

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: 743e5831359d79b519c7c2919eef74941af16c2d6e5a2724ee950842617a6c77
4
- data.tar.gz: 664454f4c6e2e82696f0a9be6a191476a9cae82cf585b3b863c3144ace066649
3
+ metadata.gz: 26bf462455d95a0c0600e9ed437593f5c485c639de150ffff76e61cf2ba7aea0
4
+ data.tar.gz: 34c3ba04a5eb8acb1ec7ba17e04e29e9515802c21650451be8b00afe9ff9a816
5
5
  SHA512:
6
- metadata.gz: 0e0a7cb347ca9dbe5c8d735ddf3deea5c08b3f94c710c09b2a7808ae6ccb7f70afaf373ea44270b15f677624026fd954b870bb6ed0c14e8b59ab645143012fd2
7
- data.tar.gz: 7583cf6516fc863fe0de6744ee95d0ed676748fbf63b9c3bdbf7945b8e916cfc66e62c2ab79ad39b63f6d067572d5bba6d197fdee85ed16c18db2f48234bbbd9
6
+ metadata.gz: 404007e2c5bfb54e00ac84d4f4fed67ea79d0f764a007209110e58cc42198ebfc6daa32bd439496090ead2fee0f700886fb12971c57f77121f9fcb04b6642dc1
7
+ data.tar.gz: f5c46e086eb0289f47e38dc584375c6a654c1fde431aaac12de6027acb5560059dc6377c75c726f904e384c669f4d24c350e977dd0d5668ff6271169eb2a5e02
data/doc/bot.md CHANGED
@@ -93,4 +93,18 @@ def set_about chat_id, about # -> Hash
93
93
  def set_rules chat_id, rules # -> Hash
94
94
  ```
95
95
  1. `chat_id` - ID чата.
96
- 2. `rules` - правила чата.
96
+ 2. `rules` - правила чата.
97
+
98
+ ## Закрепить сообщение
99
+ ```ruby
100
+ def pin_msg msg_id, chat_id # -> Hash
101
+ ```
102
+ 1. `msg_id` - ID сообщения, что нужно закрепить.
103
+ 2. `chat_id` - ID чата.
104
+
105
+ ## Открепить сообщение
106
+ ```ruby
107
+ def unpin_msg msg_id, chat_id # -> Hash
108
+ ```
109
+ 1. `msg_id` - ID сообщения, что нужно открепить.
110
+ 2. `chat_id` - ID чата.
@@ -15,19 +15,27 @@ def initialize event_h
15
15
 
16
16
  ## Аттрибуты
17
17
  ```ruby
18
- attr_reader :type, :text, :msg_id, :chat_id, :from
18
+ attr_reader :type, :text, :msg_id, :chat_id, :from,
19
+ :data, :query_id
20
+ ```
21
+ ```ruby
19
22
  event.type # Тип события.
20
23
  event.text # текст приходящего события(обычно текст сообщения от юзера).
21
24
  event.msg_id # ID пришедшего сообщения.
22
25
  event.chat_id # ID чата, в который пришло сообщения.
23
26
  event.from # Hash | Информация от кого пришло сообщение.
27
+ # -- Аттрибуты для callback event --
28
+ event.data
29
+ event.query_id
24
30
  ```
25
31
 
32
+
26
33
  ## Типы событий
27
34
  ```ruby
28
35
  module TypeEvent
29
36
  NEW_MSG = 'newMessage'
30
37
  EDITED_MSG = 'editedMessage'
31
38
  DELETED_MSG = 'deletedMessage'
39
+ CALLBACK = 'callbackQuery'
32
40
  ... # in working
33
41
  ```
@@ -17,4 +17,13 @@ def initialize text, *keyboard
17
17
  attr_reader :text, :keyboard
18
18
  msg.text # текст сообщения(String)
19
19
  msg.keyboard # массив объектов [Button](./button.md)
20
- ```
20
+ ```
21
+
22
+ ## Добавить кнопку
23
+ ```ruby
24
+ def << btn
25
+ ```
26
+ ```ruby
27
+ alias_method :append, :<<
28
+ ```
29
+ 1. `btn` - объект типа [Button](./button.md)
@@ -6,5 +6,5 @@ require_relative './icqbot/user.rb'
6
6
  require_relative './icqbot/message.rb'
7
7
 
8
8
  module ICQ
9
- VERSION = '0.1.3'
9
+ VERSION = '0.1.4'
10
10
  end
@@ -12,6 +12,7 @@ require_relative './functional/chats/get_members.rb'
12
12
  require_relative './functional/chats/administration/set_title.rb'
13
13
  require_relative './functional/chats/administration/set_about.rb'
14
14
  require_relative './functional/chats/administration/set_rules.rb'
15
+ require_relative './functional/chats/administration/pin_unpin_msg.rb'
15
16
 
16
17
 
17
18
  module ICQ
@@ -47,15 +48,6 @@ module ICQ
47
48
  end
48
49
  end
49
50
 
50
- def last_event # FIXME: its can delete
51
- events = JSON::load(get_events.body)
52
- if events and events['events'] and events['events'] != []
53
- last_event = events['events'].last
54
- @last_event_id = last_event['eventId']
55
- yield ICQ::Event.new last_event
56
- end
57
- end
58
-
59
51
  private
60
52
  def base_req chat_id
61
53
  {
@@ -8,25 +8,35 @@ module ICQ
8
8
  NEW_MSG = 'newMessage'
9
9
  EDITED_MSG = 'editedMessage'
10
10
  DELETED_MSG = 'deletedMessage'
11
+ CALLBACK = 'callbackQuery'
11
12
  end
12
13
 
13
14
  class Event
14
- attr_reader :type, :text, :msg_id, :chat_id, :from
15
+ attr_reader :type, :text, :msg_id, :chat_id, :from,
16
+ :data, :query_id
15
17
 
16
18
  def initialize event_h
19
+ # TODO: больше информации
17
20
  @event_h = event_h
18
21
  @type = event_h['type']
19
- @text = event_h['payload']['text']
20
- @msg_id = event_h['payload']['msgId']
21
- @chat_id = event_h['payload']['chat']['chatId']
22
22
  @from = event_h['payload']['from']
23
+ if @type != ICQ::TypeEvent::CALLBACK
24
+ @text = event_h['payload']['text']
25
+ @msg_id = event_h['payload']['msgId']
26
+ @chat_id = event_h['payload']['chat']['chatId']
27
+ else
28
+ @data = event_h['payload']['callbackData']
29
+ @query_id = event_h['payload']['queryId']
30
+ @chat_id = event_h['message']['chat']['chatId']
31
+ end
23
32
  end
24
33
 
25
34
  def prefix?
26
- @text[0] == ICQ::BOT_PREFIX
35
+ @text[0] == ICQ::BOT_PREFIX if @text
27
36
  end
28
37
 
29
38
  def to_h; @event_h end
39
+ def to_s; "Event(#{@type}" + (@text ? ", #{@text}" : '') + ')' end
30
40
  end
31
41
 
32
42
  end
@@ -0,0 +1,21 @@
1
+ require_relative '../../../bot.rb'
2
+
3
+ module ICQ
4
+
5
+ class Bot
6
+ def pin_msg msg_id, chat_id
7
+ params = base_req chat_id
8
+ params['msgId'] = msg_id
9
+ JSON::load Requests.get(
10
+ URLS_API::PIN_MSG, params: params).body
11
+ end
12
+
13
+ def unpin_msg msg_id, chat_id
14
+ params = base_req chat_id
15
+ params['msgId'] = msg_id
16
+ JSON::load Requests.get(
17
+ URLS_API::UNPIN_MSG, params: params).body
18
+ end
19
+ end
20
+
21
+ end
@@ -9,6 +9,13 @@ module ICQ
9
9
  @text = obj
10
10
  @keyboard = keyboard
11
11
  end
12
+
13
+ def << btn
14
+ return @keyboard << btn if btn.is_a? ICQ::Button
15
+ raise ArgumentError.new 'btn must be a Button'
16
+ end
17
+
18
+ alias_method :append, :<<
12
19
  end
13
20
 
14
21
  class Button
@@ -11,4 +11,6 @@ module URLS_API
11
11
  SET_TITLE = 'https://api.icq.net/bot/v1/chats/setTitle'
12
12
  SET_ABOUT = 'https://api.icq.net/bot/v1/chats/setAbout'
13
13
  SET_RULES = 'https://api.icq.net/bot/v1/chats/setRules'
14
+ PIN_MSG = 'https://api.icq.net/bot/v1​/chats​/pinMessage'
15
+ UNPIN_MSG = 'https://api.icq.net/bot/v1​/chats​/unpinMessage'
14
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icqbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sheyber
@@ -53,6 +53,7 @@ files:
53
53
  - lib/icqbot.rb
54
54
  - lib/icqbot/bot.rb
55
55
  - lib/icqbot/event.rb
56
+ - lib/icqbot/functional/chats/administration/pin_unpin_msg.rb
56
57
  - lib/icqbot/functional/chats/administration/set_about.rb
57
58
  - lib/icqbot/functional/chats/administration/set_rules.rb
58
59
  - lib/icqbot/functional/chats/administration/set_title.rb