telegram-loggerbot-ruby 0.0.1
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 +7 -0
- data/.gitignore +51 -0
- data/LICENSE +21 -0
- data/README.md +77 -0
- data/img/preview1.jpg +0 -0
- data/img/preview2.jpg +0 -0
- data/lib/telegram/logger_bot.rb +23 -0
- data/lib/telegram/logger_bot/configuration.rb +7 -0
- data/lib/telegram/logger_bot/logger.rb +97 -0
- data/lib/telegram/logger_bot/logger_bot.rb +14 -0
- data/lib/telegram/logger_bot/version.rb +5 -0
- data/telegram-loggerbot-ruby.gemspec +22 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad51d6a6a10e4869acd082ed262523c5a9d3eea2
|
4
|
+
data.tar.gz: 501f90f90272f72541cf29a0cd3b1bdf6405744a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 130252c67c15d582657ba6b7842f690694b1163b9545ddbf81bfcfaa6f3f6848f010d6d0ce321acebd2f26cc7ab1af14812b8280da769defe44369d5275a60c0
|
7
|
+
data.tar.gz: b4c5c45ec9641d6e34f8f3a8824ced8c615f0dae7858a0a4f46fc50172621605a5d3c4e880f05b8560cfacbbcc466331d9d06c9b98de9f2392447c1792ca9973
|
data/.gitignore
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
.idea/
|
13
|
+
|
14
|
+
# Used by dotenv library to load environment variables.
|
15
|
+
# .env
|
16
|
+
|
17
|
+
## Specific to RubyMotion:
|
18
|
+
.dat*
|
19
|
+
.repl_history
|
20
|
+
build/
|
21
|
+
*.bridgesupport
|
22
|
+
build-iPhoneOS/
|
23
|
+
build-iPhoneSimulator/
|
24
|
+
|
25
|
+
## Specific to RubyMotion (use of CocoaPods):
|
26
|
+
#
|
27
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
28
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
29
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
30
|
+
#
|
31
|
+
# vendor/Pods/
|
32
|
+
|
33
|
+
## Documentation cache and generated files:
|
34
|
+
/.yardoc/
|
35
|
+
/_yardoc/
|
36
|
+
/doc/
|
37
|
+
/rdoc/
|
38
|
+
|
39
|
+
## Environment normalization:
|
40
|
+
/.bundle/
|
41
|
+
/vendor/bundle
|
42
|
+
/lib/bundler/man/
|
43
|
+
|
44
|
+
# for a library or gem, you might want to ignore these files since the code is
|
45
|
+
# intended to run in multiple environments; otherwise, check them in:
|
46
|
+
# Gemfile.lock
|
47
|
+
# .ruby-version
|
48
|
+
# .ruby-gemset
|
49
|
+
|
50
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
51
|
+
.rvmrc
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017
|
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,77 @@
|
|
1
|
+

|
2
|
+
|
3
|
+
#telegram-loggerbot-ruby
|
4
|
+
|
5
|
+
Allows to send event logs directly to the telegram chat
|
6
|
+
|
7
|
+
##Installation
|
8
|
+
|
9
|
+
Add following line to your Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'telegram-loggerbot-ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it system-wide:
|
22
|
+
|
23
|
+
```
|
24
|
+
gem install telegram-loggerbot-ruby
|
25
|
+
```
|
26
|
+
|
27
|
+
##Usage
|
28
|
+
|
29
|
+
1. Create new bot with @BotFather and get his TOKEN
|
30
|
+
2. Write something to the new bot (!!!)
|
31
|
+
3. Obtain your TELEGRAM_USER_ID from, for example, @get_id_bot
|
32
|
+
|
33
|
+
Require it to your code:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'telegram/logger_bot'
|
37
|
+
```
|
38
|
+
|
39
|
+
Configure with obtained TOKEN and TELEGRAM_USER_ID:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Telegram::LoggerBot.configure do |config|
|
43
|
+
config.token = 'TOKEN'
|
44
|
+
config.chat_id = TELEGRAM_USER_ID
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Create new logger:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
logger = Telegram::LoggerBot.new
|
52
|
+
```
|
53
|
+
|
54
|
+
You can pass events through LoggerBot to your standard logger:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
existing_logger = Logger.new(STDOUT)
|
58
|
+
logger = Telegram::LoggerBot.new(existing_logger)
|
59
|
+
```
|
60
|
+
|
61
|
+
Log you events:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
logger.debug('MyProgram') { "Text of some errors" }
|
65
|
+
logger.info('MyProgram') { "Text of some errors" }
|
66
|
+
logger.warn('MyProgram') { "Text of some errors" }
|
67
|
+
logger.error('MyProgram') { "Text of some errors" }
|
68
|
+
logger.fatal('MyProgram') { "Text of some errors" }
|
69
|
+
```
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
75
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
76
|
+
4. Push to the branch (git push origin my-new-feature)
|
77
|
+
5. Create new Pull Request
|
data/img/preview1.jpg
ADDED
Binary file
|
data/img/preview2.jpg
ADDED
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'telegram/bot'
|
3
|
+
|
4
|
+
require 'telegram/logger_bot/logger'
|
5
|
+
require 'telegram/logger_bot/logger_bot'
|
6
|
+
require 'telegram/logger_bot/version'
|
7
|
+
require 'telegram/logger_bot/configuration'
|
8
|
+
|
9
|
+
module Telegram
|
10
|
+
module LoggerBot
|
11
|
+
class << self
|
12
|
+
attr_writer :configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@configuration ||= Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
yield(configuration)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Telegram
|
2
|
+
module LoggerBot
|
3
|
+
class Logger < ::Logger
|
4
|
+
def initialize(next_logger = nil, level = nil)
|
5
|
+
@next_logger = next_logger
|
6
|
+
@level = level || (next_logger.level if next_logger) || DEBUG
|
7
|
+
@default_formatter = Formatter.new
|
8
|
+
@api = Telegram::Bot::Api.new(Telegram::LoggerBot.configuration.token)
|
9
|
+
end
|
10
|
+
|
11
|
+
def clear_markdown(str)
|
12
|
+
str.gsub(/[^a-zA-Z0-9\<\>\s\n:+-]/, '')
|
13
|
+
end
|
14
|
+
|
15
|
+
SEV_ICON = [
|
16
|
+
"\xF0\x9F\x93\x98",
|
17
|
+
"\xF0\x9F\x93\x94",
|
18
|
+
"\xF0\x9F\x93\x99",
|
19
|
+
"\xF0\x9F\x93\x95",
|
20
|
+
"\xF0\x9F\x93\x9A",
|
21
|
+
"\xF0\x9F\x93\x93"
|
22
|
+
].each(&:freeze).freeze
|
23
|
+
|
24
|
+
def format_severity_icon(severity)
|
25
|
+
SEV_ICON[severity] || "\xF0\x9F\x93\x93"
|
26
|
+
end
|
27
|
+
|
28
|
+
TIME_ICON_FIRST_HALF = [
|
29
|
+
"\xF0\x9F\x95\x9B",
|
30
|
+
"\xF0\x9F\x95\x90",
|
31
|
+
"\xF0\x9F\x95\x91",
|
32
|
+
"\xF0\x9F\x95\x92",
|
33
|
+
"\xF0\x9F\x95\x93",
|
34
|
+
"\xF0\x9F\x95\x94",
|
35
|
+
"\xF0\x9F\x95\x95",
|
36
|
+
"\xF0\x9F\x95\x96",
|
37
|
+
"\xF0\x9F\x95\x97",
|
38
|
+
"\xF0\x9F\x95\x98",
|
39
|
+
"\xF0\x9F\x95\x99",
|
40
|
+
"\xF0\x9F\x95\x9A"
|
41
|
+
]
|
42
|
+
|
43
|
+
TIME_ICON_SECOND_HALF = [
|
44
|
+
"\xF0\x9F\x95\xA7",
|
45
|
+
"\xF0\x9F\x95\x9C",
|
46
|
+
"\xF0\x9F\x95\x9D",
|
47
|
+
"\xF0\x9F\x95\x9E",
|
48
|
+
"\xF0\x9F\x95\x9F",
|
49
|
+
"\xF0\x9F\x95\xA0",
|
50
|
+
"\xF0\x9F\x95\xA1",
|
51
|
+
"\xF0\x9F\x95\xA2",
|
52
|
+
"\xF0\x9F\x95\xA3",
|
53
|
+
"\xF0\x9F\x95\xA4",
|
54
|
+
"\xF0\x9F\x95\xA5",
|
55
|
+
"\xF0\x9F\x95\xA6"
|
56
|
+
]
|
57
|
+
|
58
|
+
def format_time_icon(time)
|
59
|
+
hour12 = time.strftime('%I').to_i
|
60
|
+
hour12 = 0 if hour12 == 12
|
61
|
+
minute = time.strftime('%M').to_i
|
62
|
+
if minute < 30
|
63
|
+
TIME_ICON_FIRST_HALF[hour12]
|
64
|
+
else
|
65
|
+
TIME_ICON_SECOND_HALF[hour12]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def add(severity, message = nil, progname = nil, &block)
|
70
|
+
severity ||= UNKNOWN
|
71
|
+
return true if severity < @level
|
72
|
+
if message.nil?
|
73
|
+
if block_given?
|
74
|
+
message = block.dup.call
|
75
|
+
else
|
76
|
+
message = progname
|
77
|
+
progname = @progname
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
chat_id = Telegram::LoggerBot.configuration.chat_id
|
82
|
+
time = Time.now
|
83
|
+
|
84
|
+
text = "#{format_severity_icon(severity)}*#{format_severity(severity)}*"
|
85
|
+
text << " _#{clear_markdown(progname)}_" if progname
|
86
|
+
text << "\n#{format_time_icon(time)}#{time}"
|
87
|
+
|
88
|
+
@api.send_message(chat_id: chat_id, text: text, parse_mode: 'Markdown')
|
89
|
+
@api.send_message(chat_id: chat_id, text: message)
|
90
|
+
|
91
|
+
return true unless @next_logger
|
92
|
+
|
93
|
+
@next_logger.add(severity, message, progname, &block)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Telegram
|
2
|
+
module LoggerBot
|
3
|
+
def self.new(obj = nil)
|
4
|
+
case obj
|
5
|
+
when ::Logger
|
6
|
+
Telegram::LoggerBot::Logger.new(obj)
|
7
|
+
when ::NilClass
|
8
|
+
Telegram::LoggerBot::Logger.new
|
9
|
+
else
|
10
|
+
fail("Unknown type of next logger #{obj.inspect}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'telegram/logger_bot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'telegram-loggerbot-ruby'
|
8
|
+
spec.version = Telegram::LoggerBot::VERSION
|
9
|
+
spec.authors = ['Anton Osenenko']
|
10
|
+
spec.email = ['anton.osenenko@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = "Telegram Logger Bot"
|
13
|
+
spec.homepage = 'https://github.com/a0s/telegram-loggerbot-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_dependency 'telegram-bot-ruby'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: telegram-loggerbot-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Osenenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: telegram-bot-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- anton.osenenko@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- img/preview1.jpg
|
52
|
+
- img/preview2.jpg
|
53
|
+
- lib/telegram/logger_bot.rb
|
54
|
+
- lib/telegram/logger_bot/configuration.rb
|
55
|
+
- lib/telegram/logger_bot/logger.rb
|
56
|
+
- lib/telegram/logger_bot/logger_bot.rb
|
57
|
+
- lib/telegram/logger_bot/version.rb
|
58
|
+
- telegram-loggerbot-ruby.gemspec
|
59
|
+
homepage: https://github.com/a0s/telegram-loggerbot-ruby
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.6.8
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Telegram Logger Bot
|
83
|
+
test_files: []
|