Загрузить файлы в «/»

This commit is contained in:
anon47 2024-01-28 07:41:36 -07:00
parent 726c18a9a4
commit 4fc9f89f07

131
autobudilnik.rb Normal file
View File

@ -0,0 +1,131 @@
# autobudilnik [-a <audiofilepath>] [-t <time>] [-c <configfilepath>]
#require 'io/console'
require 'reline'
za = [false,false,false]
nf = ''
da = ''
audiofilepath = "audio.opus"
waittime = 7200
configfilepath = "config.txt"
i=0;while i<ARGV.size
if ARGV[i] == "-a"
if za[0] == false
i += 1
za[0] = true
audiofilepath = ARGV[i]
else
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
da += " " + ARGV[i]
#raise "duplicate arguments"
end
elsif ARGV[i] == "-t"
if za[1] == false
i += 1
za[1] = true
waittime = ARGV[i].to_i
else
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
da += " " + ARGV[i]
#raise "duplicate arguments"
end
elsif ARGV[i] == "-c"
if za[2] == false
i += 1
za[2] = true
configfilepath = ARGV[i]
else
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
da += " " + ARGV[i]
#raise "duplicate arguments"
end
else
#nf.push ARGV[i]
nf += " " + ARGV[i]
#ARGV[i..ARGV.size].join(' ')
end
i+=1
end
puts "not found:" + nf if nf != ''
if da.size != 0
raise 'duplicate arguments:' + da
end
if za[0] == false || za[1] == false
configfilepath = File.absolute_path(configfilepath)
if File.file? configfilepath
puts 'reading config'
File.readlines(configfilepath).each { |l|
lspl = l.split(' ')
if za[0] == false && ('audiofilepath'.start_with? lspl[0])
audiofilepath = l.delete_prefix(lspl[0] + ' ').delete_prefix('"').delete_prefix("'").delete_suffix('"').delete_suffix("'")
#split('"')[0].split('"')[0]
elsif za[1] == false && ('waittime'.start_with? lspl[0])
waittime = lspl[1].to_i
end
}
else
if za[2] == true
raise configfilepath + ' doesnt exist'
end
end
end
puts 'waittime:' + waittime.to_s
audiofilepath = File.absolute_path(audiofilepath)
puts 'audiofilepath:' + audiofilepath
raise audiofilepath + ' doesnt exist' unless File.file? audiofilepath
nexttime = Time.new + waittime
waittime = waittime - 18 # 30 x 0.6 = 18
=begin
STDIN.echo = false
STDIN.raw!
getchr = false
Thread.new {while true do sleep(0.1);puts 't';STDIN.getbyte; getchr = true end}
puts "rtstrt"
while true
sleep(1.4)
if getchr == true
nexttime = Time.new + waittime;puts nexttime
getchr = false
end
if nexttime < Time.new
puts "audioplay"
system(audiofilepath)
end
#thr.run
end
=end
puts 'autobudilnik running'
a=Reline::Windows::Win32API.new('user32','GetAsyncKeyState','I','I')
a2=Reline::Windows::Win32API.new('user32','keybd_event','I','I')
b = []
c = []
while true
255.times {|r|
b[r] = a.call(r)
}
if c != b
nexttime = Time.now + waittime
end
sleep(3.4)
255.times {|r|
c[r] = a.call(r)
}
if c != b
nexttime = Time.now + waittime
end
if nexttime < Time.now
30.times {
sleep(0.6) #НУЖНО УБАВИТЬ С ВЭЙТТАЙМА
a2.call(175)
}
puts "audioplay"
system(audiofilepath)
end
sleep(3.4)
end