tgbot 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d47acdf7d9efc0bbc1046ec8da783f7275bf2f47
4
- data.tar.gz: f5307a153d8b7d040ac8d89f9691ce0bb5d8bba4
3
+ metadata.gz: f1e994fa95298f4a1c13b770fd4d6f9543ef5711
4
+ data.tar.gz: 06facef85842d55e084dc662e631e99814119ac1
5
5
  SHA512:
6
- metadata.gz: 8c89444e9d5716ce16dbd3f4789558e060fb8653d1550d18489430f713341ad43010cec7a3f5d8d050c9e1e72e4640e107a5718ffade5d8541ff4c25457c066c
7
- data.tar.gz: 3f25c02feffb114ef4f20e6efa2608fdebe23706df4a0903556679b433194e14e1eff9ff15e7aa600041e033540d67c40c0764fc5cb2e5268e8af75d19bf7eea
6
+ metadata.gz: f84b17b66ed508c4f18f2df27cdad3e3e4d8db76920feef9173157c41879f5ddc1bc401d5adc0b6456d0238c88f58b6d999337da2bd7b0e8175bd5298aa63922
7
+ data.tar.gz: 82cc40adf4e468e25135e2e9f31ae4589f0a94a19a3151ab39524fe187083c73071a9970da61b0c57245e35514f3e0416be15e5ac0ce040bef5e5b099f3a47a6
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/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # `Tgbot`
1
+ # Tgbot
2
2
 
3
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-3.2-blue.svg?style=flat-square)
5
+ ![](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=flat-square)
4
6
 
5
7
  A tiny but easy-to-use wrapper of [Telegram Bot API](https://core.telegram.org/bots/api).
6
8
 
@@ -10,11 +12,14 @@ A tiny but easy-to-use wrapper of [Telegram Bot API](https://core.telegram.org/b
10
12
 
11
13
  ## Usage
12
14
 
13
- See [example.rb](example.rb).
15
+ See [example.rb](example.rb) or [usage.md](usage.md).
14
16
 
15
17
  ## Todo
16
18
 
17
19
  - improve DSL
20
+ - add sqlite, then
21
+ + add session
22
+ + add privilege
18
23
 
19
24
  ## Contribute
20
25
 
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
data/example.rb CHANGED
@@ -68,7 +68,7 @@ Tgbot.run TOKEN, proxy: 'https://127.0.0.1:1080' do |bot|
68
68
 
69
69
  bot.before do |update|
70
70
  log ">> Processing ##{update.id}"
71
- log "@#{update.message&.from.username}: #{update.text}", 3
71
+ log "@#{update.message&.from&.first_name}: #{update.text}", 3
72
72
  end
73
73
  bot.after do |update|
74
74
  if update.done?
@@ -101,7 +101,7 @@ Tgbot.run TOKEN, proxy: 'https://127.0.0.1:1080' do |bot|
101
101
  send_message Array.new(text&.match(/\d+/)&.to_s.to_i || 1){ ['🌞', '🌚'].sample }.join
102
102
  end
103
103
  bot.get 'roll' do
104
- send_message rand(text&.match(/\d+/)&.to_s.to_i || 100).to_s
104
+ send_message rand(text&.match(/\d+/)&.to_s.to_i.nonzero? || 100).to_s
105
105
  end
106
106
 
107
107
  end
data/lib/tgbot/dsl.rb CHANGED
@@ -42,8 +42,7 @@ module Tgbot
42
42
  rescue Interrupt
43
43
  @procs[:finish]&.call
44
44
  rescue => e
45
- puts e
46
- puts e.backtrace
45
+ puts e.backtrace.unshift(e.to_s).join("\n")
47
46
  retry
48
47
  end
49
48
  end
@@ -54,4 +53,7 @@ module Tgbot
54
53
  def self.run(token, **opts, &blk)
55
54
  DSL.new(token, **opts).run(&blk)
56
55
  end
56
+ def self.new(token, **opts)
57
+ DSL.new(token, **opts)
58
+ end
57
59
  end
data/lib/tgbot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tgbot
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
data/tgbot.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.15"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
 
27
- spec.add_dependency 'faraday', '~> 0.12.1'
27
+ spec.add_dependency 'faraday', '~> 0.13.1'
28
28
  spec.add_dependency 'mimemagic', '~> 0.3.2'
29
29
  spec.required_ruby_version = '~> 2.4.0'
30
30
  end
data/usage.md ADDED
@@ -0,0 +1,99 @@
1
+ # Tgbot.Usage
2
+
3
+ Since the implementation is so tiny, you can just review source
4
+ code to understand usage.
5
+
6
+ ## Example and Explanation
7
+
8
+ ### Hello world
9
+
10
+ ```ruby
11
+ Tgbot.run TOKEN, proxy: 'https://127.0.0.1:1080' do |bot|
12
+ bot.get 'hello' do reply 'world' end
13
+ end
14
+ ```
15
+
16
+ This can be broken into: (with the same effect)
17
+
18
+ ```ruby
19
+ bot = Tgbot::DSL.new TOKEN, proxy: 'https://127.0.0.1:1080'
20
+ bot.get 'hello' do reply 'world' end
21
+ bot.run
22
+ ```
23
+
24
+ Here the "`bot`" is actually an instance of `Tgbot::DSL`.
25
+
26
+ ### MainLoop Model
27
+
28
+ Original Model:
29
+
30
+ ```ruby
31
+ loop { updates = get_updates; updates.each { |update| ... } }
32
+ ```
33
+
34
+ Only deal with `Update`:
35
+
36
+ ```ruby
37
+ loop_get_updates { |update| ... }
38
+ ```
39
+
40
+ Which is our `mainloop`: (see [runner.rb#L15](lib/tgbot/runner.rb#L15))
41
+
42
+ ```ruby
43
+ mainloop { |update| ... }
44
+ ```
45
+
46
+ ### DSL
47
+
48
+ ```ruby
49
+ bot.start { puts "#{bot.name}, at your service" }
50
+ bot.finish { puts "byebye." }
51
+ bot.before { |update| puts "Processing ##{update.id}." }
52
+ bot.after { |update| puts "Processed ##{update.id}." }
53
+ bot.on /\.r(\d+)?d(\d+)?/ do |matched|
54
+ p self #=> #<Update id=123456789>
55
+ t = matched[1]&.to_i || 1
56
+ n = matched[2]&.to_i || 6
57
+ reply _ = Array.new(t){rand n}.to_s rescue 'bad roll!'
58
+ end
59
+ bot.get 'cuxia', 'blind' do
60
+ name = message&.from&.first_name
61
+ next unless name
62
+ send_message "#{name} cuxia!"
63
+ if rand < 0.5
64
+ self.retry 2 #=> at most retry 2 times, default 1 if not given arg
65
+ end
66
+ done! #=> prevent any retry, mark and drop
67
+ end
68
+ bot.alias 'cuxia', 'woc', 'wodemaya'
69
+ ```
70
+
71
+ - start: will be run once when `bot.run`.
72
+ - finish: will be run once when <kbd>Ctrl</kbd><kbd>C</kbd>.
73
+ - before: do something with every `Update` before processing.
74
+ - after: do something with every `Update` after processing.
75
+ - on/get: match text and execute code in `Update` instance.
76
+
77
+
78
+
79
+ As you can see, the dsl is still weak. Wish for your idea!
80
+
81
+ ### Call Bot API
82
+
83
+ You can call bot API at any place with `bot.`.
84
+
85
+ ```ruby
86
+ p bot.get_me
87
+ bot.get 'debug' do
88
+ p bot.get_me
89
+ end
90
+ ```
91
+
92
+ Params and returns are Hash.
93
+
94
+ ### Upgrade Bot API
95
+
96
+ - Edit [types.txt](tools/types.txt) or [methods.txt](tools/methods.txt).
97
+ - `rake json`
98
+
99
+ Current version of Bot API: 3.2.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tgbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hyrious
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.12.1
47
+ version: 0.13.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.12.1
54
+ version: 0.13.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mimemagic
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +98,7 @@ files:
98
98
  - tools/methods.txt
99
99
  - tools/types.json
100
100
  - tools/types.txt
101
+ - usage.md
101
102
  homepage: https://github.com/hyrious/tgbot
102
103
  licenses:
103
104
  - MIT
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  version: '0'
119
120
  requirements: []
120
121
  rubyforge_project:
121
- rubygems_version: 2.6.11
122
+ rubygems_version: 2.6.13
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: Telegram Bot API