-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
67 lines (52 loc) · 1.26 KB
/
util.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
60
61
62
63
64
65
66
67
package gotgbot
import (
"encoding/json"
"fmt"
"github.com/go-redis/redis/v7"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/gohouse/gorose/v2"
"github.com/gohouse/gotgbot/config"
"github.com/gohouse/t"
"github.com/sirupsen/logrus"
"os"
"time"
)
func GetLargePhotoFromResponse(pic *[]tgbotapi.PhotoSize) (photo tgbotapi.PhotoSize) {
var width int
for _, v := range *pic {
width = t.Max(v.Width, width).Int()
if v.Width == width {
photo = v
}
}
return
}
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
func SimpleNewlog(msg interface{}) {
var filename = time.Now().Format("0102-150405")
var msgFilename = fmt.Sprintf("%s-msg-%v", filename, time.Now().Nanosecond())
newlog(msgFilename, msg)
}
func newlog(file string, msg interface{}) {
openFile, _ := os.OpenFile(fmt.Sprintf("log/tg_%s.log", file), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
marshal, _ := json.MarshalIndent(msg, "", " ")
fmt.Fprintln(openFile, string(marshal))
}
func Redis() *redis.Client {
return config.Redis()
}
func Logger() *logrus.Logger {
return config.Logger()
}
func DB() gorose.IOrm {
return config.DB()
}