-
Notifications
You must be signed in to change notification settings - Fork 2
/
tbot_util.go
74 lines (66 loc) · 1.53 KB
/
tbot_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
68
69
70
71
72
73
74
/*
* @Author: SpenserCai
* @Date: 2023-02-23 15:16:57
* @version:
* @LastEditors: SpenserCai
* @LastEditTime: 2023-02-25 13:08:58
* @Description: file content
*/
package main
import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"time"
tele "gopkg.in/telebot.v3"
)
func InitBot() {
tempBot, err := tele.NewBot(tele.Settings{
Token: TELBOT_TOKEN,
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
Client: &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(&url.URL{
Scheme: "socks5",
Host: "127.0.0.1:" + strconv.Itoa(LOCAL_PROXY_PORT),
}),
},
},
})
if err != nil {
fmt.Println(err)
return
}
TelBot = tempBot
}
// 发送纯文本消息
func TeleSendMessge(message string) {
TelBot.Send(tele.ChatID(-TELBOT_CHAT_ID), message)
}
// 发送支持文件和markdown的消息
func TeleSendMarkDownMessage(message string) {
// 发送markdown
TelBot.Send(tele.ChatID(-TELBOT_CHAT_ID), message, &tele.SendOptions{
ParseMode: tele.ModeMarkdown,
})
}
// 同时发送文件和markdown消息
func TeleSendFileAndMessage(message string, fileLocalList []string) {
// 判断ANONFILES_TOKEN是否为空
if ANONFILES_TOKEN == "" {
TeleSendMarkDownMessage(message)
return
}
for _, fileLocal := range fileLocalList {
// 上传文件
fileUrl, err := AnonFilesUpload(fileLocal)
if err != nil {
TeleSendMarkDownMessage(message)
return
}
message += strings.Split(fileLocal, "\\")[len(strings.Split(fileLocal, "\\"))-1] + ":" + fileUrl + " \n"
}
TeleSendMarkDownMessage(message)
}