dialog_ruby 0.1.10 → 0.1.11

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +13 -0
  3. data/{lib/storage/redis → _dev}/redisPubSub.rb +1 -1
  4. data/background/_init.rb +43 -0
  5. data/background/batch.rb +69 -0
  6. data/background/redis.rb +34 -0
  7. data/dialog_ruby.gemspec +6 -7
  8. data/exec/conf/redis_global.conf +4 -2
  9. data/exec/dialog.sh +28 -26
  10. data/exec/git_sync/dialog__sync.service +1 -1
  11. data/exec/prereq.sh +18 -1
  12. data/exec/systemd/dialog_background.service +29 -0
  13. data/exec/systemd/dialog_redis.service +1 -1
  14. data/exec/systemd/dialog_runMode@.service +16 -6
  15. data/exec/systemd/dialog_runner@.path +8 -0
  16. data/lib/{triggers/start → begin}/_main.rb +29 -21
  17. data/lib/begin/_pre_bot.rb +58 -0
  18. data/lib/begin/background.rb +24 -0
  19. data/lib/{triggers/start → begin}/bot.rb +27 -6
  20. data/lib/{triggers/start → begin}/tdlib.rb +12 -16
  21. data/lib/configuration.rb +39 -27
  22. data/lib/dialect/canvas/element/send/Inline_query_result.rb +2 -0
  23. data/lib/dialect/canvas/element/send/background.rb +28 -0
  24. data/lib/dialect/canvas/element/send/recognize.rb +3 -2
  25. data/lib/dialect/canvas/element/send/restrict.rb +0 -1
  26. data/lib/dialect/canvas/element/send/tdlib_chat.rb +1 -1
  27. data/lib/dialect/canvas/element/send/tdlib_message.rb +1 -1
  28. data/lib/dialect/codegen/codegen.rb +9 -9
  29. data/lib/dialect/codegen/erb/functional/2.2.1.Events2ModReceive.erb +27 -4
  30. data/lib/dialect/codegen/erb/functional/4.1.AppEvent2Elements.erb +7 -2
  31. data/lib/dialect/codegen/erb/functional/5.1.Element2ModElements.erb +1 -1
  32. data/lib/dialect/codegen/erb/functional/7.ElementChains.erb +7 -6
  33. data/lib/dialog_ruby.rb +5 -2
  34. data/lib/metamess/_run.rb +1 -0
  35. data/lib/metamess/content/content_o-contact_f.rb +41 -0
  36. data/lib/metamess/content/content_o.rb +7 -6
  37. data/lib/metamess/func.rb +0 -24
  38. data/lib/metamess/naming.rb +8 -5
  39. data/lib/metamess/service/service_o-inline_f.rb +4 -3
  40. data/lib/require.rb +21 -2
  41. data/lib/statistics/func.rb +72 -0
  42. data/lib/statistics/general.rb +44 -0
  43. data/lib/statistics/redisDump.rb +49 -0
  44. data/lib/storage/redis/cached/pullpush.rb +76 -0
  45. data/lib/storage/redis/cached/pushPreproc.rb +41 -0
  46. data/lib/storage/redis/func.rb +47 -0
  47. data/lib/storage/redis/stat/push.rb +33 -0
  48. data/lib/tdlib/auth.rb +8 -7
  49. data/lib/tdlib/init.rb +5 -5
  50. data/lib/telegram/botapi.rb +2 -1
  51. data/lib/telegram/wrappers.rb +1 -2
  52. data/lib/tooling/log.rb +0 -1
  53. data/lib/tooling/strings.rb +12 -0
  54. data/lib/triggers/_func.rb +39 -0
  55. data/lib/triggers/{_meta/full.rb → console_start.rb} +8 -5
  56. data/lib/triggers/deploy.rb +104 -0
  57. data/lib/triggers/false.rb +8 -6
  58. data/lib/triggers/init.rb +23 -10
  59. data/lib/triggers/systemd_start.rb +24 -0
  60. data/lib/version.rb +1 -1
  61. metadata +83 -41
  62. data/_dev/sidekiq.rb +0 -28
  63. data/exec/systemd/_fix/dialog_bot@.path +0 -6
  64. data/exec/systemd/_fix/dialog_bot_dev@.path +0 -6
  65. data/exec/systemd/_fix/dialog_bot_dev_pre@.service +0 -16
  66. data/lib/storage/redis/rediscached.rb +0 -97
  67. data/lib/triggers/deploy/deploy.rb +0 -78
  68. data/lib/triggers/start/_pre_bot.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00b5be156c8481f0ecf9a93d185b4c3d070f53d05dae47addf2d5dd002d838b9
4
- data.tar.gz: c6fa9db24028794a0b705de5a7334adebbda338180fa902af2d6fc45d5b2c376
3
+ metadata.gz: edf13cf660e814e5a448bea845d6078bee8a9ea15c8b5e89b432f5f56b616f07
4
+ data.tar.gz: 27414e8dfb0d6eba3282a2f695b12643d8b107ee84d1138f4cdb798291133939
5
5
  SHA512:
6
- metadata.gz: 2c282cc5e863660f002fe4c03a6da2812e655b07248f238dc4280a4b6430a221076a6329b0548c5243304247013f04095a2ac3c2d0ee9ad46ee1c33b682335cd
7
- data.tar.gz: c300f6cbd8767592793a2b2e30ec8d3e281287ae2e0f25750b3fc0e4ee84f4ff3dd3d2e85871256ce637110703bc085e7ed0edfa08e8c0b0c3dae4f84a952a34
6
+ metadata.gz: 938c3e4a721e3b939bda7db593602462325773d2100270c4418d8162b353df88b7d1d63bfde4872fcd15a32fc5da33eed8a5148bd3fbd6efebd24646726cb4a3
7
+ data.tar.gz: 27aa3098126b9ec3046be95869992bedb04581ca2a915bf4cc8092894807fe843fdacbc3358a4ab0f52f8d679155e5109abc9c589702444b00a7b105a8f0ae85
@@ -0,0 +1,13 @@
1
+ FROM opensuse:leap
2
+ LABEL maintainer="Eugene Istomin <e.istomin@innosense.org>"
3
+
4
+ RUN zypper ar -cf http://download.opensuse.org/repositories/openSUSE:/Leap:/15.0/standard standard::leap15.0
5
+ RUN zypper ar -cf http://download.opensuse.org/update/leap/15.0/oss update_oss::leap15.0
6
+ RUN zypper ar -cf http://download.opensuse.org/update/openSUSE-stable update_oss::stable
7
+
8
+ RUN zypper --gpg-auto-import-keys --non-interactive in --replacefiles -f ruby2.5-devel ruby2.5-rubygem-sqlite3
9
+ RUN gem specific_install -u -l https://gitlab.com/Innosense/MVP/dialog_ruby.git
10
+
11
+ ENTRYPOINT ["/bin/echo"]
12
+ CMD ["hi"]
13
+
@@ -33,7 +33,7 @@ module Dialog
33
33
  def subGetUnsub(args,redisChannelPrefix,redisSubTimeout)
34
34
  args[:x][:redis][:redisChannelpostfix].nil? ? args[:x][:redis][:redisChannelpostfix] = "" : true
35
35
  redisChannel = "#{redisChannelPrefix}__#{args[:x][:redis][:subPostfix]}_#{args[:x][:redis][:redisChannelpostfix]}"
36
- redis ||= Redis.new(path: Bot.configuration.redis_url)
36
+ #redis ||= Redis.new
37
37
  redis.subscribe_with_timeout(redisSubTimeout, redisChannel) do |on, subscriptions|
38
38
  Dialog.logger.debug "Subscribed to #{redisChannel} (#{subscriptions} subscriptions)"
39
39
  on.message do |channel, msg|
@@ -0,0 +1,43 @@
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
+ module Background
15
+ class << self
16
+
17
+ require 'active_support/time'
18
+ require 'drb'
19
+ require_relative './../lib/require.rb'
20
+ Dialog._require_min
21
+ Dialog._require_background
22
+ Dir.glob(File.join("#{File.dirname(__FILE__)}/../lib/**", "*.rb")).each{|f| require f}
23
+
24
+ Sidekiq.configure_server do |config|
25
+ config.redis = { path: Dialog.config.db.redis_url, db: Dialog.config.db.redisDBBackground }
26
+ config.average_scheduled_poll_interval = 5 ## DEV
27
+ end
28
+
29
+ Sidekiq.configure_client do |config|
30
+ config.redis = { path: Dialog.config.db.redis_url, db: Dialog.config.db.redisDBBackground }
31
+ end
32
+
33
+ ## DEV
34
+ rs = Sidekiq::RetrySet.new
35
+ rs.size
36
+ rs.clear
37
+ ##
38
+
39
+ Dir.glob(File.join("#{File.dirname(__FILE__)}/**", "*.rb")).each{|f| require f}
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,69 @@
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
+ module Background
15
+
16
+ class BotApi
17
+ include Sidekiq::Worker
18
+ include Sidekiq::Status::Worker
19
+ sidekiq_options queue: 'default'
20
+
21
+ def perform(instance,args)
22
+ batch = Sidekiq::Batch.new
23
+ batch.on(:success, 'Dialog::Background::Callback#success')
24
+ batch.on(:complete,'Dialog::Background::Callback#complete')
25
+
26
+ batch.jobs do
27
+ BotApiSend.perform_in(5.seconds.from_now,instance,args.to_h)
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+
34
+ class Callback
35
+ include Sidekiq::Worker
36
+ include Sidekiq::Status::Worker
37
+ sidekiq_options queue: 'default'
38
+
39
+ def success(status, options)
40
+ puts "You called a callback 'success', status: #{status}, options: #{options}"
41
+ end
42
+
43
+ def complete(status, options)
44
+ puts "You called a callback 'complete', status: #{status}, options: #{options}"
45
+ #if status.failures != 0
46
+ end
47
+ end
48
+
49
+
50
+
51
+ class BotApiSend
52
+ include Sidekiq::Worker
53
+ include Sidekiq::Status::Worker
54
+ sidekiq_options queue: 'default'
55
+
56
+ def perform(instance, mmsg)
57
+ bot = DRbObject.new_with_uri("drbunix:./_data/bot/#{instance}/drb.sock")
58
+ puts "instance: #{instance}, mmsg: #{mmsg}"
59
+ smsg = {}
60
+ pp bot.api.send(:getMe)
61
+ chatId = mmsg["fqndata"]["o"]["chat"]["id"]
62
+ pp bot.api.send(:sendMessage, {'chat_id' => chatId, 'text' => "This is the background proc, man: reply to you message from '#{DateTime.strptime(mmsg["fqndata"]["o"]["msg"]["date"].to_s, '%s')}'"})
63
+ end
64
+ end
65
+
66
+
67
+
68
+ end
69
+ end
@@ -0,0 +1,34 @@
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
+ module Background
15
+ class << self
16
+
17
+ Sidekiq::Cron::Job.create(name: 'RedisDumper - every 1 min', cron: '*/1 * * * *', class: 'Dialog::Background::RedisDumper')
18
+ pp Sidekiq::Cron::Job.all
19
+
20
+ end
21
+
22
+ class RedisDumper
23
+ include Sidekiq::Worker
24
+ include Sidekiq::Status::Worker
25
+ sidekiq_options queue: 'default'
26
+
27
+ def perform
28
+ puts Dialog::Statistics.redisDump2json
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -20,21 +20,20 @@ Gem::Specification.new do |s|
20
20
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  s.require_paths = ['lib'.freeze]
22
22
 
23
- #Innosense
24
- s.add_runtime_dependency 'dialect_lookup', '~> 0.0.4'
25
- s.add_runtime_dependency 'dialog_bot_ruby', '~> 0.8.7'
26
-
27
-
28
23
  #External
29
24
  s.add_runtime_dependency 'tdlib-ruby', '~> 1.0'
25
+ s.add_runtime_dependency 'activesupport', '~> 5.2'
30
26
  s.add_runtime_dependency 'i18n', '~> 1.1'
31
27
  s.add_runtime_dependency 'redis', '~> 4.0'
32
- s.add_runtime_dependency 'concurrent-ruby', '~> 1.0.5'
28
+ s.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
33
29
  s.add_runtime_dependency 'oj', '~> 3.6'
34
- s.add_runtime_dependency 'sidekiq-cron', '~> 1.0'
35
30
  s.add_runtime_dependency 'sidekiq', '~> 5.2'
31
+ s.add_runtime_dependency 'sidekiq-batch', '~> 0.1'
32
+ s.add_runtime_dependency 'sidekiq-status', '~> 1.1'
33
+ s.add_runtime_dependency 'sidekiq-cron', '~> 1.0'
36
34
  s.add_runtime_dependency 'sidekiq-rate-limiter', '~> 0.1'
37
35
  s.add_runtime_dependency 'dry-configurable', '~> 0.7'
36
+ s.add_runtime_dependency 'redis-dump', '~> 0.4'
38
37
 
39
38
  end
40
39
 
@@ -1,16 +1,18 @@
1
1
  daemonize no
2
- port 0
2
+ port 4000
3
3
  unixsocketperm 700
4
4
  loglevel notice
5
5
  syslog-enabled yes
6
6
  syslog-facility local1
7
- databases 2
7
+ databases 4
8
8
  save 600 1
9
9
  save 300 5
10
10
  save 180 10
11
11
  save 60 50
12
12
  save 10 100
13
13
 
14
+ maxmemory-policy noeviction
15
+
14
16
  stop-writes-on-bgsave-error yes
15
17
  rdbcompression yes
16
18
  rdbchecksum yes
@@ -15,38 +15,40 @@ set -e
15
15
  ## PRE - ENV ##
16
16
  # . ./engine/exec.sh
17
17
 
18
- if [[ -z $RunMethod ]]; then
19
- DialogMsg="Please specify run method"
20
- echo $DialogMsg; select RunMethod in console systemd; do break ; done
18
+ if [[ -z $runInstance ]]; then
19
+ DialogMsg="Please specify instance"
20
+ echo $DialogMsg; select runInstance in `ls ./_env/*|grep -v tmpl|sed -e 's/.*.\///'`; do break ; done
21
+ runMode=`echo $runInstance|cut -d '.' -f 2`
22
+ runInstance=`echo $runInstance|cut -d '.' -f 1`
21
23
  fi
22
24
 
23
- if [[ -z $BotFullname ]]; then
24
- DialogMsg="Please specify BotFullname"
25
- echo $DialogMsg; select BotFullname in `ls ./_env/*|grep -v tmpl|sed -e 's/.*.\///'`; do break ; done
25
+ if [[ -z $runScope ]]; then
26
+ DialogMsg="Please specify scope"
27
+ echo $DialogMsg; select runScope in init systemd_start console_start; do break ; done
28
+ showCommand=1
26
29
  fi
27
30
 
28
- case $RunMethod in
29
- 'sytemd')
31
+ case $runScope in
32
+ 'console_start')
33
+ runModes="bot tdlib check dialect"
30
34
  ;;
35
+ *)
36
+ runModes="bot tdlib bot_dev"
37
+ ;;
38
+ esac
31
39
 
32
- 'console')
33
-
34
- if [[ -z $runScope ]]; then
35
- DialogMsg="Please specify scope"
36
- echo $DialogMsg; select runScope in init start stop; do break ; done
37
- fi
38
-
39
- if [[ -z $runMode ]]; then
40
- DialogMsg="Please specify mode: "
41
- echo $DialogMsg; select runMode in check bot dev dev_offline; do break ; done
42
- fi
40
+ if [[ -z $runMode ]]; then
41
+ DialogMsg="Please specify mode: "
42
+ echo $DialogMsg; select runMode in $runModes; do break ; done
43
+ fi
43
44
 
44
- export $(grep -v '^#' ./_env/$BotFullname | xargs)
45
+ if [[ $showCommand == 1 ]]; then
46
+ GREEN='\033[0;32m'
47
+ NC='\033[0m' # No Color
48
+ runCommand="runInstance=$runInstance runScope=$runScope runMode=$runMode"
49
+ echo -e "Start using:\n${GREEN}$runCommand bash ./dialog.sh ${NC}"
50
+ else
51
+ export $(grep -v '^#' ./_env/$runInstance.* | xargs)
45
52
  ruby ./dialog.rb
53
+ fi
46
54
 
47
- ;;
48
-
49
- *)
50
- echo 'Wrong run method!'
51
- ;;
52
- esac
@@ -4,7 +4,7 @@ After=syslog.target network.target
4
4
 
5
5
  [Service]
6
6
  Type=oneshot
7
- WorkingDirectory={RunPath}
7
+ WorkingDirectory=<%=Dialog.config.path.dialog%>
8
8
  ExecStart=/usr/bin/git pull
9
9
  StandardOutput=syslog
10
10
  StandardError=syslog
@@ -1,2 +1,19 @@
1
+ #!/bin/bash
2
+ ######## ####### ######## ####### ######## ########
3
+ ## / / / / License \ \ \ \
4
+ ## Copyleft culture, Copyright (C) is prohibited here
5
+ ## This work is licensed under a CC BY-SA 4.0
6
+ ## Creative Commons Attribution-ShareAlike 4.0 License
7
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
8
+ ######## ####### ######## ####### ######## ########
9
+ ## / / / / Code Climate \ \ \ \
10
+ ## Language = bash
11
+ ## Indent = space; 2 chars;
12
+ ######## ####### ######## ####### ######## ########
13
+ set -e
14
+
1
15
  zypper ar -cf https://download.opensuse.org/repositories/devel:/languages:/ruby:/extensions/openSUSE_Leap_15.0/devel:languages:ruby:extensions.repo
2
- zypper --gpg-auto-import-keys --non-interactive in ruby2.5-devel ruby2.5-rubygem-sqlite3 ruby2.5-rubygem-oj redis
16
+ zypper ar -cf https://download.opensuse.org/repositories/devel:/languages:/ruby/openSUSE_Leap_15.0/devel:languages:ruby.repo
17
+ zypper --gpg-auto-import-keys --non-interactive up
18
+ zypper --gpg-auto-import-keys --non-interactive in jemalloc tdlib redis
19
+ zypper --gpg-auto-import-keys --non-interactive in ruby2.5-devel ruby2.5-rubygem-sqlite3 ruby2.5-rubygem-oj ruby2.5-rubygem-yajl-ruby
@@ -0,0 +1,29 @@
1
+ [Unit]
2
+ Description= Dialog background runner
3
+ After=syslog.target network.target
4
+
5
+ [Service]
6
+ Type=simple
7
+ WorkingDirectory=<%=Dialog.config.path.dialog%>
8
+
9
+ Environment=runScope=_run
10
+ Environment=runMode=background
11
+
12
+ # Greatly reduce Ruby memory fragmentation and heap usage
13
+ # https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
14
+ Environment=MALLOC_ARENA_MAX=2
15
+ # Use jemalloc
16
+ # https://brandonhilkert.com/blog/reducing-sidekiq-memory-usage-with-jemalloc/
17
+ Environment=LD_PRELOAD=/usr/lib64/libjemalloc.so.2
18
+
19
+ ExecStart=/usr/bin/ruby ./dialog.rb
20
+
21
+ RestartSec=5
22
+ TimeoutStopSec=5
23
+ Restart=on-failure
24
+ StandardOutput=syslog
25
+ StandardError=syslog
26
+ SyslogIdentifier=dialog_background
27
+
28
+ [Install]
29
+ WantedBy=default.target
@@ -12,4 +12,4 @@ ExecStart=/usr/sbin/redis-server ./redis_local.conf
12
12
  Restart=on-failure
13
13
 
14
14
  [Install]
15
- WantedBy=multi-user.target
15
+ WantedBy=default.target
@@ -1,3 +1,5 @@
1
+ <% erb.has_key?(:env) ? env = erb[:env] : env = erb[:mode]
2
+ %>
1
3
  [Unit]
2
4
  Description= Dialog (Telegram Bot abstraction layer) - instance %i
3
5
  After=syslog.target network.target
@@ -5,22 +7,30 @@ After=syslog.target network.target
5
7
  [Service]
6
8
  Type=simple
7
9
  WorkingDirectory=<%=Dialog.config.path.dialog%>
8
- EnvironmentFile=<%=Dialog.config.path.dialog%>/_env/%i
9
- Environment=runScope=start
10
- Environment=runMode=<%=mode%>
11
- Environment=BotFullname=%i
10
+ EnvironmentFile=<%=Dialog.config.path.dialog%>/_env/%i.<%= env %>
11
+ Environment=runScope=_run
12
+ Environment=runMode=<%=erb[:mode]%>
13
+ Environment=runInstance=%i
12
14
 
13
15
  # Greatly reduce Ruby memory fragmentation and heap usage
14
16
  # https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
15
17
  Environment=MALLOC_ARENA_MAX=2
18
+ # Use jemalloc
19
+ # https://brandonhilkert.com/blog/reducing-sidekiq-memory-usage-with-jemalloc/
20
+ Environment=LD_PRELOAD=/usr/lib64/libjemalloc.so.2
16
21
 
22
+ <% if erb.has_key?(:systemdChain)%>
23
+ ExecStartPre=/usr/bin/ruby ./dialog.rb
24
+ ExecStart=/usr/bin/systemctl --user restart <%=erb[:systemdChain]%>@%i
25
+ <% else %>
17
26
  ExecStart=/usr/bin/ruby ./dialog.rb
27
+ <% end %>
18
28
  RestartSec=5
19
29
  TimeoutStopSec=5
20
30
  Restart=on-failure
21
31
  StandardOutput=syslog
22
32
  StandardError=syslog
23
- SyslogIdentifier=dialog_<%=mode%>_%i
33
+ SyslogIdentifier=dialog_<%=erb[:mode]%>_%i
24
34
 
25
35
  [Install]
26
- WantedBy=multi-user.target
36
+ WantedBy=default.target
@@ -0,0 +1,8 @@
1
+ [Unit]
2
+ Description=<%=erb[:desc]%>
3
+
4
+ [Path]
5
+ PathChanged=<%=erb[:path]%>
6
+
7
+ [Install]
8
+ WantedBy=default.target
@@ -13,9 +13,11 @@
13
13
  module Dialog
14
14
  class << self
15
15
 
16
- def trigger_start
16
+ def _run(mode=false)
17
17
  args = {}
18
- case Dialog.config.common.mode
18
+ mode == false ? mode = Dialog.config.run.mode : true
19
+ Dialog.logger.debug "Using mode '#{mode}'"
20
+ case mode
19
21
  when 'check'
20
22
  _require
21
23
  jsonDriven(args, :check)
@@ -23,31 +25,27 @@ module Dialog
23
25
  _require
24
26
  jsonDriven(args, :prod)
25
27
  bot(args)
26
- when 'dev'
27
- _require
28
- dialectDriven(args)
29
- jsonDriven(args, :prod)
30
- bot(args)
31
- when 'dev_offline'
28
+ when 'dialect'
32
29
  _require
33
30
  dialectDriven(args)
34
31
  jsonDriven(args, :check)
35
32
  when 'tdlib'
36
33
  start_tdlib(args)
34
+ when 'background'
35
+ start_background(args)
37
36
  else
38
- Dialog.logger.error "ERROR: no such mode - '#{Dialog.config.common.mode}'"
37
+ Dialog.logger.error "ERROR: no such mode - '#{mode}'"
39
38
  end
40
39
  end
41
40
 
42
-
43
41
 
44
42
  def dialectDriven(args)
45
43
  require 'dialect_lookup'
46
44
  state = {
47
- dialectFolder: Dialog.config.dialect.folder,
45
+ dialectFolder: Dialog.config.naming.interface,
48
46
  myAppName: Dialog.config.naming.app,
49
47
  sqlite: Dialog.config.dialect.sqlite,
50
- jsonFolder: "#{Dialog.config.path.dialogRender}/json/"
48
+ json: Dialog.config.dialect.json
51
49
  }
52
50
  ::Dialect::Lookup.new.run(state)
53
51
  # File.delete(Dialog.config.dialect.sqlite)
@@ -58,15 +56,25 @@ module Dialog
58
56
  FileUtils.rm_rf(Dir.glob("#{Dialog.config.path.dialogRender}/code_#{type}/*.rb"))
59
57
  args[:dialect] = {}
60
58
 
61
- json = "#{Dialog.config.path.dialogRender}/json/#{Dialog.config.dialect.folder}_#{Dialog.config.naming.app}.json"
62
- jsonLoad = Oj.load(File.read(json), symbol_keys: true)
63
- args[:dialect] = jsonLoad[:stages][Dialog.config.dialect.folder.to_sym]
64
- Dialog::Dialect.run(args, type)
65
-
66
- args[:dialect] ={}
67
- args[:tmp] = {}
68
- Dir.glob(File.join("#{Dialog.config.path.dialogRender}/code_#{type}/**", "*.rb")).sort.each{|f| require f}
69
- Dialog.logger.info "Rendered bot code is ok"
59
+ json = Dialog.config.dialect.json
60
+ if File.file?(json)
61
+ jsonLoad = Oj.load(File.read(json), symbol_keys: true)
62
+ args[:dialect] = jsonLoad[:stages][Dialog.config.naming.interface.to_sym]
63
+ Dialog::Dialect.run(args, type)
64
+
65
+ args[:dialect] ={}
66
+ args[:tmp] = {}
67
+ Dir.glob(File.join("#{Dialog.config.path.dialogRender}/code_#{type}/**", "*.rb")).sort.each{|f| require f}
68
+ Dialog.logger.info "Rendered bot code is ok"
69
+ else
70
+ Dialog.logger.info "No JSON to render, trying to export"
71
+ begin
72
+ trigger_start('dialect')
73
+ rescue
74
+ Dialog.logger.error "Seems like no Dialect DB, exiting! Please upload valid JSON or use a valid Dialect DB"
75
+ exit(false)
76
+ end
77
+ end
70
78
  end
71
79
 
72
80