-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_screenshot.go
59 lines (51 loc) · 1.08 KB
/
handle_screenshot.go
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
package main
import (
"fmt"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
func scrotFName(lossless bool) string {
fname := "scrot_" + time.Now().Format("20060102_150405")
if lossless {
fname += ".png"
} else {
fname += ".jpg"
}
return fname
}
func do_scrot(m *tgbotapi.Message, lossless bool) {
_, dsp := Split2(m.Text)
if dsp == "" {
dsp = config.Display
} else {
if config.Display != dsp {
config.Display = dsp
SaveConfig()
}
}
data, err := scrot(lossless)
fname := scrotFName(lossless)
if err != nil {
send_reply(m, true, fmt.Sprintf("scrot error: %s", err))
} else {
if lossless {
send_reply_document(m, fname, data)
} else {
send_reply_image(m, fname, data)
}
}
}
func handle_scrot(m *tgbotapi.Message) {
do_scrot(m, false)
}
func handle_hqscrot(m *tgbotapi.Message) {
do_scrot(m, true)
}
func register_screenshot() {
addHandler("SCROT", handle_scrot, "SCROT [<display>]\n"+
"take screenshot",
ACL_SCROT)
addHandler("HQSCROT", handle_hqscrot, "HQSCROT [<display>]\n"+
"take screenshot in high quality",
ACL_SCROT)
}