1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
require 'tempfile'
class ChatBot
def initialize(account, password, otr_key, opts = Hash.new)
@account = account
@password = password
@otr_key = otr_key
@opts = opts
@pid = nil
@otr_key_file = nil
end
def start
@otr_key_file = Tempfile.new("otr_key.", $config["TMPDIR"])
@otr_key_file << @otr_key
@otr_key_file.close
cmd_helper(['/usr/bin/convertkey', @otr_key_file.path])
cmd_helper(["mv", "#{@otr_key_file.path}3", @otr_key_file.path])
cmd = [
"#{GIT_DIR}/features/scripts/otr-bot.py",
@account,
@password,
@otr_key_file.path
]
cmd += ["--connect-server", @opts["connect_server"]] if @opts["connect_server"]
cmd += ["--auto-join"] + @opts["auto_join"] if @opts["auto_join"]
cmd += ["--log-file", DEBUG_LOG_PSEUDO_FIFO]
job = IO.popen(cmd)
@pid = job.pid
end
def stop
@otr_key_file.delete
begin
Process.kill("TERM", @pid)
rescue
# noop
end
end
def active?
begin
ret = Process.kill(0, @pid)
rescue Errno::ESRCH => e
if e.message == "No such process"
return false
else
raise e
end
end
assert_equal(1, ret, "This shouldn't happen")
return true
end
end
|