dialog_ruby 0.1.7 → 0.1.8

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: f30155becff2a9f39d3d1c827c6c63d31ded0b9197884501f224cce0cf20fa42
4
- data.tar.gz: '095776832dcc0af93bf076f7e4dfa79da9551e2ae20c428b58da63bfc3cbd8c4'
3
+ metadata.gz: 50b52161687990f23ad7cff84999068743836e72ac832d43071b46c19b724518
4
+ data.tar.gz: 2c4085bbe8b9b1cc4303a3013090e8be6bae7a54d2f8ff724b85bde4531ad23c
5
5
  SHA512:
6
- metadata.gz: 5ed7b3240d5ec6c6deba9b3cda0e155bace016fcbcd317b0723179ccdfceceba8c67f007aeef6031a39b1b30bd9d3ccfbbdd0951978e8ebbc9b2b452179512bb
7
- data.tar.gz: 60c766700b3f958441ad542e8430ec7f4feffc7fa3139730f98acc591a39b2449d10f924252e55e9f8ae15471ecccc005e15e62a54a4fbc39e1479d9e78daff2
6
+ metadata.gz: 684b298d0a10b2f839ae392b5ced57a2947c64797c7597f7c38dca8477b86e297cc40dc2b2f466700b615cc542f3173eae1b5bc6637e745a61bb2774d07377bb
7
+ data.tar.gz: 0b5fdb43a58eaba5995fdcb7946043b1577602da46b438671926dd9287bb472204b4d5556a1aa434609d3663abaca4994bb65229341ef42a5d921cef9600102d
@@ -0,0 +1,49 @@
1
+ daemonize no
2
+ port 0
3
+ unixsocketperm 700
4
+ loglevel notice
5
+ syslog-enabled yes
6
+ syslog-facility local1
7
+ databases 2
8
+ save 600 1
9
+ save 300 5
10
+ save 180 10
11
+ save 60 50
12
+ save 10 100
13
+
14
+ stop-writes-on-bgsave-error yes
15
+ rdbcompression yes
16
+ rdbchecksum yes
17
+ dbfilename dump.rdb
18
+ appendonly no
19
+ appendfsync everysec
20
+ no-appendfsync-on-rewrite no
21
+ maxclients 1000
22
+
23
+ auto-aof-rewrite-percentage 100
24
+ auto-aof-rewrite-min-size 64mb
25
+ aof-rewrite-incremental-fsync yes
26
+
27
+
28
+ aof-load-truncated yes
29
+ lua-time-limit 5000
30
+ slowlog-log-slower-than 10000
31
+ slowlog-max-len 128
32
+ latency-monitor-threshold 0
33
+ notify-keyspace-events ""
34
+
35
+ hash-max-ziplist-entries 512
36
+ hash-max-ziplist-value 64
37
+ list-max-ziplist-entries 512
38
+ list-max-ziplist-value 64
39
+ set-max-intset-entries 512
40
+
41
+ zset-max-ziplist-entries 128
42
+ zset-max-ziplist-value 64
43
+ hll-sparse-max-bytes 3000
44
+ activerehashing yes
45
+ client-output-buffer-limit normal 0 0 0
46
+ client-output-buffer-limit slave 256mb 64mb 60
47
+ client-output-buffer-limit pubsub 32mb 8mb 60
48
+
49
+ hz 10
@@ -0,0 +1,4 @@
1
+ include 'redis_global.conf'
2
+ unixsocket 'redis.sock'
3
+ syslog-ident dialog_redis
4
+ dir './'
@@ -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 = bash
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ set -e
13
+
14
+
15
+ #####
16
+ DialogBotExec() (
17
+ systemctl --user restart dialog_redis@${BotFullname}
18
+ systemctl --user restart dialog_bot@${BotFullname}
19
+
20
+ case $Mode in
21
+ 'prod')
22
+ echo "Ready!"
23
+ systemctl --user enable dialog_redis@${BotFullname}
24
+ systemctl --user enable dialog_bot@${BotFullname}
25
+ ;;
26
+ 'dev')
27
+ mkdir -p /tmp/_render
28
+
29
+ inotifywait -r -e DELETE --format '%w %f' -m ./engine |\
30
+ (
31
+ while read; do
32
+ echo "Bot restarting"
33
+ systemctl --user restart dialog_bot@${BotFullname}
34
+ done
35
+ )
36
+
37
+ systemctl --user stop dialog_bot@${BotFullname}
38
+ systemctl --user stop dialog_redis@${BotFullname}
39
+ ;;
40
+ esac
41
+ )
42
+ #####
@@ -0,0 +1,5 @@
1
+ # See tmpfiles.d(5) for details
2
+ d /tmp/in4/dialog 0770 in4 in4 2d
3
+ d /tmp/in4/dialog/render 0770 in4 in4 1d
4
+
5
+
data/exec/dialog.sh ADDED
@@ -0,0 +1,52 @@
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
+
15
+ ## PRE - ENV ##
16
+ # . ./engine/exec.sh
17
+
18
+ if [[ -z $RunMethod ]]; then
19
+ DialogMsg="Please specify run method"
20
+ echo $DialogMsg; select RunMethod in console systemd; do break ; done
21
+ fi
22
+
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
26
+ fi
27
+
28
+ case $RunMethod in
29
+ 'sytemd')
30
+ ;;
31
+
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
43
+
44
+ export $(grep -v '^#' ./_env/$BotFullname | xargs)
45
+ ruby ./dialog.rb
46
+
47
+ ;;
48
+
49
+ *)
50
+ echo 'Wrong run method!'
51
+ ;;
52
+ esac
@@ -0,0 +1,14 @@
1
+ [Unit]
2
+ Description= Dialog sync
3
+ After=syslog.target network.target
4
+
5
+ [Service]
6
+ Type=oneshot
7
+ WorkingDirectory={RunPath}
8
+ ExecStart=/usr/bin/git pull
9
+ StandardOutput=syslog
10
+ StandardError=syslog
11
+ SyslogIdentifier=dialog_sync
12
+
13
+ [Install]
14
+ WantedBy=multi-user.target
@@ -0,0 +1,11 @@
1
+ [Unit]
2
+ Description=Timer for dialog__sync
3
+ After=syslog.target network.target
4
+ [Install]
5
+ WantedBy=multi-user.target
6
+
7
+ [Timer]
8
+ OnBootSec=2min
9
+ OnUnitActiveSec=1min
10
+ Unit=dialog__sync.service
11
+
@@ -0,0 +1,5 @@
1
+ cd ./_env
2
+
3
+ find . -mindepth 1 -not -path './_tmpl.bot' -print0 | while IFS= read -r -d $'\0' line; do
4
+ systemctl --user restart dialog_bot_pre@`echo $line|sed 's/^.\///'`.service
5
+ done
@@ -0,0 +1,31 @@
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
+ )
@@ -0,0 +1,6 @@
1
+ [Unit]
2
+ Description=Monitor /tmp/ready
3
+
4
+ [Path]
5
+ Unit=dialog_bot_pre@%i.service
6
+ PathChanged=/tmp/ready_%i
@@ -0,0 +1,26 @@
1
+ [Unit]
2
+ Description= Dialog (Telegram Bot abstraction layer) - instance %i
3
+ After=syslog.target network.target
4
+
5
+ [Service]
6
+ Type=simple
7
+ WorkingDirectory=<%=Dialog.config.path.dialog%>
8
+ EnvironmentFile=<%=Dialog.config.path.dialog%>/_env/%i
9
+ Environment=runScope=start
10
+ Environment=runMode=bot
11
+ Environment=BotFullname=%i
12
+
13
+ # Greatly reduce Ruby memory fragmentation and heap usage
14
+ # https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
15
+ Environment=MALLOC_ARENA_MAX=2
16
+
17
+ ExecStart=/usr/bin/ruby ./dialog.rb
18
+ RestartSec=5
19
+ TimeoutStopSec=5
20
+ Restart=on-failure
21
+ StandardOutput=syslog
22
+ StandardError=syslog
23
+ SyslogIdentifier=dialog_%i
24
+
25
+ [Install]
26
+ WantedBy=multi-user.target
@@ -0,0 +1,6 @@
1
+ [Unit]
2
+ Description=Monitor sqlite export
3
+
4
+ [Path]
5
+ Unit=dialog_bot_dev_pre@%i.service
6
+ PathChanged={RunPath}/_data/Dialect.sqlite
@@ -0,0 +1,16 @@
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 dev_offline %i
10
+ ExecStart=/usr/bin/systemctl --user restart dialog_bot@%i
11
+ StandardOutput=syslog
12
+ StandardError=syslog
13
+ SyslogIdentifier=dialog_dev_pre_%i
14
+
15
+ [Install]
16
+ WantedBy=multi-user.target
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,15 @@
1
+ [Unit]
2
+ Description=Redis
3
+ After=network.target
4
+ PartOf=redis.target
5
+
6
+ [Service]
7
+ Type=simple
8
+ #PrivateTmp=true
9
+ WorkingDirectory=<%=Dialog.config.path.dialogData%>/redis
10
+ PIDFile=<%=Dialog.config.path.dialogData%>/redis/redis.pid
11
+ ExecStart=/usr/sbin/redis-server ./redis_local.conf
12
+ Restart=on-failure
13
+
14
+ [Install]
15
+ WantedBy=multi-user.target
data/lib/configuration.rb CHANGED
@@ -13,6 +13,10 @@
13
13
  module Dialog
14
14
  extend Dry::Configurable
15
15
 
16
+ require_relative './tooling/log.rb'
17
+ def self.getDialogPath; return @dialogPath; end
18
+ def self.getDialog_rubyPath; return File.dirname(__FILE__); end
19
+
16
20
  def self.checkEnv(env, val, err=[])
17
21
  if ENV[env].nil?
18
22
  case val
@@ -21,33 +25,30 @@ module Dialog
21
25
  else res = val
22
26
  end
23
27
  else res = ENV[env]; end
28
+ puts err
24
29
  return res
25
30
  end
26
31
 
27
-
28
32
  err = []
29
- app = 'Dialog'
30
- ARGV[0] ? scope = ARGV[0] : err << "There is no scope as ARGV[0]" && scope = false
31
- ARGV[1] ? mode = ARGV[1] : err << "There is no mode as ARGV[1]" && mode = false
33
+ app = 'Dialog'
32
34
 
33
35
  setting :api do
34
- setting :id, Dialog.checkEnv('ApiID', false, err)
36
+ setting :id, Dialog.checkEnv('ApiID', false, err)
35
37
  setting :hash_s, Dialog.checkEnv('ApiHash', false, err)
36
38
  end
37
39
 
38
40
  setting :run do
39
- setting :scope, scope
40
- setting :mode, mode
41
+ setting :scope, Dialog.checkEnv('runScope', false, err)
42
+ setting :mode, Dialog.checkEnv('runMode', false, err)
41
43
  end
42
44
 
43
45
  setting :naming do
44
46
  setting :app, app
45
47
  end
46
48
 
47
- unless scope == 'init'
48
- ARGV[2] ? namingFull = ARGV[2] : err << "There is no naming as ARGV[2]"
49
-
50
- token = Dialog.checkEnv('BotToken', false, err)
49
+ unless Dialog.checkEnv('runScope', false, err) == 'init'
50
+ namingFull = Dialog.checkEnv('BotFullname', false, err)
51
+ token = Dialog.checkEnv('BotToken', false, err)
51
52
 
52
53
  setting :naming do
53
54
  setting :app, app
@@ -58,7 +59,7 @@ module Dialog
58
59
  else
59
60
  err << "Error in naming!"
60
61
  end
61
- setting :id, token.split(':')[0].to_i
62
+ setting :id, token.split(':')[0].to_i unless token == false
62
63
  end
63
64
 
64
65
  setting :dialect do
@@ -67,7 +68,7 @@ module Dialog
67
68
  end
68
69
 
69
70
  setting :db do
70
- setting :redis_url, "./_data/#{namingFull}/redis.sock"
71
+ setting :redis_url, "./_data/redis/redis.sock"
71
72
  end
72
73
 
73
74
  setting :secure do
@@ -84,13 +85,15 @@ module Dialog
84
85
  end
85
86
 
86
87
  setting :path do
87
- setting :run, "#{Dir.pwd}/engine"
88
- setting :data, "#{Dir.pwd}/_data"
89
- setting :render,"#{Dir.pwd}/_render"
88
+ setting :dialog_ruby, "#{Dialog.getDialog_rubyPath}/../"
89
+ setting :dialog_rubyLib,"#{Dialog.getDialog_rubyPath}"
90
+ setting :dialog, "#{Dialog.getDialogPath}"
91
+ setting :dialogData, "#{Dialog.getDialogPath}/_data"
92
+ setting :dialogRender, "#{Dialog.getDialogPath}/_render"
90
93
  end
91
94
 
92
95
  setting :common do
93
- setting :mode, mode
96
+ setting :mode, Dialog.checkEnv('runMode', false, err)
94
97
  end
95
98
 
96
99
  setting :log do
@@ -109,6 +112,11 @@ module Dialog
109
112
  setting :web_hook_url, "https://#{botInstanceHostName}/telegram/api/web_hook"
110
113
  end
111
114
 
115
+ if Dialog.checkEnv('runScope', false, err) == false and Dialog.checkEnv('runMode', false, err) == false
116
+ FileUtils.cp "#{Dialog.getDialog_rubyPath}/../exec/dialog.sh", "#{Dialog.getDialogPath}/" if not File.file?("#{Dialog.getDialogPath}/dialog.sh")
117
+ Dialog.logger.info "dialog.sh is copied to your dialog folder, please use it for correct ENV exports!"
118
+ end
119
+
112
120
  unless err.empty?
113
121
  err << "EXITING!"
114
122
  puts err
@@ -42,7 +42,7 @@ module Dialog
42
42
 
43
43
 
44
44
  def makeAErb(args, type, stage)
45
- FileUtils.mkdir_p("#{Dialog.config.path.render}/code_#{type}/")
45
+ FileUtils.mkdir_p("#{Dialog.config.path.dialogRender}/code_#{type}/")
46
46
 
47
47
  args[:tmp][:stages][stage].each do |runProps|
48
48
  nameSym = runProps[:name].to_sym
@@ -54,9 +54,9 @@ module Dialog
54
54
  fullName = "#{runProps[:order]}_#{runProps[:name]}_#{viewId}"
55
55
  fullNameSym = fullName.to_sym
56
56
 
57
- tmpl = ERB.new(File.read("#{Dialog.config.path.run}/lib/dialect/codegen/erb/#{stage}/#{runProps[:order]}.#{runProps[:name]}.erb")).result(binding)
57
+ tmpl = ERB.new(File.read("#{File.dirname(__FILE__)}/erb/#{stage}/#{runProps[:order]}.#{runProps[:name]}.erb")).result(binding)
58
58
  runProps.has_key?(:erb_order) ? rname = "#{runProps[:erb_order]}_#{fullName}" : rname = fullName
59
- File.open("#{Dialog.config.path.render}/code_#{type}/#{stage}__#{rname}.rb", 'w') do |f| f.write tmpl; end
59
+ File.open("#{Dialog.config.path.dialogRender}/code_#{type}/#{stage}__#{rname}.rb", 'w') do |f| f.write tmpl; end
60
60
  end
61
61
  end
62
62
  end
data/lib/dialog_ruby.rb CHANGED
@@ -10,41 +10,20 @@
10
10
  ## Indent = space; 2 chars;
11
11
  ######## ####### ######## ####### ######## ########
12
12
 
13
- ### SYSTEM
14
- require 'pp'
15
- require 'timeout'
16
- require 'logger'
17
- require 'socket'
18
- require 'fileutils'
19
- require 'uri'
20
- require 'open3'
21
- require 'erb'
22
-
23
- ### GEMS
24
- require 'dialect_lookup'
25
- require 'tdlib-ruby'
26
- require 'telegram/bot'
27
- require 'i18n'
28
- require 'redis'
29
- require 'concurrent'
30
- require 'oj'
31
- require 'sidekiq-cron'
32
- require 'sidekiq-rate-limiter'
33
- #lazy_object
34
-
35
- ### DRY
36
- require 'dry-configurable'
37
- # require 'dry-monads'
38
- # require 'dry-matcher'
39
- # require 'dry-transaction'
40
- # require 'dry/inflector'
41
- # require 'dry-validation'
42
- # require 'dry-struct'
43
- # require 'dry-types'
44
-
45
- #dry-events - pub/sub
46
-
47
- ### CODE
48
- require_relative './configuration.rb'
49
- require_relative './dialogStart.rb'
50
- Dir.glob(File.join("#{Dialog.config.path.run}/**", "*.rb")).each{|f| require f}
13
+ module Dialog
14
+ class << self
15
+
16
+ def create
17
+ version = RUBY_VERSION.split('.').map { |x| x.to_i }
18
+ if (version <=> [2, 5, 0]) >= 1
19
+ require_relative './require.rb'
20
+ _require
21
+ send("trigger_#{Dialog.config.run.scope}".to_sym)
22
+ else
23
+ puts "Minimum required Ruby version - 2.5.0"
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+
data/lib/require.rb ADDED
@@ -0,0 +1,58 @@
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 _require
17
+ ### SYSTEM
18
+ require 'pp'
19
+ require 'timeout'
20
+ require 'logger'
21
+ require 'socket'
22
+ require 'fileutils'
23
+ require 'uri'
24
+ require 'open3'
25
+ require 'erb'
26
+ require 'shellwords'
27
+
28
+ ### GEMS
29
+ require 'dialect_lookup'
30
+ require 'tdlib-ruby'
31
+ require 'telegram/bot'
32
+ require 'i18n'
33
+ require 'redis'
34
+ require 'concurrent'
35
+ require 'oj'
36
+ require 'sidekiq-cron'
37
+ require 'sidekiq-rate-limiter'
38
+ #lazy_object
39
+
40
+ ### DRY
41
+ require 'dry-configurable'
42
+ # require 'dry-monads'
43
+ # require 'dry-matcher'
44
+ # require 'dry-transaction'
45
+ # require 'dry/inflector'
46
+ # require 'dry-validation'
47
+ # require 'dry-struct'
48
+ # require 'dry-types'
49
+
50
+ #dry-events - pub/sub
51
+
52
+ ### CODE
53
+ Dir.glob(File.join("#{File.dirname(__FILE__)}/**", "*.rb")).each{|f| require f}
54
+ end
55
+
56
+ end
57
+ end
58
+
data/lib/tooling/lang.rb CHANGED
@@ -14,7 +14,8 @@ module Dialog
14
14
  class << self
15
15
 
16
16
  def initial
17
- I18n.load_path = Dir["#{Dialog.config.path.run}/lang/*.yml"]
17
+ I18n.load_path = Dir["#{Dialog.config.path.dialog_ruby}/lang/*.yml"]
18
+ I18n.available_locales = [:en, :ru]
18
19
  I18n.default_locale = :ru
19
20
  I18n.backend.load_translations
20
21
  end
@@ -0,0 +1,21 @@
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 trigger_full
17
+
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,58 @@
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 trigger_deploy
17
+ deploy_redis
18
+ deploy_bot
19
+ end
20
+
21
+ def erb(erbFile, dst)
22
+ if not File.file?(dst)
23
+ tmpl = ERB.new(File.read("#{Dialog.config.path.dialog_ruby}/exec/#{erbFile}")).result(binding)
24
+ File.open(dst, 'w') do |f| f.write tmpl; end
25
+ end
26
+ end
27
+
28
+ 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')
35
+ end
36
+
37
+
38
+ def deploy_bot
39
+ erb('systemd/dialog_bot@.service', "#{Dir.home}/.config/systemd/user/dialog_bot@.service")
40
+ systemd("dialog_bot@#{Dialog.config.naming.full}")
41
+ end
42
+
43
+ def deploy_tdlib
44
+ end
45
+
46
+ def deploy_devenv
47
+ end
48
+
49
+ def deploy_gitsync
50
+ end
51
+
52
+ def systemd(service)
53
+ Open3.popen3('/usr/bin/systemctl', '--user', 'daemon-reload')
54
+ Open3.popen3('/usr/bin/systemctl', '--user', 'restart', service)
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,21 @@
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 trigger_false
17
+ Dialog.logger.error "Something wrong in runtime scenario"
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,27 @@
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 trigger_init
17
+ Dialog.tdlibAuth
18
+ end
19
+
20
+ def tdlibAuth
21
+ sess = Dialog::TDLib.tdlibInit(Dialog.config.run.mode)
22
+ Dialog::TDLib.tdlibAuth(Dialog.config.run.mode, sess)
23
+ end
24
+
25
+
26
+ end
27
+ end
@@ -0,0 +1,68 @@
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 trigger_start
17
+ args = {}
18
+ case Dialog.config.common.mode
19
+ when 'check'
20
+ jsonDriven(args, :check)
21
+ when 'bot'
22
+ jsonDriven(args, :prod)
23
+ bot(args)
24
+ when 'dev'
25
+ dialectDriven(args)
26
+ jsonDriven(args, :prod)
27
+ bot(args)
28
+ when 'dev_offline'
29
+ dialectDriven(args)
30
+ jsonDriven(args, :check)
31
+ else
32
+ Dialog.logger.error "ERROR: no such mode - '#{Dialog.config.common.mode}'"
33
+ end
34
+ end
35
+
36
+
37
+
38
+ def dialectDriven(args)
39
+ require 'dialect_lookup'
40
+ state = {
41
+ dialectFolder: Dialog.config.dialect.folder,
42
+ myAppName: Dialog.config.naming.app,
43
+ sqlite: Dialog.config.dialect.sqlite,
44
+ jsonFolder: "#{Dialog.config.path.dialogRender}/json/"
45
+ }
46
+ ::Dialect::Lookup.new.run(state)
47
+ # File.delete(Dialog.config.dialect.sqlite)
48
+ end
49
+
50
+
51
+ def jsonDriven(args, type)
52
+ FileUtils.rm_rf(Dir.glob("#{Dialog.config.path.dialogRender}/code_#{type}/*.rb"))
53
+ args[:dialect] = {}
54
+
55
+ json = "#{Dialog.config.path.dialogRender}/json/#{Dialog.config.dialect.folder}_#{Dialog.config.naming.app}.json"
56
+ jsonLoad = Oj.load(File.read(json), symbol_keys: true)
57
+ args[:dialect] = jsonLoad[:stages][Dialog.config.dialect.folder.to_sym]
58
+ Dialog::Dialect.run(args, type)
59
+
60
+ args[:dialect] ={}
61
+ args[:tmp] = {}
62
+ Dir.glob(File.join("#{Dialog.config.path.dialogRender}/code_#{type}/**", "*.rb")).sort.each{|f| require f}
63
+ Dialog.logger.info "Rendered bot code is ok"
64
+ end
65
+
66
+
67
+ end
68
+ end
@@ -11,73 +11,7 @@
11
11
  ######## ####### ######## ####### ######## ########
12
12
 
13
13
  module Dialog
14
- class << self
15
-
16
- def redis
17
- @redis ||= Redis.new(path: Dialog.config.db.redis_url)
18
- end
19
-
20
- def clear(args)
21
- args[:x] = {metamess: {}, redis: {}, data: {}, labels: {}, send: {}, exec: {}}
22
- args[:smsg] = {}
23
- end
24
-
25
- def clearRedis(args)
26
- args[:x][:redis] = {}
27
- end
28
-
29
- def clearApi(args)
30
- args[:api] = {}
31
- end
32
-
33
- def start
34
- args = {}
35
- case Dialog.config.common.mode
36
- when 'check'
37
- jsonDriven(args, :check)
38
- when 'bot'
39
- jsonDriven(args, :prod)
40
- bot(args)
41
- when 'dev'
42
- dialectDriven(args)
43
- jsonDriven(args, :prod)
44
- bot(args)
45
- when 'dev_offline'
46
- dialectDriven(args)
47
- jsonDriven(args, :check)
48
- else
49
- Dialog.logger.error "ERROR: no such mode - '#{Dialog.config.common.mode}'"
50
- end
51
- end
52
-
53
-
54
- def dialectDriven(args)
55
- state = {
56
- dialectFolder: Dialog.config.dialect.folder,
57
- myAppName: Dialog.config.naming.app,
58
- sqlite: Dialog.config.dialect.sqlite,
59
- jsonFolder: "#{Dialog.config.path.render}/json/"
60
- }
61
- ::Dialect::Lookup.new.run(state)
62
- File.delete(Dialog.config.dialect.sqlite)
63
- end
64
-
65
-
66
- def jsonDriven(args, type)
67
- FileUtils.rm_rf(Dir.glob("#{Dialog.config.path.render}/code_#{type}/*.rb"))
68
- args[:dialect] = {}
69
-
70
- json = "#{Dialog.config.path.render}/json/#{Dialog.config.dialect.folder}_#{Dialog.config.naming.app}.json"
71
- jsonLoad = Oj.load(File.read(json), symbol_keys: true)
72
- args[:dialect] = jsonLoad[:stages][Dialog.config.dialect.folder.to_sym]
73
- Dialog::Dialect.run(args, type)
74
-
75
- args[:dialect] ={}
76
- args[:tmp] = {}
77
- Dir.glob(File.join("#{Dialog.config.path.render}/code_#{type}/**", "*.rb")).sort.each{|f| require f}
78
- Dialog.logger.info "Rendered bot code is ok"
79
- end
80
-
14
+ class << self
81
15
 
82
16
  def tdlibInit(args)
83
17
  inits = ['cli']
@@ -93,25 +27,25 @@ module Dialog
93
27
  end
94
28
 
95
29
 
96
-
97
- def tdlibAuth
98
- sess = Dialog::TDLib.tdlibInit(Dialog.config.run.mode)
99
- Dialog::TDLib.tdlibAuth(Dialog.config.run.mode, sess)
100
- end
101
-
102
-
103
30
  def bot(args)
104
31
  args[:globals] = {}
105
32
 
106
33
  ### LANG
107
34
  i18n = Dialog::Lang.initial
108
35
 
109
- tdlibInit(args)
110
- args[:tdlib][:cli].on_ready do |client|
111
- a = client.fetch('@type' => 'getMe')
112
- args[:globals][:cliId] = a['id'].to_i
113
- end
114
-
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
42
+ begin
43
+ Dialog::redis.call(['info', 'clients'])
44
+ rescue
45
+ Dialog.logger.error "No Redis connection!"
46
+ sleep(2)
47
+ retry
48
+ end
115
49
  Telegram::Bot::Client.run Dialog.config.secure.token do |bot|
116
50
  args[:bot]= bot; args[:bot].freeze
117
51
 
@@ -177,13 +111,7 @@ module Dialog
177
111
  raise
178
112
  end
179
113
  end
180
-
181
- def perf(perf)
182
- a = []
183
- a << "mmsg: #{perf[:metamess] - perf[:init]}s" if perf.has_key?(:metamess)
184
- a << "preApiAction: #{perf[:preApiAction] - perf[:init]}s" if perf.has_key?(:preApiAction)
185
- a << "full: #{perf[:fullend] - perf[:init]}s"
186
- end
114
+
187
115
 
188
116
  end
189
117
  end
@@ -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
+ class << self
15
+
16
+
17
+ def redis
18
+ @redis ||= Redis.new(path: Dialog.config.db.redis_url)
19
+ end
20
+
21
+ def clear(args)
22
+ args[:x] = {metamess: {}, redis: {}, data: {}, labels: {}, send: {}, exec: {}}
23
+ args[:smsg] = {}
24
+ end
25
+
26
+ def clearRedis(args)
27
+ args[:x][:redis] = {}
28
+ end
29
+
30
+ def clearApi(args)
31
+ args[:api] = {}
32
+ end
33
+
34
+
35
+ def perf(perf)
36
+ a = []
37
+ a << "mmsg: #{perf[:metamess] - perf[:init]}s" if perf.has_key?(:metamess)
38
+ a << "preApiAction: #{perf[:preApiAction] - perf[:init]}s" if perf.has_key?(:preApiAction)
39
+ a << "full: #{perf[:fullend] - perf[:init]}s"
40
+ end
41
+
42
+ end
43
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,15 @@
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
+
1
13
  module Dialog
2
- VERSION = '0.1.7'.freeze
14
+ VERSION = '0.1.8'.freeze
3
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.7
4
+ version: 0.1.8
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-21 00:00:00.000000000 Z
11
+ date: 2018-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dialect_lookup
@@ -181,6 +181,21 @@ files:
181
181
  - _dev/sidekiq.rb
182
182
  - _dev/tdlib.rb
183
183
  - dialog_ruby.gemspec
184
+ - exec/conf/redis_global.conf
185
+ - exec/conf/redis_local.conf
186
+ - exec/dev/run_dev.sh
187
+ - exec/dev/tmpfiles.conf
188
+ - exec/dialog.sh
189
+ - exec/git_sync/dialog__sync.service
190
+ - exec/git_sync/dialog__sync.timer
191
+ - 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
198
+ - exec/systemd/dialog_redis.service
184
199
  - lang/global_ru.yml
185
200
  - lib/configuration.rb
186
201
  - lib/dialect/canvas/canvas.rb
@@ -225,7 +240,6 @@ files:
225
240
  - lib/dialect/codegen/repack/functional/5.2.Element2ModSend.rb
226
241
  - lib/dialect/codegen/repack/functional/7.ElementChains.rb
227
242
  - lib/dialect/codegen/run.rb
228
- - lib/dialogStart.rb
229
243
  - lib/dialog_ruby.rb
230
244
  - lib/metamess/_run.rb
231
245
  - lib/metamess/content/content_o-command_f.rb
@@ -244,6 +258,7 @@ files:
244
258
  - lib/metamess/service/service_o-inline_f.rb
245
259
  - lib/metamess/service/service_o.rb
246
260
  - lib/naming.rb
261
+ - lib/require.rb
247
262
  - lib/storage/redis/redisPubSub.rb
248
263
  - lib/storage/redis/rediscached.rb
249
264
  - lib/tdlib/auth.rb
@@ -255,6 +270,13 @@ files:
255
270
  - lib/tooling/lang.rb
256
271
  - lib/tooling/log.rb
257
272
  - lib/tooling/ruby.rb
273
+ - lib/triggers/_meta/full.rb
274
+ - lib/triggers/deploy/deploy.rb
275
+ - lib/triggers/false.rb
276
+ - lib/triggers/init.rb
277
+ - lib/triggers/start/start.rb
278
+ - lib/triggers/start/start_bot.rb
279
+ - lib/triggers/start/start_pre.rb
258
280
  - lib/version.rb
259
281
  - logo.png
260
282
  homepage: https://gitlab.com/Innosense/MVP/dialog_ruby
@@ -277,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
299
  version: '0'
278
300
  requirements: []
279
301
  rubyforge_project:
280
- rubygems_version: 2.7.3
302
+ rubygems_version: 2.7.6
281
303
  signing_key:
282
304
  specification_version: 4
283
305
  summary: Communication prototyping platform