-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.rb
75 lines (69 loc) · 1.5 KB
/
main.rb
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# encoding: utf-8
require './photoIso.rb'
require './server.rb'
require './log.rb'
require './setting.rb'
require 'thread'
instance = PhotoIso.new "PhotoIso main block"
setting = Setting.new
# server
st = Thread.new {
if setting.server == "true"
begin
log %(#{Time.now.to_s} [EVENT] Start server)
s = Server.run!
rescue
log %(#{Time.now.to_s} [ERROR] Start server some error: #{$!.to_s} \nretry it...)
sleep 10
retry
end
end
}
#listen channel
Thread.new {
begin
log %(#{Time.now.to_s} [EVENT] Start listen channel)
instance.listenChannel while true
rescue
log %(#{Time.now.to_s} [ERROR] listen channel has some error: #{$!.to_s} \nretry it...)
retry
end
}
#friend watch
Thread.new {
addAllAsFriends
sleep 15
}
# check unreadPlurk once on start
#begin
# p instance.checkUnreadPlurk
#rescue
# log %(#{Time.now.to_s} [ERROR] Checking unread plurk has error: #{$!.to_s})
# sleep(10)
# retry
#end
while true
case gets.chomp
when "check"
p instance.checkUnreadPlurk
p instance.addAllAsFriends
when "get"
p instance.getUnreadPlurk
when "a"
#ic = Iconv.new("utf-8","big5")
p instance.addPlurk(gets.to_s,{ qualifier: ':' })
when "set"
puts "please entry the key"
key = gets.chomp
puts "please entry the value"
value = gets.chomp
setting.set(key,value)
setting.write!
setting.read
when "set -l"
setting.list
when "close"
log %(#{Time.now.to_s} [EVENT] Close robot)
exit
end
end