forked from zu1k/tg-keyword-reply-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendutil.go
executable file
·80 lines (72 loc) · 1.61 KB
/
sendutil.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
75
76
77
78
79
80
package main
import (
"log"
"time"
api "github.com/go-telegram-bot-api/telegram-bot-api"
)
/**
* 发送文字消息
*/
func sendMessage(msg api.MessageConfig) api.Message {
if msg.Text == "" {
return api.Message{}
}
mmsg, err := bot.Send(msg)
if err != nil {
log.Println(err)
}
go deleteMessage(msg.ChatID, mmsg.MessageID)
return mmsg
}
/**
* 发送图片消息, 需要是已经存在的图片链接
*/
func sendPhoto(chatid int64, photoid string) api.Message {
file := api.NewPhotoShare(chatid, photoid)
mmsg, err := bot.Send(file)
if err != nil {
log.Println(err)
}
go deleteMessage(chatid, mmsg.MessageID)
return mmsg
}
/**
* 发送动图, 需要是已经存在的链接
*/
func sendGif(chatid int64, gifid string) api.Message {
file := api.NewAnimationShare(chatid, gifid)
mmsg, err := bot.Send(file)
if err != nil {
log.Println(err)
}
go deleteMessage(chatid, mmsg.MessageID)
return mmsg
}
/**
* 发送视频, 需要是已经存在的视频连接
*/
func sendVideo(chatid int64, videoid string) api.Message {
file := api.NewVideoShare(chatid, videoid)
mmsg, err := bot.Send(file)
if err != nil {
log.Println(err)
}
go deleteMessage(chatid, mmsg.MessageID)
return mmsg
}
/**
* 发送文件, 必须是已经存在的文件链接
*/
func sendFile(chatid int64, fileid string) api.Message {
file := api.NewDocumentShare(chatid, fileid)
mmsg, err := bot.Send(file)
if err != nil {
log.Println(err)
}
go deleteMessage(chatid, mmsg.MessageID)
return mmsg
}
func deleteMessage(gid int64, mid int) {
time.Sleep(time.Second * 240)
_, _ = bot.DeleteMessage(api.NewDeleteMessage(gid, mid))
}