yorgi 0.1.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
+ SHA256:
3
+ metadata.gz: 676411de9c101d44fd5c88fa5dd67136925bb39b956f08a67cb2df91c9735de1
4
+ data.tar.gz: 6a6681be9139fbf86911ffcda0df949bc7434b4893cd801c798d215d03c4db10
5
+ SHA512:
6
+ metadata.gz: cac1591b09f500c403c61233a25a479dab03213a758271b1debe224545823868884aad07745aa00cb6b7cb5ad319b0f27e01883fb4f7259e2116b36caabab413
7
+ data.tar.gz: a48cd71d8de65836e236395021671b3411e68c24d43e266ea65e7b8600eab05cacbb14620e926a850ab7e329fd50bfe60bc71e6e34e9ddef1ace23bd0fe5b8a7
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ ---
2
+ require:
3
+ - rubocop-minitest
4
+ - rubocop-performance
5
+ - rubocop-rails
6
+
7
+ Bundler/OrderedGems:
8
+ Enabled: false
9
+
10
+ Layout/IndentationConsistency:
11
+ Enabled: true
12
+ EnforcedStyle: indented_internal_methods
13
+
14
+ Layout/LineLength:
15
+ Enabled: true
16
+ Max: 80
17
+
18
+ Metrics/AbcSize:
19
+ Enabled: false
20
+
21
+ Metrics/MethodLength:
22
+ Enabled: true
23
+ CountAsOne: ['array', 'hash']
24
+
25
+ Style/Documentation:
26
+ Enabled: false
27
+
28
+ Style/FrozenStringLiteralComment:
29
+ Enabled: false
30
+
31
+ Style/StringLiterals:
32
+ Enabled: true
33
+ EnforcedStyle: double_quotes
34
+ ...
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in yorgi.gemspec
6
+ gemspec
7
+
8
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
9
+
10
+ gem "rake"
11
+ gem "org-ruby", github: "wallyqs/org-ruby"
12
+ gem "telegram-bot-ruby", "~> 0.15.0"
13
+ gem "i18n", "~> 1.8"
14
+ gem "rails-i18n", "~> 6.0"
15
+ gem "zeitwerk", "~> 2.4"
16
+ gem "filewatcher", "~> 1.1"
17
+ gem "config", "~> 3.1"
18
+
19
+ group :test, :development do
20
+ gem "byebug"
21
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,169 @@
1
+ GIT
2
+ remote: https://github.com/wallyqs/org-ruby
3
+ revision: 7a28c2e6e91cdaceb1fddc2d870f4458632816e8
4
+ specs:
5
+ org-ruby (0.9.12)
6
+ rubypants (~> 0.2)
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ yorgi (0.1.0)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actionpack (6.1.3.2)
17
+ actionview (= 6.1.3.2)
18
+ activesupport (= 6.1.3.2)
19
+ rack (~> 2.0, >= 2.0.9)
20
+ rack-test (>= 0.6.3)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
23
+ actionview (6.1.3.2)
24
+ activesupport (= 6.1.3.2)
25
+ builder (~> 3.1)
26
+ erubi (~> 1.4)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
29
+ activesupport (6.1.3.2)
30
+ concurrent-ruby (~> 1.0, >= 1.0.2)
31
+ i18n (>= 1.6, < 2)
32
+ minitest (>= 5.1)
33
+ tzinfo (~> 2.0)
34
+ zeitwerk (~> 2.3)
35
+ axiom-types (0.1.1)
36
+ descendants_tracker (~> 0.0.4)
37
+ ice_nine (~> 0.11.0)
38
+ thread_safe (~> 0.3, >= 0.3.1)
39
+ builder (3.2.4)
40
+ byebug (11.1.3)
41
+ coercible (1.0.0)
42
+ descendants_tracker (~> 0.0.1)
43
+ concurrent-ruby (1.1.8)
44
+ config (3.1.0)
45
+ deep_merge (~> 1.2, >= 1.2.1)
46
+ dry-validation (~> 1.0, >= 1.0.0)
47
+ crass (1.0.6)
48
+ deep_merge (1.2.1)
49
+ descendants_tracker (0.0.4)
50
+ thread_safe (~> 0.3, >= 0.3.1)
51
+ dry-configurable (0.12.1)
52
+ concurrent-ruby (~> 1.0)
53
+ dry-core (~> 0.5, >= 0.5.0)
54
+ dry-container (0.7.2)
55
+ concurrent-ruby (~> 1.0)
56
+ dry-configurable (~> 0.1, >= 0.1.3)
57
+ dry-core (0.5.0)
58
+ concurrent-ruby (~> 1.0)
59
+ dry-equalizer (0.3.0)
60
+ dry-inflector (0.2.0)
61
+ dry-initializer (3.0.4)
62
+ dry-logic (1.2.0)
63
+ concurrent-ruby (~> 1.0)
64
+ dry-core (~> 0.5, >= 0.5)
65
+ dry-schema (1.6.2)
66
+ concurrent-ruby (~> 1.0)
67
+ dry-configurable (~> 0.8, >= 0.8.3)
68
+ dry-core (~> 0.5, >= 0.5)
69
+ dry-initializer (~> 3.0)
70
+ dry-logic (~> 1.0)
71
+ dry-types (~> 1.5)
72
+ dry-types (1.5.1)
73
+ concurrent-ruby (~> 1.0)
74
+ dry-container (~> 0.3)
75
+ dry-core (~> 0.5, >= 0.5)
76
+ dry-inflector (~> 0.1, >= 0.1.2)
77
+ dry-logic (~> 1.0, >= 1.0.2)
78
+ dry-validation (1.6.0)
79
+ concurrent-ruby (~> 1.0)
80
+ dry-container (~> 0.7, >= 0.7.1)
81
+ dry-core (~> 0.4)
82
+ dry-equalizer (~> 0.2)
83
+ dry-initializer (~> 3.0)
84
+ dry-schema (~> 1.5, >= 1.5.2)
85
+ equalizer (0.0.11)
86
+ erubi (1.10.0)
87
+ faraday (1.4.2)
88
+ faraday-em_http (~> 1.0)
89
+ faraday-em_synchrony (~> 1.0)
90
+ faraday-excon (~> 1.1)
91
+ faraday-net_http (~> 1.0)
92
+ faraday-net_http_persistent (~> 1.1)
93
+ multipart-post (>= 1.2, < 3)
94
+ ruby2_keywords (>= 0.0.4)
95
+ faraday-em_http (1.0.0)
96
+ faraday-em_synchrony (1.0.0)
97
+ faraday-excon (1.1.0)
98
+ faraday-net_http (1.0.1)
99
+ faraday-net_http_persistent (1.1.0)
100
+ filewatcher (1.1.1)
101
+ optimist (~> 3.0)
102
+ i18n (1.8.10)
103
+ concurrent-ruby (~> 1.0)
104
+ ice_nine (0.11.2)
105
+ inflecto (0.0.2)
106
+ loofah (2.9.1)
107
+ crass (~> 1.0.2)
108
+ nokogiri (>= 1.5.9)
109
+ method_source (1.0.0)
110
+ mini_portile2 (2.5.1)
111
+ minitest (5.14.4)
112
+ multipart-post (2.1.1)
113
+ nokogiri (1.11.6)
114
+ mini_portile2 (~> 2.5.0)
115
+ racc (~> 1.4)
116
+ optimist (3.0.1)
117
+ racc (1.5.2)
118
+ rack (2.2.3)
119
+ rack-test (1.1.0)
120
+ rack (>= 1.0, < 3)
121
+ rails-dom-testing (2.0.3)
122
+ activesupport (>= 4.2.0)
123
+ nokogiri (>= 1.6)
124
+ rails-html-sanitizer (1.3.0)
125
+ loofah (~> 2.3)
126
+ rails-i18n (6.0.0)
127
+ i18n (>= 0.7, < 2)
128
+ railties (>= 6.0.0, < 7)
129
+ railties (6.1.3.2)
130
+ actionpack (= 6.1.3.2)
131
+ activesupport (= 6.1.3.2)
132
+ method_source
133
+ rake (>= 0.8.7)
134
+ thor (~> 1.0)
135
+ rake (13.0.3)
136
+ ruby2_keywords (0.0.4)
137
+ rubypants (0.7.1)
138
+ telegram-bot-ruby (0.15.0)
139
+ faraday
140
+ inflecto
141
+ virtus
142
+ thor (1.1.0)
143
+ thread_safe (0.3.6)
144
+ tzinfo (2.0.4)
145
+ concurrent-ruby (~> 1.0)
146
+ virtus (1.0.5)
147
+ axiom-types (~> 0.1)
148
+ coercible (~> 1.0)
149
+ descendants_tracker (~> 0.0, >= 0.0.3)
150
+ equalizer (~> 0.0, >= 0.0.9)
151
+ zeitwerk (2.4.2)
152
+
153
+ PLATFORMS
154
+ ruby
155
+
156
+ DEPENDENCIES
157
+ byebug
158
+ config (~> 3.1)
159
+ filewatcher (~> 1.1)
160
+ i18n (~> 1.8)
161
+ org-ruby!
162
+ rails-i18n (~> 6.0)
163
+ rake
164
+ telegram-bot-ruby (~> 0.15.0)
165
+ yorgi!
166
+ zeitwerk (~> 2.4)
167
+
168
+ BUNDLED WITH
169
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Ermenegildo Fiorito
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.org ADDED
@@ -0,0 +1,20 @@
1
+ * Yorgi
2
+
3
+ Interact with your Org Mode files from Telegram
4
+
5
+ ** Setup
6
+
7
+ 1. Change the relevant settings in ~config/settings.yml~
8
+ 2. Run!
9
+ #+BEGIN_SRC sh
10
+ bundle install
11
+ ./bin/yorgi
12
+ #+END_SRC
13
+
14
+ ** Contributing
15
+
16
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gildo/yorgi.
17
+
18
+ ** License
19
+
20
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yorgi"
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
data/bin/yorgi ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ Bundler.require(:default)
4
+
5
+ require "yorgi"
6
+
7
+ yorgi_env = ENV["YORGI_ENV"] || "development"
8
+
9
+ # TODO: Add env specific configuration
10
+ Config.load_and_set_settings("config/settings.yml")
11
+
12
+ server = Yorgi::Server.new
13
+ server.run
@@ -0,0 +1,9 @@
1
+ token: <%= ENV["YORGI_TOKEN"] || "" %>
2
+
3
+ org_directory: /home/gildo/org/
4
+ org_file: /home/gildo/org/ynbox.org
5
+ journal_directory: /home/gildo/org/journal/
6
+ journal_file_format: "%Y-%m-%d.org"
7
+ journal_time_format: "%R"
8
+ journal_date_prefix: "#+TITLE: "
9
+ journal_date_format: "%A, %x"
data/lib/yorgi.rb ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "filewatcher"
4
+ require "yaml"
5
+ require "org-ruby"
6
+ require "telegram/bot"
7
+
8
+ require "zeitwerk"
9
+ loader = Zeitwerk::Loader.for_gem
10
+ loader.enable_reloading
11
+ loader.push_dir("#{__dir__}/")
12
+ loader.setup # ready!
13
+
14
+ filewatcher = Filewatcher.new("lib/")
15
+ Thread.new(filewatcher) do |fw|
16
+ fw.watch do |_|
17
+ puts "Reloading.."
18
+ loader.reload
19
+ end
20
+ end
21
+
22
+ module Yorgi
23
+ end
@@ -0,0 +1,29 @@
1
+ # lib/message_responder.rb
2
+
3
+ module Yorgi
4
+ class MessageResponder
5
+ include Utils
6
+
7
+ attr_accessor :journaling
8
+ attr_reader :message, :bot
9
+
10
+ def initialize(bot, message)
11
+ @bot = bot
12
+ @message = message
13
+ @journaling = Settings.journaling
14
+ end
15
+
16
+ def list
17
+ bot.api.send_message(chat_id: message.chat.id, text: headlines)
18
+ end
19
+
20
+ def journal
21
+ Org::Journal.new.add message.text
22
+ end
23
+
24
+ def capture
25
+ Org::Capture.new.capture message.text
26
+ list
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ # lib/message_router.rb
2
+
3
+ module Yorgi
4
+ class MessageRouter
5
+ include Utils
6
+ attr_reader :bot, :message, :responder
7
+
8
+ def initialize(bot, message)
9
+ @bot = bot
10
+ @message = message
11
+ @responder = MessageResponder.new(bot, message)
12
+ end
13
+
14
+ def route
15
+ case message.text
16
+ when "/list"
17
+ @responder.list
18
+ when "/j"
19
+ Settings.journaling = !Settings.journaling
20
+ bot.api.send_message(chat_id: message.chat.id,
21
+ text: "journaling: #{Settings.journaling}")
22
+ else
23
+ if Settings.journaling
24
+ @responder.journal
25
+ else
26
+ @responder.capture
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ module Yorgi::Org
2
+ class Capture
3
+ include Yorgi::Utils
4
+ attr_reader :capture_file
5
+
6
+ def initialize
7
+ # TODO: set different capture file
8
+ @capture_file = Settings.org_file
9
+ end
10
+
11
+ def capture(text)
12
+ write capture_file, "* #{text}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ module Yorgi::Org
2
+ class Journal
3
+ include Yorgi::Utils
4
+ attr_reader :directory,
5
+ :date_format,
6
+ :file_format,
7
+ :time_format,
8
+ :date_prefix,
9
+ :journal_file
10
+
11
+ def initialize
12
+ @directory = Settings.journal_directory
13
+ @file_format = Settings.journal_file_format
14
+ @time_format = Settings.journal_time_format
15
+ @date_prefix = Settings.journal_date_prefix
16
+ @date_format = Settings.journal_date_format
17
+ @journal_file = File.join directory, now.strftime(file_format)
18
+ end
19
+
20
+ def add(text)
21
+ text = "** #{now.strftime(time_format)} \n #{text}"
22
+
23
+ add_headline unless File.exist? journal_file
24
+
25
+ write(journal_file, text)
26
+ end
27
+
28
+ private
29
+
30
+ def add_headline
31
+ title = "#{date_prefix}#{now.strftime(date_format)}"
32
+ write journal_file, title
33
+ end
34
+
35
+ def now
36
+ DateTime.now
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ module Yorgi
2
+ class Server
3
+ def initialize; end
4
+
5
+ def client
6
+ @client ||= Telegram::Bot::Client.new(Settings.token)
7
+ end
8
+
9
+ def run
10
+ client.run do |bot|
11
+ bot.listen do |message|
12
+ message_handler(bot, message)
13
+ end
14
+ end
15
+ end
16
+
17
+ def message_handler(bot, message)
18
+ MessageRouter.new(bot, message).route
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # lib/utils.rb
2
+
3
+ module Yorgi
4
+ module Utils
5
+ def write(file, text)
6
+ f = File.open(file, "a")
7
+ f.puts(text)
8
+ ensure
9
+ f.close
10
+ end
11
+
12
+ def headlines
13
+ filepath = File.join Settings.org_file
14
+ file = File.read filepath
15
+ parser = Orgmode::Parser.new(file)
16
+ parser.headlines.map(&:to_s).join("\n")
17
+ end
18
+ end
19
+ end
data/yorgi.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "yorgi"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Ermenegildo Fiorito"]
5
+ spec.email = ["gildo.fiorito@gmail.com"]
6
+
7
+ spec.summary = "Yorgi: Org Mode in Telegram"
8
+ spec.description = "Yorgi: Org Mode in Telegram"
9
+ spec.homepage = "https://github.com/gildo/yorgi"
10
+ spec.license = "MIT"
11
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+
13
+ spec.metadata["homepage_uri"] = spec.homepage
14
+ spec.metadata["source_code_uri"] = "https://github.com/gildo/yorgi"
15
+
16
+ spec.metadata["changelog_uri"] = "https://github.com/gildo/yorgi"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yorgi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ermenegildo Fiorito
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Yorgi: Org Mode in Telegram'
14
+ email:
15
+ - gildo.fiorito@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rubocop.yml"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.org
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - bin/yorgi
30
+ - config/settings.yml
31
+ - lib/yorgi.rb
32
+ - lib/yorgi/message_responder.rb
33
+ - lib/yorgi/message_router.rb
34
+ - lib/yorgi/org/capture.rb
35
+ - lib/yorgi/org/journal.rb
36
+ - lib/yorgi/server.rb
37
+ - lib/yorgi/utils.rb
38
+ - yorgi.gemspec
39
+ homepage: https://github.com/gildo/yorgi
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://github.com/gildo/yorgi
44
+ source_code_uri: https://github.com/gildo/yorgi
45
+ changelog_uri: https://github.com/gildo/yorgi
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.1.4
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: 'Yorgi: Org Mode in Telegram'
65
+ test_files: []