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.
- checksums.yaml +4 -4
- data/Dockerfile +13 -0
- data/{lib/storage/redis → _dev}/redisPubSub.rb +1 -1
- data/background/_init.rb +43 -0
- data/background/batch.rb +69 -0
- data/background/redis.rb +34 -0
- data/dialog_ruby.gemspec +6 -7
- data/exec/conf/redis_global.conf +4 -2
- data/exec/dialog.sh +28 -26
- data/exec/git_sync/dialog__sync.service +1 -1
- data/exec/prereq.sh +18 -1
- data/exec/systemd/dialog_background.service +29 -0
- data/exec/systemd/dialog_redis.service +1 -1
- data/exec/systemd/dialog_runMode@.service +16 -6
- data/exec/systemd/dialog_runner@.path +8 -0
- data/lib/{triggers/start → begin}/_main.rb +29 -21
- data/lib/begin/_pre_bot.rb +58 -0
- data/lib/begin/background.rb +24 -0
- data/lib/{triggers/start → begin}/bot.rb +27 -6
- data/lib/{triggers/start → begin}/tdlib.rb +12 -16
- data/lib/configuration.rb +39 -27
- data/lib/dialect/canvas/element/send/Inline_query_result.rb +2 -0
- data/lib/dialect/canvas/element/send/background.rb +28 -0
- data/lib/dialect/canvas/element/send/recognize.rb +3 -2
- data/lib/dialect/canvas/element/send/restrict.rb +0 -1
- data/lib/dialect/canvas/element/send/tdlib_chat.rb +1 -1
- data/lib/dialect/canvas/element/send/tdlib_message.rb +1 -1
- data/lib/dialect/codegen/codegen.rb +9 -9
- data/lib/dialect/codegen/erb/functional/2.2.1.Events2ModReceive.erb +27 -4
- data/lib/dialect/codegen/erb/functional/4.1.AppEvent2Elements.erb +7 -2
- data/lib/dialect/codegen/erb/functional/5.1.Element2ModElements.erb +1 -1
- data/lib/dialect/codegen/erb/functional/7.ElementChains.erb +7 -6
- data/lib/dialog_ruby.rb +5 -2
- data/lib/metamess/_run.rb +1 -0
- data/lib/metamess/content/content_o-contact_f.rb +41 -0
- data/lib/metamess/content/content_o.rb +7 -6
- data/lib/metamess/func.rb +0 -24
- data/lib/metamess/naming.rb +8 -5
- data/lib/metamess/service/service_o-inline_f.rb +4 -3
- data/lib/require.rb +21 -2
- data/lib/statistics/func.rb +72 -0
- data/lib/statistics/general.rb +44 -0
- data/lib/statistics/redisDump.rb +49 -0
- data/lib/storage/redis/cached/pullpush.rb +76 -0
- data/lib/storage/redis/cached/pushPreproc.rb +41 -0
- data/lib/storage/redis/func.rb +47 -0
- data/lib/storage/redis/stat/push.rb +33 -0
- data/lib/tdlib/auth.rb +8 -7
- data/lib/tdlib/init.rb +5 -5
- data/lib/telegram/botapi.rb +2 -1
- data/lib/telegram/wrappers.rb +1 -2
- data/lib/tooling/log.rb +0 -1
- data/lib/tooling/strings.rb +12 -0
- data/lib/triggers/_func.rb +39 -0
- data/lib/triggers/{_meta/full.rb → console_start.rb} +8 -5
- data/lib/triggers/deploy.rb +104 -0
- data/lib/triggers/false.rb +8 -6
- data/lib/triggers/init.rb +23 -10
- data/lib/triggers/systemd_start.rb +24 -0
- data/lib/version.rb +1 -1
- metadata +83 -41
- data/_dev/sidekiq.rb +0 -28
- data/exec/systemd/_fix/dialog_bot@.path +0 -6
- data/exec/systemd/_fix/dialog_bot_dev@.path +0 -6
- data/exec/systemd/_fix/dialog_bot_dev_pre@.service +0 -16
- data/lib/storage/redis/rediscached.rb +0 -97
- data/lib/triggers/deploy/deploy.rb +0 -78
- data/lib/triggers/start/_pre_bot.rb +0 -43
@@ -1,97 +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 = ruby
|
10
|
-
## Indent = space; 2 chars;
|
11
|
-
######## ####### ######## ####### ######## ########
|
12
|
-
|
13
|
-
module Dialog
|
14
|
-
module RedisCached
|
15
|
-
class << self
|
16
|
-
|
17
|
-
def areaDescr(args)
|
18
|
-
case args[:x][:redis][:region]
|
19
|
-
when 'chat'
|
20
|
-
args[:x][:redis][:area] = args[:mmsg][:fqndata][:o][:chat][:id]
|
21
|
-
args[:pushCache] = true if args[:x][:redis][:territory] == 'context'
|
22
|
-
when 'user'
|
23
|
-
args[:x][:redis][:area] = args[:mmsg][:user_id]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
def pullCached(args)
|
29
|
-
# Using a "REGION -> AREA -> TERRITORY" semantics
|
30
|
-
# Means: hash 'REGION:AREA' key 'TERRITORY'
|
31
|
-
areaDescr(args)
|
32
|
-
# redis ||= Redis.new(path: Bot.configuration.redis_url) ### May be BUG - needs additional Redis connection
|
33
|
-
a = Dialog::redis.hmget("#{args[:x][:redis][:region]}:#{args[:x][:redis][:area]}", ":#{args[:x][:redis][:territory]}")[0] # possible BUG - first array element
|
34
|
-
Dialog.logger.debug "Redis Request: \"#{args[:x][:redis][:region]}:#{args[:x][:redis][:area]}\" Key: \":#{args[:x][:redis][:territory]}\" Answer: \"#{a}\", x: #{args[:x][:redis]}"
|
35
|
-
|
36
|
-
if a.nil? and args[:pushCache] == true
|
37
|
-
a = pushCached(args)
|
38
|
-
end
|
39
|
-
Dialog.logger.debug "Using RedisCached for the upper request"
|
40
|
-
Dialog.clearRedis(args)
|
41
|
-
a
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
def pushCached(args)
|
46
|
-
areaDescr(args)
|
47
|
-
Dialog.logger.debug "Redis pushToCache, area::#{args[:x][:redis][:area]}, region::#{args[:x][:redis][:region]}"
|
48
|
-
case args[:x][:redis][:region]
|
49
|
-
when 'chat'
|
50
|
-
|
51
|
-
case args[:x][:redis][:territory]
|
52
|
-
when 'context'
|
53
|
-
pushCachedContext(args)
|
54
|
-
end
|
55
|
-
|
56
|
-
when 'user'
|
57
|
-
case args[:x][:redis][:territory]
|
58
|
-
when 'settings'
|
59
|
-
@v = true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
@v=redisWrite_ChatCached({hname: "#{args[:x][:redis][:region]}:#{args[:x][:redis][:area]}", k: args[:x][:redis][:territory], v: @v}, args)
|
64
|
-
@v
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
def pushCachedContext(args)
|
69
|
-
Dialog.clearApi(args)
|
70
|
-
args[:smsg] = {chat_id: args[:mmsg][:fqndata][:o][:chat][:id]}
|
71
|
-
args[:api][:op] = 'ChatAdministrators'
|
72
|
-
a = Dialog::BotApi.apiActionGet(args)
|
73
|
-
bman = 0; cman = 0
|
74
|
-
a['result'].each do |user|
|
75
|
-
Dialog.logger.debug "userId #{user['user']['id']}, userStatus #{user['status']}; cliId #{args[:globals][:cliId]}, botId #{Dialog.config.naming.id}"
|
76
|
-
cman = 1 if (user['user']['id'].to_i == args[:globals][:cliId] and user['status'] == 'creator')
|
77
|
-
bman = 1 if (user['user']['id'].to_i == Dialog.config.naming.id and user['status'] == 'administrator')
|
78
|
-
end
|
79
|
-
Dialog.logger.debug "Context args: @bman=#{bman} @cman=#{cman}"
|
80
|
-
@v = Dialog::Naming::ChatContext.Fullman if (bman == 1 and cman == 1)
|
81
|
-
@v = Dialog::Naming::ChatContext.Botman if (bman == 1 and cman == 0)
|
82
|
-
@v = Dialog::Naming::ChatContext.Climan if (bman == 0 and cman == 1)
|
83
|
-
@v = Dialog::Naming::ChatContext.Noman if (bman == 0 and cman == 0)
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
def redisWrite_ChatCached(vals, args)
|
88
|
-
Dialog.redis.hmset("#{vals[:hname]}", ":#{vals[:k]}", vals[:v])
|
89
|
-
args[:x][:redis].key?(:ttl) ? true : args[:x][:redis][:ttl] = 600
|
90
|
-
Dialog.redis.expire "#{vals[:hname]}", args[:x][:redis][:ttl]
|
91
|
-
Dialog.logger.debug "Redis SET - #{vals[:hname]} K:#{vals[:k]} V: #{vals[:v]} with ttl #{args[:x][:redis][:ttl]}"
|
92
|
-
vals[:v]
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,78 +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 = ruby
|
10
|
-
## Indent = space; 2 chars;
|
11
|
-
######## ####### ######## ####### ######## ########
|
12
|
-
|
13
|
-
module Dialog
|
14
|
-
class << self
|
15
|
-
|
16
|
-
def trigger_deploy
|
17
|
-
require 'erb'
|
18
|
-
deploy_redis
|
19
|
-
deploy_bot
|
20
|
-
deploy_binaries
|
21
|
-
end
|
22
|
-
|
23
|
-
def erb(erbFile, dst, mode='')
|
24
|
-
if not File.file?(dst)
|
25
|
-
tmpl = ERB.new(File.read("#{Dialog.config.path.dialog_ruby}/exec/#{erbFile}")).result(binding)
|
26
|
-
File.open(dst, 'w') do |f| f.write tmpl; end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def deploy_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
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
def deploy_bot
|
47
|
-
erb('systemd/dialog_runMode@.service', "#{Dir.home}/.config/systemd/user/dialog_bot_pre@.service", 'check')
|
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}")
|
52
|
-
end
|
53
|
-
|
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}")
|
57
|
-
end
|
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
|
-
|
65
|
-
def deploy_devenv
|
66
|
-
end
|
67
|
-
|
68
|
-
def deploy_gitsync
|
69
|
-
end
|
70
|
-
|
71
|
-
def systemd(service)
|
72
|
-
Open3.popen3('/usr/bin/systemctl', '--user', 'daemon-reload')
|
73
|
-
# Open3.popen3('/usr/bin/systemctl', '--user', 'restart', service)
|
74
|
-
#enable
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
@@ -1,43 +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 = 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
|