botkit-telegram 0.0.1 → 0.0.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
- SHA1:
3
- metadata.gz: 89d50e1cb055acbbb6e213cd67a5e1c909f31d96
4
- data.tar.gz: 02e08fe2a232c63a36930b5dab168923601d4e94
2
+ SHA256:
3
+ metadata.gz: 7f008344cec53e7d8a7e29e13bb6e6ace856bc777aa74e3f5746f1c901116a18
4
+ data.tar.gz: cffdf6f86d1132190122327516f4245fed0c4d80441fb37ca18d2a9ce36e1927
5
5
  SHA512:
6
- metadata.gz: ed27de5f150ec0371955c0d23cfe870e6abe860ed35745acfd2dcb29d68ddd7057c6e853f91a473967437f5f7cf0bb3255e082e0c70ae31608a235b95496a4c3
7
- data.tar.gz: 49f5c6168f2b9c34c940ae6c5b1aed774b21483207b022b4b9e0400fb6c395895df137dffb426e47b07f0d9b53d6fa845950d2fa2153b6c4fc69bd941bee4653
6
+ metadata.gz: 4d67799509d7ebb0a5e134b1f2869fa36788c67449884013876fc63f6d787e775a124c347e9e2c9c89e8c82d581da50ddbb8e6430431340e974dd88f95f45a23
7
+ data.tar.gz: 5a60b51fc0e227d748b26824bedbb5c0675e6a1f516bf5557d2d154249a9d210882b8d7640f1afbd88782d3cbfb5ee16088c723595974bd8c2d35d450170431d
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [fnando]
data/.rubocop.yml CHANGED
@@ -1,116 +1,10 @@
1
- AllCops:
2
- TargetRubyVersion: 2.4
3
-
4
- Style/Alias:
5
- EnforcedStyle: prefer_alias_method
6
-
7
- Style/FrozenStringLiteralComment:
8
- EnforcedStyle: always
9
-
10
- Style/ClassCheck:
11
- EnforcedStyle: kind_of?
12
-
13
- Metrics/LineLength:
14
- Max: 80
15
-
16
- Style/BlockDelimiters:
17
- Enabled: false
18
-
19
- Style/RegexpLiteral:
20
- Enabled: false
21
-
22
- Metrics/AbcSize:
23
- Enabled: false
24
-
25
- Style/PerlBackrefs:
26
- Enabled: false
27
-
28
- ClassLength:
29
- Enabled: false
30
-
31
- CyclomaticComplexity:
32
- Enabled: false
33
-
34
- Documentation:
35
- Enabled: false
36
-
37
- Encoding:
38
- Enabled: false
39
-
40
- FileName:
41
- Enabled: false
42
-
43
- IfUnlessModifier:
44
- Enabled: false
45
-
46
- MethodLength:
47
- Enabled: false
48
-
49
- ModuleFunction:
50
- Enabled: false
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
51
4
 
52
- OneLineConditional:
53
- Enabled: false
54
-
55
- ParameterLists:
56
- Enabled: false
57
-
58
- Proc:
59
- Enabled: false
60
-
61
- SingleLineBlockParams:
62
- Enabled: false
63
-
64
- VariableInterpolation:
65
- Enabled: false
66
-
67
- Style/TrailingCommaInLiteral:
68
- Enabled: false
69
-
70
- WhileUntilModifier:
71
- Enabled: false
72
-
73
- PredicateName:
74
- NamePrefixBlacklist:
75
- - is_
76
-
77
- StringLiterals:
78
- EnforcedStyle: double_quotes
79
-
80
- DotPosition:
81
- EnforcedStyle: leading
82
-
83
- SpaceBeforeBlockBraces:
84
- EnforcedStyle: space
85
-
86
- SpaceInsideBlockBraces:
87
- EnforcedStyle: no_space
88
-
89
- DoubleNegation:
90
- Enabled: false
91
-
92
- SpaceInsideBlockBraces:
93
- SpaceBeforeBlockParameters: false
94
-
95
- SpaceInsideHashLiteralBraces:
96
- Enabled: false
97
-
98
- PercentLiteralDelimiters:
99
- PreferredDelimiters:
100
- '%': '{}'
101
- '%i': '{}'
102
- '%q': '{}'
103
- '%Q': '{}'
104
- '%r': '{}'
105
- '%s': '{}'
106
- '%w': '{}'
107
- '%W': '{}'
108
- '%x': '{}'
5
+ AllCops:
6
+ TargetRubyVersion: 3.0
109
7
 
110
- Style/CollectionMethods:
111
- PreferredMethods:
112
- collect: 'map'
113
- collect!: 'map!'
114
- inject: 'reduce'
115
- detect: 'find'
116
- find_all: 'select'
8
+ Naming/FileName:
9
+ Exclude:
10
+ - lib/botkit-telegram.rb
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
data/Gemfile.lock CHANGED
@@ -1,28 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- botkit-telegram (0.0.1)
4
+ botkit-telegram (0.0.2)
5
5
  botkit
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- aitch (1.0.2)
11
- nokogiri (>= 1.6.0)
12
- botkit (0.0.1)
10
+ aitch (1.2.1)
11
+ nokogiri
12
+ botkit (0.0.5)
13
13
  aitch
14
14
  signal
15
- mini_portile2 (2.3.0)
16
- minitest (5.10.3)
17
- minitest-utils (0.4.0)
15
+ mini_portile2 (2.8.1)
16
+ minitest (5.16.3)
17
+ minitest-utils (0.4.8)
18
18
  minitest
19
- nokogiri (1.8.1)
20
- mini_portile2 (~> 2.3.0)
21
- rake (12.2.1)
22
- signal (1.1.0)
19
+ nokogiri (1.13.10)
20
+ mini_portile2 (~> 2.8.0)
21
+ racc (~> 1.4)
22
+ racc (1.6.2)
23
+ rake (13.0.6)
24
+ signal (1.3.1)
25
+ voltage
26
+ voltage (0.1.0)
23
27
 
24
28
  PLATFORMS
25
- ruby
29
+ arm64-darwin-22
26
30
 
27
31
  DEPENDENCIES
28
32
  botkit-telegram!
@@ -31,4 +35,4 @@ DEPENDENCIES
31
35
  rake
32
36
 
33
37
  BUNDLED WITH
34
- 1.16.0
38
+ 2.4.1
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
1
  # Botkit::Telegram
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/botkit/telegram`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Create a chatbot for [Telegram](https://telegram.org).
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'botkit-telegram'
10
+ gem "botkit-telegram"
13
11
  ```
14
12
 
15
13
  And then execute:
@@ -22,22 +20,35 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ See a bot example at
24
+ [examples/bot.rb](https://github.com/fnando/botkit-telegram/blob/main/examples/bot.rb).
26
25
 
27
26
  ## Development
28
27
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
29
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
30
+ prompt that will allow you to experiment.
30
31
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To
33
+ release a new version, update the version number in `version.rb`, and then run
34
+ `bundle exec rake release`, which will create a git tag for the version, push
35
+ git commits and tags, and push the `.gem` file to
36
+ [rubygems.org](https://rubygems.org).
32
37
 
33
38
  ## Contributing
34
39
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/botkit-telegram. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
40
+ Bug reports and pull requests are welcome on GitHub at
41
+ <https://github.com/fnando/botkit-telegram>. This project is intended to be a
42
+ safe, welcoming space for collaboration, and contributors are expected to adhere
43
+ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
44
 
37
45
  ## License
38
46
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
47
+ The gem is available as open source under the terms of the
48
+ [MIT License](https://opensource.org/licenses/MIT).
40
49
 
41
50
  ## Code of Conduct
42
51
 
43
- Everyone interacting in the Botkit::Telegram project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/botkit-telegram/blob/master/CODE_OF_CONDUCT.md).
52
+ Everyone interacting in the Botkit::Telegram project’s codebases, issue
53
+ trackers, chat rooms and mailing lists is expected to follow the
54
+ [code of conduct](https://github.com/fnando/botkit-telegram/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
5
+ require "rubocop/rake_task"
3
6
 
4
7
  Rake::TestTask.new(:test) do |t|
5
8
  t.libs << "test"
@@ -7,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
7
10
  t.test_files = FileList["test/**/*_test.rb"]
8
11
  end
9
12
 
10
- task :default => :test
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "botkit/telegram"
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 ADDED
@@ -0,0 +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
@@ -6,7 +6,9 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "botkit-telegram"
7
7
  spec.version = Botkit::Telegram::VERSION
8
8
  spec.authors = ["Nando Vieira"]
9
- spec.email = ["fnando.vieira@gmail.com"]
9
+ spec.email = ["me@fnando.com"]
10
+ spec.required_ruby_version = ">= 3.0.0"
11
+ spec.metadata = {"rubygems_mfa_required" => "true"}
10
12
 
11
13
  spec.summary = "A botkit for Telegram"
12
14
  spec.description = spec.summary
@@ -23,6 +25,6 @@ Gem::Specification.new do |spec|
23
25
  spec.add_dependency "botkit"
24
26
 
25
27
  spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "rake"
27
28
  spec.add_development_dependency "minitest-utils"
29
+ spec.add_development_dependency "rake"
28
30
  end
data/examples/bot.rb ADDED
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH << File.expand_path("#{__dir__}/../lib")
4
+ require "botkit-telegram"
5
+
6
+ class MyBot
7
+ attr_reader :chatbot
8
+
9
+ def initialize(api_token:)
10
+ @chatbot = Botkit::Telegram.new(api_token: api_token)
11
+ configure_bot
12
+ end
13
+
14
+ def configure_bot
15
+ chatbot.command(:time, &method(:on_time))
16
+ chatbot.command(:gem, &method(:on_gem))
17
+ chatbot.message(&method(:on_message))
18
+ chatbot.exception(&method(:on_exception))
19
+ end
20
+
21
+ def call
22
+ Botkit.run(chatbot)
23
+ end
24
+
25
+ def on_time(message)
26
+ text = "Now is <b>#{Time.now}</b>"
27
+ message =
28
+ Botkit::Telegram::Message.new(text: text, channel_id: message.channel_id)
29
+ chatbot.send_message(message, parse_mode: "HTML")
30
+ end
31
+
32
+ def on_gem(message)
33
+ GemCommand.new(message).call
34
+ end
35
+
36
+ def on_exception(error)
37
+ $stderr << "#{error.class}: #{error.message}\n"
38
+ $stderr << error.backtrace.join("\n")
39
+ $stderr << "\n\n"
40
+ end
41
+
42
+ def on_message(message)
43
+ reply = Botkit::Telegram::Message.new(
44
+ text: "Sorry, but I don't know what you mean.",
45
+ channel_id: message.channel_id
46
+ )
47
+ chatbot.reply_message(message, reply)
48
+ end
49
+
50
+ class GemCommand
51
+ attr_reader :message
52
+
53
+ def initialize(message)
54
+ @message = message
55
+ end
56
+
57
+ def call
58
+ response = Aitch.get do
59
+ url "https://rubygems.org/api/v1/gems/#{message.text}.json"
60
+ end
61
+
62
+ case response.code
63
+ when 200
64
+ send_gem_info(response)
65
+ when 404
66
+ send_gem_not_found
67
+ else
68
+ send_error
69
+ end
70
+ end
71
+
72
+ def send_gem_info(response)
73
+ gem_info = response.data
74
+ name = gem_info["name"]
75
+ description = gem_info["description"]
76
+ project_uri = gem_info["project_uri"]
77
+
78
+ text = [
79
+ "<b>Info about #{name}</b>",
80
+ "#{description}\n",
81
+ project_uri
82
+ ].join("\n")
83
+
84
+ chatbot.send_message(
85
+ Botkit::Telegram::Message.new(text: text),
86
+ parse_mode: "HTML"
87
+ )
88
+ end
89
+
90
+ def send_gem_not_found
91
+ chatbot.send_message(
92
+ Botkit::Telegram::Message.new(text: "Sorry! This gem doesn't exist.")
93
+ )
94
+ end
95
+
96
+ def send_error
97
+ chatbot.send_message(
98
+ Botkit::Telegram::Message.new(text: "Sorry! Something went wrong.")
99
+ )
100
+ end
101
+ end
102
+ end
103
+
104
+ MyBot.new(api_token: ENV.fetch("TELEGRAM_API_TOKEN")).call
@@ -7,6 +7,7 @@ module Botkit
7
7
  attr_accessor :offset
8
8
 
9
9
  def initialize(api_token:)
10
+ super()
10
11
  @api_token = api_token
11
12
  @booted_at = Time.now.utc.to_i
12
13
  @offset = 0
@@ -36,7 +37,8 @@ module Botkit
36
37
  def prepare_message(message)
37
38
  params = parse_message(message.dig("message", "text"))
38
39
  params = params.merge(raw: message,
39
- channel_id: message.dig("message", "chat", "id"))
40
+ channel_id: message.dig("message", "chat", "id"),
41
+ id: message.dig("message", "message_id"))
40
42
  Message.new(**params)
41
43
  end
42
44
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Botkit
4
4
  module Telegram
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
  end
7
7
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "botkit/telegram"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: botkit-telegram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-11 00:00:00.000000000 Z
11
+ date: 2022-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: botkit
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: minitest-utils
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest-utils
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -68,21 +68,25 @@ dependencies:
68
68
  version: '0'
69
69
  description: A botkit for Telegram
70
70
  email:
71
- - fnando.vieira@gmail.com
71
+ - me@fnando.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/FUNDING.yml"
76
77
  - ".gitignore"
77
78
  - ".rubocop.yml"
78
- - ".travis.yml"
79
79
  - CODE_OF_CONDUCT.md
80
80
  - Gemfile
81
81
  - Gemfile.lock
82
82
  - LICENSE.txt
83
83
  - README.md
84
84
  - Rakefile
85
+ - bin/console
86
+ - bin/setup
85
87
  - botkit-telegram.gemspec
88
+ - examples/bot.rb
89
+ - lib/botkit-telegram.rb
86
90
  - lib/botkit/telegram.rb
87
91
  - lib/botkit/telegram/bot.rb
88
92
  - lib/botkit/telegram/message.rb
@@ -90,8 +94,9 @@ files:
90
94
  homepage: https://rubygems.org/gems/botkit-telegram
91
95
  licenses:
92
96
  - MIT
93
- metadata: {}
94
- post_install_message:
97
+ metadata:
98
+ rubygems_mfa_required: 'true'
99
+ post_install_message:
95
100
  rdoc_options: []
96
101
  require_paths:
97
102
  - lib
@@ -99,16 +104,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
104
  requirements:
100
105
  - - ">="
101
106
  - !ruby/object:Gem::Version
102
- version: '0'
107
+ version: 3.0.0
103
108
  required_rubygems_version: !ruby/object:Gem::Requirement
104
109
  requirements:
105
110
  - - ">="
106
111
  - !ruby/object:Gem::Version
107
112
  version: '0'
108
113
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.6.13
111
- signing_key:
114
+ rubygems_version: 3.4.1
115
+ signing_key:
112
116
  specification_version: 4
113
117
  summary: A botkit for Telegram
114
118
  test_files: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.2
5
- before_install: gem install bundler -v 1.16.0