ruboty-telegram 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc95224de3a2e1d20ece90c7f943ec4b584a0ad0
4
+ data.tar.gz: b72deb47c705c0e99fca2435620f24f2c0991623
5
+ SHA512:
6
+ metadata.gz: b6cc92f84b8c8814cfaca84498ad4a026dc19211efd9dc7ceecc0145f22a5a807209f8239f6d881446ccb43bed92cfc5edb59543e711ec71352a53162c1c7807
7
+ data.tar.gz: 343d5e78ee39746a3d29ad5d8e9057f6de220d2fe4b0f96fc5a3f960b2441a66fe2ff5454544ef619eee7705aa1ddd268936487750e4fb0022dc9fce12697936
data/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_size = 2
7
+ indent_style = space
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.md]
12
+ indent_style = 4
13
+ trim_trailing_whitespace = false
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /.bundle/
2
+ /pkg/
3
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Yamagishi Kazutoshi <ykzts@desire.sh>
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 ADDED
@@ -0,0 +1,10 @@
1
+ # Ruboty::Telegram
2
+
3
+ Discord adapter for [Ruboty](https://github.com/r7kamura/ruboty).
4
+
5
+ ## Install
6
+
7
+ ```ruby
8
+ # Gemfile
9
+ gem 'ruboty-telegram'
10
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: tru
2
+
3
+ require 'ruboty/adapters/base'
4
+ require 'telegram/bot'
5
+
6
+ module Ruboty
7
+ module Adapters # :nodoc:
8
+ class Telegram < Base # :nodoc:
9
+ env :TELEGRAM_TOKEN, 'Account\'s token'
10
+
11
+ def run
12
+ init
13
+ listen
14
+ end
15
+
16
+ def say(message)
17
+ chat_id = message[:to]
18
+ body = message[:body]
19
+ text = message[:code] ? "```\n#{body}\n```" : body
20
+
21
+ api.send_message(chat_id: chat_id, text: text, parse_mode: 'Markdown')
22
+ end
23
+
24
+ private
25
+
26
+ def client
27
+ @client ||= ::Telegram::Bot::Client.new(ENV['TELEGRAM_TOKEN'])
28
+ end
29
+
30
+ def api
31
+ client.api
32
+ end
33
+
34
+ def init
35
+ response = api.get_me
36
+ ENV['RUBOTY_NAME'] = response['result']['username']
37
+ end
38
+
39
+ def listen
40
+ client.listen do |message|
41
+ on_message(message)
42
+ end
43
+ end
44
+
45
+ def on_message(message)
46
+ from_name = [message.from.first_name, message.from.last_name].join(' ')
47
+
48
+ robot.receive(
49
+ body: message.text,
50
+ from: message.chat.id,
51
+ from_name: from_name,
52
+ to: message.chat.id
53
+ )
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,2 @@
1
+ require 'ruboty/adapters/telegram'
2
+ require 'ruboty/telegram/version'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruboty
4
+ module Telegram
5
+ VERSION = '1.0.0'.freeze
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'ruboty/telegram/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruboty-telegram'
8
+ spec.version = Ruboty::Telegram::VERSION
9
+ spec.authors = ['Yamagishi Kazutoshi']
10
+ spec.email = ['ykzts@desire.sh']
11
+ spec.summary = 'Telegram adapter for Ruboty.'
12
+ spec.homepage = 'https://github.com/ykzts/ruboty-telegram'
13
+ spec.license = 'MIT'
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.require_paths = ['lib']
16
+ spec.add_dependency 'ruboty', '>= 1.0.4'
17
+ spec.add_dependency 'telegram-bot-ruby', '~> 0.8'
18
+ spec.add_development_dependency 'bundler', '~> 1.6'
19
+ spec.add_development_dependency 'rake'
20
+ spec.add_development_dependency 'rubocop', '~> 0.51'
21
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-telegram
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yamagishi Kazutoshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: telegram-bot-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.51'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.51'
83
+ description:
84
+ email:
85
+ - ykzts@desire.sh
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".editorconfig"
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - lib/ruboty/adapters/telegram.rb
97
+ - lib/ruboty/telegram.rb
98
+ - lib/ruboty/telegram/version.rb
99
+ - ruboty-telegram.gemspec
100
+ homepage: https://github.com/ykzts/ruboty-telegram
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.6.8
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Telegram adapter for Ruboty.
124
+ test_files: []