dialog_ruby 0.1.8 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50b52161687990f23ad7cff84999068743836e72ac832d43071b46c19b724518
4
- data.tar.gz: 2c4085bbe8b9b1cc4303a3013090e8be6bae7a54d2f8ff724b85bde4531ad23c
3
+ metadata.gz: de8a1266c971e423750e588c68386da28060d0f111e273925acfeac6fd53fdf2
4
+ data.tar.gz: bf7448b451fe7963009e2b1323d3be6fc28e9f05d53750c1ca939492a7f50b20
5
5
  SHA512:
6
- metadata.gz: 684b298d0a10b2f839ae392b5ced57a2947c64797c7597f7c38dca8477b86e297cc40dc2b2f466700b615cc542f3173eae1b5bc6637e745a61bb2774d07377bb
7
- data.tar.gz: 0b5fdb43a58eaba5995fdcb7946043b1577602da46b438671926dd9287bb472204b4d5556a1aa434609d3663abaca4994bb65229341ef42a5d921cef9600102d
6
+ metadata.gz: ce6bc8eafa36ce596ac2e7a4d5a1d36e2df955ea18fc5cf2e7f47a27ec8ba4c2a5b55978af936a88de1e0bf68c46055993e30f47fb3d170dfb652960072f7822
7
+ data.tar.gz: 31078ef9e5041b07f23777cbc936683e7381f4a1bcf978dfc40c059486771f285bbecc50cc2d91812381cb12dbee37eeb00300238e47d4eabbe58b0dcced4dbb
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
@@ -7,7 +7,7 @@ Type=simple
7
7
  WorkingDirectory=<%=Dialog.config.path.dialog%>
8
8
  EnvironmentFile=<%=Dialog.config.path.dialog%>/_env/%i
9
9
  Environment=runScope=start
10
- Environment=runMode=bot
10
+ Environment=runMode=<%=mode%>
11
11
  Environment=BotFullname=%i
12
12
 
13
13
  # Greatly reduce Ruby memory fragmentation and heap usage
@@ -20,7 +20,7 @@ TimeoutStopSec=5
20
20
  Restart=on-failure
21
21
  StandardOutput=syslog
22
22
  StandardError=syslog
23
- SyslogIdentifier=dialog_%i
23
+ SyslogIdentifier=dialog_<%=mode%>_%i
24
24
 
25
25
  [Install]
26
26
  WantedBy=multi-user.target
data/lib/configuration.rb CHANGED
@@ -98,7 +98,7 @@ module Dialog
98
98
 
99
99
  setting :log do
100
100
  setting :base, Dialog.checkEnv('LogLevel', 'info')
101
- setting :tdlib, Dialog.checkEnv('TdlibLoglevel', 1)
101
+ setting :tdlib, Dialog.checkEnv('TdlibLoglevel', 9)
102
102
  end
103
103
 
104
104
  setting :monitoring do
data/lib/dialog_ruby.rb CHANGED
@@ -17,7 +17,7 @@ module Dialog
17
17
  version = RUBY_VERSION.split('.').map { |x| x.to_i }
18
18
  if (version <=> [2, 5, 0]) >= 1
19
19
  require_relative './require.rb'
20
- _require
20
+ _require_min
21
21
  send("trigger_#{Dialog.config.run.scope}".to_sym)
22
22
  else
23
23
  puts "Minimum required Ruby version - 2.5.0"
File without changes
data/lib/require.rb CHANGED
@@ -13,21 +13,31 @@
13
13
  module Dialog
14
14
  class << self
15
15
 
16
- def _require
16
+ def _require_min
17
17
  ### SYSTEM
18
18
  require 'pp'
19
19
  require 'timeout'
20
20
  require 'logger'
21
21
  require 'socket'
22
22
  require 'fileutils'
23
- require 'uri'
24
23
  require 'open3'
24
+
25
+ ### DRY
26
+ require 'dry-configurable'
27
+ require_relative './version.rb'
28
+ require_relative './configuration.rb'
29
+ Dir.glob(File.join("#{File.dirname(__FILE__)}/triggers/**", "*.rb")).each{|f| require f}
30
+ end
31
+
32
+
33
+ def _require
34
+ ### SYSTEM
35
+ require 'uri'
25
36
  require 'erb'
26
37
  require 'shellwords'
27
38
 
28
39
  ### GEMS
29
40
  require 'dialect_lookup'
30
- require 'tdlib-ruby'
31
41
  require 'telegram/bot'
32
42
  require 'i18n'
33
43
  require 'redis'
@@ -38,7 +48,6 @@ module Dialog
38
48
  #lazy_object
39
49
 
40
50
  ### DRY
41
- require 'dry-configurable'
42
51
  # require 'dry-monads'
43
52
  # require 'dry-matcher'
44
53
  # require 'dry-transaction'
data/lib/tdlib/init.rb CHANGED
@@ -15,13 +15,13 @@ module Dialog
15
15
 
16
16
  def tdlibInit(name)
17
17
 
18
- FileUtils.mkdir_p("#{Dialog.config.path.data}/tdlib/#{name}")
18
+ FileUtils.mkdir_p("#{Dialog.config.path.dialogData}/tdlib/#{name}")
19
19
  config = {
20
20
  api_id: Dialog.config.api.id,
21
21
  api_hash: Dialog.config.api.hash_s,
22
22
  device_model: Dialog.config.naming.app,
23
- database_directory: "#{Dialog.config.path.data}/tdlib/#{name}",
24
- files_directory: "#{Dialog.config.path.data}/tdlib/#{name}",
23
+ database_directory: "#{Dialog.config.path.dialogData}/tdlib/#{name}",
24
+ files_directory: "#{Dialog.config.path.dialogData}/tdlib/#{name}",
25
25
  }
26
26
 
27
27
  TD.configure do |config|
@@ -14,11 +14,13 @@ module Dialog
14
14
  class << self
15
15
 
16
16
  def trigger_deploy
17
+ require 'erb'
17
18
  deploy_redis
18
19
  deploy_bot
20
+ deploy_binaries
19
21
  end
20
22
 
21
- def erb(erbFile, dst)
23
+ def erb(erbFile, dst, mode='')
22
24
  if not File.file?(dst)
23
25
  tmpl = ERB.new(File.read("#{Dialog.config.path.dialog_ruby}/exec/#{erbFile}")).result(binding)
24
26
  File.open(dst, 'w') do |f| f.write tmpl; end
@@ -26,23 +28,40 @@ module Dialog
26
28
  end
27
29
 
28
30
  def deploy_redis
29
- redisDir = "#{Dialog.config.path.dialogData}/redis"
30
- FileUtils.mkdir_p redisDir
31
- erb('systemd/dialog_redis.service', "#{Dir.home}/.config/systemd/user/dialog_redis.service")
32
- erb('conf/redis_local.conf', "#{redisDir}/redis_local.conf")
33
- erb('conf/redis_global.conf', "#{redisDir}/redis_global.conf")
34
- systemd('dialog_redis')
31
+ if File.file?('/usr/sbin/redis-server')
32
+ redisDir = "#{Dialog.config.path.dialogData}/redis"
33
+ FileUtils.mkdir_p redisDir
34
+ erb('systemd/dialog_redis.service', "#{Dir.home}/.config/systemd/user/dialog_redis.service")
35
+ erb('conf/redis_local.conf', "#{redisDir}/redis_local.conf")
36
+ erb('conf/redis_global.conf', "#{redisDir}/redis_global.conf")
37
+ systemd('dialog_redis')
38
+ else
39
+ Dialog.logger.error "Please install Redis binary"
40
+ Dialog.logger.info "openSUSE: zypper --no-gpg-checks --non-interactive in redis"
41
+ exit(false)
42
+ end
35
43
  end
36
44
 
37
45
 
38
46
  def deploy_bot
39
- erb('systemd/dialog_bot@.service', "#{Dir.home}/.config/systemd/user/dialog_bot@.service")
47
+ erb('systemd/dialog_runMode@.service', "#{Dir.home}/.config/systemd/user/dialog_bot_pre@.service", 'check')
40
48
  systemd("dialog_bot@#{Dialog.config.naming.full}")
49
+
50
+ erb('systemd/dialog_runMode@.service', "#{Dir.home}/.config/systemd/user/dialog_bot@.service", Dialog.config.run.mode)
51
+ systemd("dialog_bot@#{Dialog.config.naming.full}")
41
52
  end
42
53
 
43
54
  def deploy_tdlib
55
+ erb('systemd/dialog_runMode@.service', "#{Dir.home}/.config/systemd/user/dialog_tdlib@.service", Dialog.config.run.mode)
56
+ systemd("dialog_tdlib@#{Dialog.config.naming.full}")
44
57
  end
45
58
 
59
+ def deploy_binaries
60
+ Dialog.logger.info "openSUSE: zypper ar -cf https://download.opensuse.org/repositories/home:/in4ops:/4wrap/openSUSE_Leap_15.0/home:in4ops:4wrap.repo"
61
+ #will be 'home:in4ops:Innosense:libs'
62
+ Dialog.logger.info "openSUSE: zypper --no-gpg-checks --non-interactive in zbar tdlib"
63
+ end
64
+
46
65
  def deploy_devenv
47
66
  end
48
67
 
@@ -51,7 +70,8 @@ module Dialog
51
70
 
52
71
  def systemd(service)
53
72
  Open3.popen3('/usr/bin/systemctl', '--user', 'daemon-reload')
54
- Open3.popen3('/usr/bin/systemctl', '--user', 'restart', service)
73
+ # Open3.popen3('/usr/bin/systemctl', '--user', 'restart', service)
74
+ #enable
55
75
  end
56
76
 
57
77
  end
@@ -17,17 +17,23 @@ module Dialog
17
17
  args = {}
18
18
  case Dialog.config.common.mode
19
19
  when 'check'
20
+ _require
20
21
  jsonDriven(args, :check)
21
22
  when 'bot'
23
+ _require
22
24
  jsonDriven(args, :prod)
23
25
  bot(args)
24
26
  when 'dev'
27
+ _require
25
28
  dialectDriven(args)
26
29
  jsonDriven(args, :prod)
27
30
  bot(args)
28
31
  when 'dev_offline'
32
+ _require
29
33
  dialectDriven(args)
30
- jsonDriven(args, :check)
34
+ jsonDriven(args, :check)
35
+ when 'tdlib'
36
+ start_tdlib(args)
31
37
  else
32
38
  Dialog.logger.error "ERROR: no such mode - '#{Dialog.config.common.mode}'"
33
39
  end
File without changes
@@ -13,32 +13,13 @@
13
13
  module Dialog
14
14
  class << self
15
15
 
16
- def tdlibInit(args)
17
- inits = ['cli']
18
- args[:tdlib] = {}
19
- inits.each do |init|
20
- unless File.exists?("#{Dialog.config.path.data}/tdlib/#{init}/td.binlog")
21
- Dialog.logger.error "ERROR: please make init of the '#{init}' using 'ruby dialog.rb init #{init}"
22
- exit(false)
23
- end
24
- args[:tdlib][init.to_sym] = Dialog::TDLib.tdlibInit(init)
25
- end
26
- args[:tdlib].freeze
27
- end
28
-
29
16
 
30
17
  def bot(args)
31
18
  args[:globals] = {}
32
19
 
33
20
  ### LANG
34
21
  i18n = Dialog::Lang.initial
35
-
36
- ## BUG - TEMPORARY DISABLE
37
- # tdlibInit(args)
38
- # args[:tdlib][:cli].on_ready do |client|
39
- # a = client.fetch('@type' => 'getMe')
40
- # args[:globals][:cliId] = a['id'].to_i
41
- # end
22
+
42
23
  begin
43
24
  Dialog::redis.call(['info', 'clients'])
44
25
  rescue
@@ -0,0 +1,42 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+
13
+ module Dialog
14
+ class << self
15
+
16
+ def start_tdlib(args)
17
+ require 'tdlib-ruby'
18
+ args[:globals] = {}
19
+ Dir.glob(File.join("#{Dialog.config.path.dialog_rubyLib}/tdlib/**", "*.rb")).each{|f| require f}
20
+ tdlibInit(args)
21
+ args[:tdlib][:cli].on_ready do |client|
22
+ a = client.fetch('@type' => 'getMe')
23
+ args[:globals][:cliId] = a['id'].to_i
24
+ end
25
+ end
26
+
27
+
28
+ def tdlibInit(args)
29
+ inits = ['cli']
30
+ args[:tdlib] = {}
31
+ inits.each do |init|
32
+ unless File.exists?("#{Dialog.config.path.dialogData}/tdlib/#{init}/td.binlog")
33
+ Dialog.logger.error "ERROR: please make init of the '#{init}' using 'ruby dialog.rb init #{init}"
34
+ exit(false)
35
+ end
36
+ args[:tdlib][init.to_sym] = Dialog::TDLib.tdlibInit(init)
37
+ end
38
+ args[:tdlib].freeze
39
+ end
40
+
41
+ end
42
+ end
data/lib/version.rb CHANGED
@@ -11,5 +11,5 @@
11
11
  ######## ####### ######## ####### ######## ########
12
12
 
13
13
  module Dialog
14
- VERSION = '0.1.8'.freeze
14
+ VERSION = '0.1.9'.freeze
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dialog_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Istomin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-25 00:00:00.000000000 Z
11
+ date: 2018-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dialect_lookup
@@ -173,6 +173,7 @@ extra_rdoc_files: []
173
173
  files:
174
174
  - ".gitignore"
175
175
  - Gemfile
176
+ - LICENSE
176
177
  - _dev/get_full_botapi.rb
177
178
  - _dev/inlinekb_pubsub.rb
178
179
  - _dev/main.rb
@@ -189,13 +190,11 @@ files:
189
190
  - exec/git_sync/dialog__sync.service
190
191
  - exec/git_sync/dialog__sync.timer
191
192
  - exec/git_sync/post-merge
192
- - exec/systemd/deploy.sh
193
- - exec/systemd/dialog_bot@.path
194
- - exec/systemd/dialog_bot@.service
195
- - exec/systemd/dialog_bot_dev@.path
196
- - exec/systemd/dialog_bot_dev_pre@.service
197
- - exec/systemd/dialog_bot_pre@.service
193
+ - exec/systemd/_fix/dialog_bot@.path
194
+ - exec/systemd/_fix/dialog_bot_dev@.path
195
+ - exec/systemd/_fix/dialog_bot_dev_pre@.service
198
196
  - exec/systemd/dialog_redis.service
197
+ - exec/systemd/dialog_runMode@.service
199
198
  - lang/global_ru.yml
200
199
  - lib/configuration.rb
201
200
  - lib/dialect/canvas/canvas.rb
@@ -254,10 +253,10 @@ files:
254
253
  - lib/metamess/event/notify_o.rb
255
254
  - lib/metamess/event_c.rb
256
255
  - lib/metamess/func.rb
256
+ - lib/metamess/naming.rb
257
257
  - lib/metamess/service/service_o-callback_f.rb
258
258
  - lib/metamess/service/service_o-inline_f.rb
259
259
  - lib/metamess/service/service_o.rb
260
- - lib/naming.rb
261
260
  - lib/require.rb
262
261
  - lib/storage/redis/redisPubSub.rb
263
262
  - lib/storage/redis/rediscached.rb
@@ -274,9 +273,10 @@ files:
274
273
  - lib/triggers/deploy/deploy.rb
275
274
  - lib/triggers/false.rb
276
275
  - lib/triggers/init.rb
277
- - lib/triggers/start/start.rb
278
- - lib/triggers/start/start_bot.rb
279
- - lib/triggers/start/start_pre.rb
276
+ - lib/triggers/start/_main.rb
277
+ - lib/triggers/start/_pre_bot.rb
278
+ - lib/triggers/start/bot.rb
279
+ - lib/triggers/start/tdlib.rb
280
280
  - lib/version.rb
281
281
  - logo.png
282
282
  homepage: https://gitlab.com/Innosense/MVP/dialog_ruby
@@ -1,31 +0,0 @@
1
- ######## ####### ######## ####### ######## ########
2
- ## / / / / License \ \ \ \
3
- ## Copyleft culture, Copyright (C) is prohibited here
4
- ## This work is licensed under a CC BY-SA 4.0
5
- ## Creative Commons Attribution-ShareAlike 4.0 License
6
- ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
- ######## ####### ######## ####### ######## ########
8
- ## / / / / Code Climate \ \ \ \
9
- ## Language = bash
10
- ## Indent = space; 2 chars;
11
- ######## ####### ######## ####### ######## ########
12
- set -e
13
-
14
- runInitMain() (
15
- if [ ! -f ~/.config/systemd/user/dialog_bot@.service ] || [ ! -f ~/.config/systemd/user/dialog_redis@.service ] ; then
16
- cp dialog*@.service ~/.config/systemd/user
17
- sed -i "s#{RunPath}#`echo $PWD`#" ~/.config/systemd/user/dialog*@.service
18
- fi
19
- systemctl --user daemon-reload
20
- )
21
-
22
- botRunInit() (
23
- mkdir -p ~/.config/systemd/user ./_data/${BotFullname}
24
- runInitMain
25
-
26
- if [ ! -f ./_data/${BotFullname}/redis.conf ]; then
27
- cp ../conf/redis_local.conf ./_data/${BotFullname}/redis.conf
28
- sed -i "s/{INSTANCE}/${BotFullname}/" ./_data/${BotFullname}/redis.conf
29
- fi
30
- systemctl --user daemon-reload
31
- )
@@ -1,16 +0,0 @@
1
- [Unit]
2
- Description= Dialog (Telegram Bot abstraction layer) - instance %i
3
- After=syslog.target network.target
4
-
5
- [Service]
6
- Type=oneshot
7
- WorkingDirectory={RunPath}
8
- EnvironmentFile={RunPath}/_env/%i
9
- ExecStartPre=/usr/bin/ruby.ruby2.5 ./dialog.rb start check %i
10
- ExecStart=/usr/bin/systemctl --user restart dialog_bot@%i
11
- StandardOutput=syslog
12
- StandardError=syslog
13
- SyslogIdentifier=dialog_pre_%i
14
-
15
- [Install]
16
- WantedBy=multi-user.target