icqbot 0.1.2 → 0.1.7
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/.gitignore +2 -1
- data/README.md +2 -1
- data/bin/bot_with_handlers.rb +13 -0
- data/doc/bot.md +68 -1
- data/doc/event.md +9 -1
- data/doc/message.md +11 -2
- data/icqbot.gemspec +25 -25
- data/lib/icqbot.rb +1 -1
- data/lib/icqbot/bot.rb +21 -8
- data/lib/icqbot/event.rb +15 -5
- data/lib/icqbot/functional/chats/administration/block_unblock_user.rb +27 -0
- data/lib/icqbot/functional/chats/administration/pin_unpin_msg.rb +21 -0
- data/lib/icqbot/functional/chats/administration/set_about.rb +14 -0
- data/lib/icqbot/functional/chats/administration/set_rules.rb +14 -0
- data/lib/icqbot/functional/chats/administration/set_title.rb +18 -0
- data/lib/icqbot/message.rb +7 -0
- data/lib/icqbot/urls_api.rb +7 -0
- metadata +8 -3
- data/doc/user.md +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2476d6444ccc42193d8107657feda1832784bede5714c6a4f7734ab51cd26b71
|
4
|
+
data.tar.gz: d813abef94c9e009ba7b1a2cc0dae3505b3cac053188f4a52f4bbf67afbac5bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0eab2d54a5842addbaa53267b8209d0227c5be8fa790e31c7894f050ce6ff94d2630c02f3f346a32d65e40311fd31a28c5459bf965a0d776ac4ae5731bc063b
|
7
|
+
data.tar.gz: 1a3a4437f11ccd39128a777e588d1f723bb9fc648fac18eeb217239a8bd5e550149e923a90f88e356d82016666de6ff7e04039c841c722ea27686584ba86d22f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
icq-bot-ruby
|
2
|
+
icq-bot-ruby :diamonds:
|
3
3
|
------------
|
4
4
|
Ruby wrapper for [ICQ Bot API](https://icq.com/botapi/)
|
5
5
|
|
@@ -21,6 +21,7 @@ ICQ::Bot.new('token') do |bot|
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
```
|
24
|
+
more examples in `bin/`
|
24
25
|
|
25
26
|
## Docs
|
26
27
|
* **[Documentation](./doc/overview.md)**
|
data/doc/bot.md
CHANGED
@@ -23,6 +23,20 @@ def listen
|
|
23
23
|
bot.loop = false
|
24
24
|
```
|
25
25
|
|
26
|
+
## Добавить handler(обработчик событий)
|
27
|
+
```ruby
|
28
|
+
def add_handler text, handler
|
29
|
+
```
|
30
|
+
1. `text` - текст события.
|
31
|
+
2. `handler` - анонимная функция(принимает объект типа [Event](./event.md)), которая сработает при получение события с текстом идентичном `text`.
|
32
|
+
|
33
|
+
## Добавить callback handler
|
34
|
+
```ruby
|
35
|
+
def add_callback_handler data, handler
|
36
|
+
```
|
37
|
+
1. `data` - текст события..
|
38
|
+
2. `handler` - анонимная функция(принимает объект типа [Event](./event.md)), которая сработает при получение callback события с идентификатор идентичным `data`.
|
39
|
+
|
26
40
|
## Отправить сообщение
|
27
41
|
```ruby
|
28
42
|
def send_msg msg, chat_id # -> Hash
|
@@ -69,4 +83,57 @@ def get_blocked_users chat_id # -> [Hash]
|
|
69
83
|
```ruby
|
70
84
|
def get_admins chat_id # -> [Hash]
|
71
85
|
```
|
72
|
-
1. `chat_id` - ID чата, откуда надо получить список aдминов.
|
86
|
+
1. `chat_id` - ID чата, откуда надо получить список aдминов.
|
87
|
+
|
88
|
+
# Chat administration
|
89
|
+
Для работы этих методов бот должен иметь права администрации.
|
90
|
+
|
91
|
+
## Установка названия чата
|
92
|
+
```ruby
|
93
|
+
def set_title chat_id, title # -> Hash
|
94
|
+
```
|
95
|
+
1. `chat_id` - ID чата.
|
96
|
+
2. `title` - новое название чата.
|
97
|
+
|
98
|
+
## Установка описания чата
|
99
|
+
```ruby
|
100
|
+
def set_about chat_id, about # -> Hash
|
101
|
+
```
|
102
|
+
1. `chat_id` - ID чата.
|
103
|
+
2. `about` - новое описание чата.
|
104
|
+
|
105
|
+
## Установка правил чата
|
106
|
+
```ruby
|
107
|
+
def set_rules chat_id, rules # -> Hash
|
108
|
+
```
|
109
|
+
1. `chat_id` - ID чата.
|
110
|
+
2. `rules` - правила чата.
|
111
|
+
|
112
|
+
## Закрепить сообщение
|
113
|
+
```ruby
|
114
|
+
def pin_msg msg_id, chat_id # -> Hash
|
115
|
+
```
|
116
|
+
1. `msg_id` - ID сообщения, что нужно закрепить.
|
117
|
+
2. `chat_id` - ID чата.
|
118
|
+
|
119
|
+
## Открепить сообщение
|
120
|
+
```ruby
|
121
|
+
def unpin_msg msg_id, chat_id # -> Hash
|
122
|
+
```
|
123
|
+
1. `msg_id` - ID сообщения, что нужно открепить.
|
124
|
+
2. `chat_id` - ID чата.
|
125
|
+
|
126
|
+
## Забанить участника
|
127
|
+
```ruby
|
128
|
+
def block_user user_id, chat_id, del_last_msg=false # -> Hash
|
129
|
+
```
|
130
|
+
1. `user_id` - ID пользователя, который должен отлететь в бан.
|
131
|
+
2. `chat_id` - ID чата, где забанят.
|
132
|
+
3. `del_last_msg` - удалить или нет последние сообщение пользователя.
|
133
|
+
|
134
|
+
## Разбанить участника
|
135
|
+
```ruby
|
136
|
+
def unblock_user user_id, chat_id # -> Hash
|
137
|
+
```
|
138
|
+
1. `user_id` - ID пользователя, который должен вернуться из бана.
|
139
|
+
2. `chat_id` - ID чата, где разабанят.
|
data/doc/event.md
CHANGED
@@ -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
|
```
|
data/doc/message.md
CHANGED
@@ -16,5 +16,14 @@ def initialize text, *keyboard
|
|
16
16
|
```ruby
|
17
17
|
attr_reader :text, :keyboard
|
18
18
|
msg.text # текст сообщения(String)
|
19
|
-
msg.keyboard # массив объектов
|
20
|
-
```
|
19
|
+
msg.keyboard # массив объектов Button
|
20
|
+
```
|
21
|
+
|
22
|
+
## Добавить кнопку
|
23
|
+
```ruby
|
24
|
+
def << btn
|
25
|
+
```
|
26
|
+
```ruby
|
27
|
+
alias_method :append, :<<
|
28
|
+
```
|
29
|
+
1. `btn` - объект типа [Button](./button.md)
|
data/icqbot.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
require_relative './lib/icqbot.rb'
|
2
|
-
|
3
|
-
lib = File.expand_path('../lib', __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = "icqbot"
|
8
|
-
s.version = ICQ::VERSION
|
9
|
-
s.authors = ["sheyber"]
|
10
|
-
s.email = ["ukt1@ro.ru"]
|
11
|
-
s.license = '0BSD'
|
12
|
-
|
13
|
-
s.summary = %q{Ruby wrapper for ICQ Bot API.}
|
14
|
-
s.description = %q{This gem is a simple and minimalistic library for creating ICQ bots.}
|
15
|
-
s.homepage = "https://github.com/sheyber/icqbot"
|
16
|
-
s.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
17
|
-
|
18
|
-
s.metadata["homepage_uri"] = s.homepage
|
19
|
-
|
20
|
-
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
-
s.bindir = 'exe'
|
22
|
-
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
-
s.require_paths = ['lib']
|
24
|
-
|
25
|
-
s.add_dependency 'requests', '~> 1.0', '>= 1.0.2'
|
1
|
+
require_relative './lib/icqbot.rb'
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "icqbot"
|
8
|
+
s.version = ICQ::VERSION
|
9
|
+
s.authors = ["sheyber"]
|
10
|
+
s.email = ["ukt1@ro.ru"]
|
11
|
+
s.license = '0BSD'
|
12
|
+
|
13
|
+
s.summary = %q{Ruby wrapper for ICQ Bot API.}
|
14
|
+
s.description = %q{This gem is a simple and minimalistic library for creating ICQ bots.}
|
15
|
+
s.homepage = "https://github.com/sheyber/icqbot"
|
16
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
17
|
+
|
18
|
+
s.metadata["homepage_uri"] = s.homepage
|
19
|
+
|
20
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
s.bindir = 'exe'
|
22
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
s.require_paths = ['lib']
|
24
|
+
|
25
|
+
s.add_dependency 'requests', '~> 1.0', '>= 1.0.2'
|
26
26
|
end
|
data/lib/icqbot.rb
CHANGED
data/lib/icqbot/bot.rb
CHANGED
@@ -9,6 +9,11 @@ require_relative './functional/delete_msg.rb'
|
|
9
9
|
require_relative './functional/chats/get_info.rb'
|
10
10
|
require_relative './functional/chats/get_admins.rb'
|
11
11
|
require_relative './functional/chats/get_members.rb'
|
12
|
+
require_relative './functional/chats/administration/set_title.rb'
|
13
|
+
require_relative './functional/chats/administration/set_about.rb'
|
14
|
+
require_relative './functional/chats/administration/set_rules.rb'
|
15
|
+
require_relative './functional/chats/administration/pin_unpin_msg.rb'
|
16
|
+
require_relative './functional/chats/administration/block_unblock_user.rb'
|
12
17
|
|
13
18
|
module ICQ
|
14
19
|
|
@@ -20,6 +25,8 @@ module ICQ
|
|
20
25
|
@pool_time = pool_time
|
21
26
|
@last_event_id = 0
|
22
27
|
@loop = true
|
28
|
+
@handlers = {}
|
29
|
+
@callback_handlers = {}
|
23
30
|
yield self if block_given?
|
24
31
|
end
|
25
32
|
|
@@ -38,18 +45,24 @@ module ICQ
|
|
38
45
|
if events and events['events'] and events['events'] != []
|
39
46
|
last_event = events['events'].last
|
40
47
|
@last_event_id = last_event['eventId']
|
41
|
-
|
48
|
+
last_event = ICQ::Event.new last_event
|
49
|
+
if @handlers.has_key? last_event.text
|
50
|
+
@handlers[last_event.text].call last_event
|
51
|
+
elsif last_event.type == ICQ::TypeEvent::CALLBACK and @callback_handlers.has_key? last_event.data
|
52
|
+
@callback_handlers[last_event.text].call last_event
|
53
|
+
else
|
54
|
+
yield last_event
|
55
|
+
end
|
42
56
|
end
|
43
57
|
end
|
44
58
|
end
|
45
59
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
60
|
+
def add_handler text, handler
|
61
|
+
@handlers[text] = handler
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_callback_handler data, handler
|
65
|
+
@callback_handlers[data] = handler
|
53
66
|
end
|
54
67
|
|
55
68
|
private
|
data/lib/icqbot/event.rb
CHANGED
@@ -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,27 @@
|
|
1
|
+
require_relative '../../../bot.rb'
|
2
|
+
|
3
|
+
module ICQ
|
4
|
+
|
5
|
+
class Bot
|
6
|
+
def block_user user_id, chat_id, del_last_msg=false
|
7
|
+
params = base_req_for_block_unblock_user user_id, chat_id, del_last_msg
|
8
|
+
JSON::load Requests.get(
|
9
|
+
URLS_API::BLOCK_USER, params: params).body
|
10
|
+
end
|
11
|
+
|
12
|
+
def unblock_user user_id, chat_id
|
13
|
+
params = base_req_for_block_unblock_user user_id, chat_id
|
14
|
+
JSON::load Requests.get(
|
15
|
+
URLS_API::UNBLOCK_USER, params: params).body
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def base_req_for_block_unblock_user user_id, chat_id, del_last_msg=nil
|
20
|
+
params = base_req chat_id
|
21
|
+
params['userId'] = user_id
|
22
|
+
params['delLastMessages'] = del_last_msg if del_last_msg
|
23
|
+
return params
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
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
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../../../bot.rb'
|
2
|
+
|
3
|
+
module ICQ
|
4
|
+
|
5
|
+
class Bot
|
6
|
+
def set_title chat_id, title
|
7
|
+
params = base_req chat_id
|
8
|
+
params['title'] = title
|
9
|
+
JSON::load Requests.get(
|
10
|
+
URLS_API::SET_TITLE, params: params).body
|
11
|
+
end
|
12
|
+
|
13
|
+
def title= o
|
14
|
+
set_title *o
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/icqbot/message.rb
CHANGED
data/lib/icqbot/urls_api.rb
CHANGED
@@ -8,4 +8,11 @@ module URLS_API
|
|
8
8
|
GET_ADMINS = 'https://api.icq.net/bot/v1/chats/getAdmins'
|
9
9
|
GET_MEMBRS = 'https://api.icq.net/bot/v1/chats/getMembers'
|
10
10
|
GET_BLOCKED_USERS = 'https://api.icq.net/bot/v1/chats/getBlockedUsers'
|
11
|
+
SET_TITLE = 'https://api.icq.net/bot/v1/chats/setTitle'
|
12
|
+
SET_ABOUT = 'https://api.icq.net/bot/v1/chats/setAbout'
|
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'
|
16
|
+
BLOCK_USER = 'https://api.icq.net/bot/v1/chats/blockUser'
|
17
|
+
UNBLOCK_USER = 'https://api.icq.net/bot/v1/chats/unblockUser'
|
11
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icqbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sheyber
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: requests
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- Gemfile
|
42
42
|
- README.md
|
43
43
|
- bin/5time_echo_and_end.rb
|
44
|
+
- bin/bot_with_handlers.rb
|
44
45
|
- bin/echo_bot.rb
|
45
46
|
- bin/send_text_with_button.rb
|
46
47
|
- doc/bot.md
|
@@ -48,11 +49,15 @@ files:
|
|
48
49
|
- doc/event.md
|
49
50
|
- doc/message.md
|
50
51
|
- doc/overview.md
|
51
|
-
- doc/user.md
|
52
52
|
- icqbot.gemspec
|
53
53
|
- lib/icqbot.rb
|
54
54
|
- lib/icqbot/bot.rb
|
55
55
|
- lib/icqbot/event.rb
|
56
|
+
- lib/icqbot/functional/chats/administration/block_unblock_user.rb
|
57
|
+
- lib/icqbot/functional/chats/administration/pin_unpin_msg.rb
|
58
|
+
- lib/icqbot/functional/chats/administration/set_about.rb
|
59
|
+
- lib/icqbot/functional/chats/administration/set_rules.rb
|
60
|
+
- lib/icqbot/functional/chats/administration/set_title.rb
|
56
61
|
- lib/icqbot/functional/chats/get_admins.rb
|
57
62
|
- lib/icqbot/functional/chats/get_blocked_users.rb
|
58
63
|
- lib/icqbot/functional/chats/get_info.rb
|