tgbot 0.2.7 → 0.4.6

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: d9a76dc51733e8bf5980a4cbc12aa9f86159a74066660c6b4b385c1dda3424d6
4
- data.tar.gz: 6022394e75913433de65dc0aa580ed4c39851a70059995bdffcf42f38709a743
3
+ metadata.gz: 294a4c0bb7a9ad39e5774c0ccfa25823fc5ca32e9a42a02da3ccf78caf5d0f77
4
+ data.tar.gz: 97b42d15245ab40642b1338e71bab4b13a4f38dfd52b83246b01e69ad79c2c1c
5
5
  SHA512:
6
- metadata.gz: 105f22096320ed5634ef41fe10571ff51b5e25cd9592b537e044854c853bc87d72f86ef7c2d053fbab33d75815e5dda7e3227008ab5c72cfda90ca0dbc064d05
7
- data.tar.gz: 4dcc05edefdc30a79187a6684c473dd3d10b80b8eac5e894568dd82055c19a710c8717919c48141de076ff39822e7cbeddcf5314e7bf4f3fb8eca87fef19de56
6
+ metadata.gz: 2094281be883d4b9a65d9b5d141b817cbda3ac4a435384e654951cfc0ab18ae7040c5a6a7dfbd40557d27ec6efa9f4b45b450d1018d7a694cb8a4c7d851d670f
7
+ data.tar.gz: 5ac90115b0b93baccb11c3c2485ec79608683e18540feb0d4eeb04b3ee5ab999d2ee013c6dc3dda2da96f479e3d1b8f74678da181e329279d599b3611c46da7e
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in tgbot.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tgbot.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 hyrious
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2019-2023 hyrious
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,126 +1,126 @@
1
- # Tgbot
2
-
3
- [![Gem Version](https://badge.fury.io/rb/tgbot.svg)](https://badge.fury.io/rb/tgbot)
4
- ![Bot API Version](https://img.shields.io/badge/Bot%20API-4.7-blue.svg?style=flat-square)
5
- ![](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=flat-square)
6
-
7
- A tiny but easy-to-use wrapper of [Telegram Bot API](https://core.telegram.org/bots/api).
8
-
9
- ## Install
10
-
11
- gem install tgbot
12
-
13
- ## Usage
14
-
15
- ```ruby
16
- Tgbot.run TOKEN, proxy: 'http://127.0.0.1:1080' do
17
- @name = get_me&.result&.first_name
18
- on 'start' do
19
- reply "#@name, at your service."
20
- end
21
- end
22
- # or
23
- bot = Tgbot.new TOKEN, proxy: 'http://127.0.0.1:1080'
24
- bot.on('start'){ reply "#{get_me&.result&.first_name}, at your service." }
25
- bot.run # will block current thread
26
- ```
27
-
28
- #### `Tgbot.run token, **options do (block) end`
29
-
30
- Start a long polling bot.
31
-
32
- | argument | type | notes | example |
33
- |----------|------|-------|---------|
34
- | token | `String` | [ask BotFather for one](https://core.telegram.org/bots#generating-an-authorization-token) | `'123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11'` |
35
-
36
- | option | type | notes | example |
37
- |--------|------|-------|---------|
38
- | proxy | `String` | http only | `'127.0.0.1:1080'` |
39
-
40
- and in that `(block)`:
41
-
42
- #### method_missing
43
-
44
- Just call the native bot api. e.g. `getMe()` `send_message(chat_id: 123, text: 'hello')`.
45
-
46
- Returns an OpenStruct of the replied object. Basically `struct{ok=true,result=...}`.
47
-
48
- #### `self.debug = true | false (default)`
49
-
50
- Show debug info (every message, matched command).
51
-
52
- #### `start do (do sth when it is connected) end`
53
-
54
- ```ruby
55
- start do
56
- puts "\e[33m#{get_me&.result&.first_name}\e[32m, at your service."
57
- end
58
- ```
59
-
60
- #### `finish do (do sth when Ctrl+C) end`
61
-
62
- ```ruby
63
- finish do
64
- puts "おやすみなさい"
65
- end
66
- ```
67
-
68
- #### `on pattern=nil, **options do |match_data, update, task| (block) end`
69
-
70
- Match pattern and do something.
71
-
72
- | argument | type | notes | example |
73
- |----------|------|-------|---------|
74
- | pattern | `nil` | match all (including inline query etc.) | `on do ... end` |
75
- | - | `String` \| `Regexp` | match all text<sup>1</sup> | `/^r(\d*)d(\d*)(?:\+(\d*))?/` |
76
-
77
- <sup>1</sup>: for convenience, the bot's `@username` is trimmed for easilier matching.
78
-
79
- e.g. `"hey bot, /r3d6@mybot+1 lol" => #<MatchData "/r3d6+1" 1:"3" 2:"6" 3:"1">`.
80
-
81
- | option | type | notes | example |
82
- |--------|------|-------|---------|
83
- | name | `String` | just give it a name | `'roll!'` |
84
- | before_all | `true` | set to run before other `on`s matching the same message | `true` |
85
- | after_all | `true` | set to run after other `on`s matching the same message<sup>2</sup><br>you can't set both `before_all` and `after_all` on one command | `true` |
86
-
87
- <sup>2</sup>: order is `* -> before2 -> before1 -> other -> after1 -> after2 -> *`.
88
-
89
- and in that `(block)`:
90
-
91
- #### `debug message`
92
-
93
- Puts that message to STDERR when it is in debug mode.
94
-
95
- #### `reply *things, **options`
96
-
97
- Reply to the matched message.
98
-
99
- | argument | type | notes | example |
100
- |----------|------|-------|---------|
101
- | thing | `String` \| can `.to_s` | will use `parse_mode: Markdown` | `'hello world'` |
102
- | - | `IO` | will use `sendPhoto` if it is a photo, etc. | `File.new("a.png")` |
103
-
104
- | option | type | notes | example |
105
- |--------|------|-------|---------|
106
- | media | `false` | set to `false` to force `sendDocument` | `'127.0.0.1:1080'` |
107
- | style | `:none` \| `:at` \| `nil` (default) | reply style<sup>3</sup> | `:at` |
108
- | parse_mode, etc. | depends | see [sendMessage](https://core.telegram.org/bots/api#sendmessage) | - |
109
-
110
- reply style<sup>3</sup>:
111
-
112
- - `:none` : don't add reply info, so the sender won't receive a prompting.
113
- - `:at`: use `[inline mention of a user](tg://user?id=123456789)` in replied message.
114
- - `nil` (default): include `reply_to_message_id` in replied message object.
115
-
116
- #### `interrupt!` `done!`
117
-
118
- Stop processing this message (if there be further blocks matching it). see `before_all` `after_all`.
119
-
120
- #### `retry! n=1`
121
-
122
- Enqueue this message again for at most `n` times.
123
-
124
- ## Contribute
125
-
126
- PRs/issues are welcome.
1
+ # Tgbot
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/tgbot.svg)](https://badge.fury.io/rb/tgbot)
4
+ ![Bot API Version](https://img.shields.io/badge/Bot%20API-6.6-blue.svg?style=flat-square)
5
+ ![](https://img.shields.io/badge/License-MIT-lightblue.svg?style=flat-square)
6
+
7
+ A tiny but easy-to-use wrapper of [Telegram Bot API](https://core.telegram.org/bots/api).
8
+
9
+ ## Install
10
+
11
+ gem install tgbot
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ Tgbot.run TOKEN, proxy: 'http://127.0.0.1:1080' do
17
+ @name = get_me&.result&.first_name
18
+ on 'start' do
19
+ reply "#@name, at your service."
20
+ end
21
+ end
22
+ # or
23
+ bot = Tgbot.new TOKEN, proxy: 'http://127.0.0.1:1080'
24
+ bot.on('start'){ reply "#{get_me&.result&.first_name}, at your service." }
25
+ bot.run # will block current thread
26
+ ```
27
+
28
+ #### `Tgbot.run token, **options do (block) end`
29
+
30
+ Start a long polling bot.
31
+
32
+ | argument | type | notes | example |
33
+ |----------|------|-------|---------|
34
+ | token | `String` | [ask BotFather for one](https://core.telegram.org/bots#generating-an-authorization-token) | `'123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11'` |
35
+
36
+ | option | type | notes | example |
37
+ |--------|------|-------|---------|
38
+ | proxy | `String` | http only | `'127.0.0.1:1080'` |
39
+
40
+ and in that `(block)`:
41
+
42
+ #### method_missing
43
+
44
+ Just call the native bot api. e.g. `getMe()` `send_message(chat_id: 123, text: 'hello')`.
45
+
46
+ Returns an OpenStruct of the replied object. Basically `struct{ok=true,result=...}`.
47
+
48
+ #### `self.debug = true | false (default)`
49
+
50
+ Show debug info (every message, matched command).
51
+
52
+ #### `start do (do sth when it is connected) end`
53
+
54
+ ```ruby
55
+ start do
56
+ puts "\e[33m#{get_me&.result&.first_name}\e[32m, at your service."
57
+ end
58
+ ```
59
+
60
+ #### `finish do (do sth when Ctrl+C) end`
61
+
62
+ ```ruby
63
+ finish do
64
+ puts "おやすみなさい"
65
+ end
66
+ ```
67
+
68
+ #### `on pattern=nil, **options do |match_data, update, task| (block) end`
69
+
70
+ Match pattern and do something.
71
+
72
+ | argument | type | notes | example |
73
+ |----------|------|-------|---------|
74
+ | pattern | `nil` | match all (including inline query etc.) | `on do ... end` |
75
+ | - | `String` \| `Regexp` | match all text<sup>1</sup> | `/^r(\d*)d(\d*)(?:\+(\d*))?/` |
76
+
77
+ <sup>1</sup>: for convenience, the bot's `@username` is trimmed for easilier matching.
78
+
79
+ e.g. `"hey bot, /r3d6@mybot+1 lol" => #<MatchData "/r3d6+1" 1:"3" 2:"6" 3:"1">`.
80
+
81
+ | option | type | notes | example |
82
+ |--------|------|-------|---------|
83
+ | name | `String` | just give it a name | `'roll!'` |
84
+ | before_all | `true` | set to run before other `on`s matching the same message | `true` |
85
+ | after_all | `true` | set to run after other `on`s matching the same message<sup>2</sup><br>you can't set both `before_all` and `after_all` on one command | `true` |
86
+
87
+ <sup>2</sup>: order is `* -> before2 -> before1 -> other -> after1 -> after2 -> *`.
88
+
89
+ and in that `(block)`:
90
+
91
+ #### `debug message`
92
+
93
+ Puts that message to STDERR when it is in debug mode.
94
+
95
+ #### `reply *things, **options`
96
+
97
+ Reply to the matched message.
98
+
99
+ | argument | type | notes | example |
100
+ |----------|------|-------|---------|
101
+ | thing | `String` \| can `.to_s` | will use `parse_mode: Markdown` | `'hello world'` |
102
+ | - | `IO` | will use `sendPhoto` if it is a photo, etc. | `File.new("a.png")` |
103
+
104
+ | option | type | notes | example |
105
+ |--------|------|-------|---------|
106
+ | media | `false` | set to `false` to force `sendDocument` | `'127.0.0.1:1080'` |
107
+ | style | `:none` \| `:at` \| `nil` (default) | reply style<sup>3</sup> | `:at` |
108
+ | parse_mode, etc. | depends | see [sendMessage](https://core.telegram.org/bots/api#sendmessage) | - |
109
+
110
+ reply style<sup>3</sup>:
111
+
112
+ - `:none` : don't add reply info, so the sender won't receive a prompting.
113
+ - `:at`: use `[inline mention of a user](tg://user?id=123456789)` in replied message.
114
+ - `nil` (default): include `reply_to_message_id` in replied message object.
115
+
116
+ #### `interrupt!` `done!`
117
+
118
+ Stop processing this message (if there be further blocks matching it). see `before_all` `after_all`.
119
+
120
+ #### `retry! n=1`
121
+
122
+ Enqueue this message again for at most `n` times.
123
+
124
+ ## Contribute
125
+
126
+ PRs/issues are welcome.
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "tgbot"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tgbot"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here