-
Notifications
You must be signed in to change notification settings - Fork 9
/
liveLocation.go
117 lines (94 loc) 路 4.04 KB
/
liveLocation.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package telego
import (
"encoding/json"
errs "github.com/SakoDroid/telego/v2/errors"
objs "github.com/SakoDroid/telego/v2/objects"
)
// LiveLocation is a live location that can be sent to a user.
type LiveLocation struct {
bot *Bot
chatIdInt int
chatIdString string
messageId int
replyTo, messageThreadId int
allowSendingWihoutReply bool
replyMarkUp objs.ReplyMarkup
latitude, longitude, horizontalAccuracy float32
livePeriod, heading, proximityAlertRadius int
}
/*
Send sends this live location to all types of chats but channels. To send it to a channel use "SendToChannelMethod".
If "silent" argument is true, the message will be sent without notification.
If "protectContent" argument is true, the message can't be forwarded or saved.
------------------------
Official telegram doc :
Use this method to send point on the map. On success, the sent Message is returned.
*/
func (ll *LiveLocation) Send(chatId int, silent, protectContent bool) (*objs.Result[*objs.Message], error) {
ll.chatIdInt = chatId
res, err := ll.bot.apiInterface.SendLocation(
chatId, "", ll.latitude, ll.longitude, ll.horizontalAccuracy, ll.livePeriod,
ll.heading, ll.proximityAlertRadius, ll.replyTo, ll.messageThreadId, silent, ll.allowSendingWihoutReply, protectContent,
ll.replyMarkUp,
)
if err == nil {
ll.messageId = res.Result.MessageId
}
return res, err
}
/*
SendToChannel sends this live location to a channel. Chat id should be the username of the channel.
If "silent" argument is true, the message will be sent without notification.
If "protectContent" argument is true, the message can't be forwarded or saved.
------------------------
Official telegram doc :
Use this method to send point on the map. On success, the sent Message is returned.
*/
func (ll *LiveLocation) SendToChannel(chatId string, silent, protectContent bool) (*objs.Result[*objs.Message], error) {
ll.chatIdString = chatId
res, err := ll.bot.apiInterface.SendLocation(
0, chatId, ll.latitude, ll.longitude, ll.horizontalAccuracy, ll.livePeriod,
ll.heading, ll.proximityAlertRadius, ll.replyTo, ll.messageThreadId, silent, ll.allowSendingWihoutReply, protectContent,
ll.replyMarkUp,
)
if err == nil {
ll.messageId = res.Result.MessageId
}
return res, err
}
/*
Edit edits the live location.
------------------------
Official telegram doc :
Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
*/
func (ll *LiveLocation) Edit(latitude, langitude, horizontalAccuracy float32, heading, proximtyAlertRadius int, replyMarkUp *objs.InlineKeyboardMarkup) (*objs.Result[json.RawMessage], error) {
if ll.messageId != 0 {
ll.latitude = latitude
ll.longitude = langitude
ll.horizontalAccuracy = horizontalAccuracy
ll.heading = heading
ll.proximityAlertRadius = proximtyAlertRadius
ll.replyMarkUp = replyMarkUp
return ll.bot.apiInterface.EditMessageLiveLocation(
ll.chatIdInt, ll.chatIdString, "", ll.messageId, ll.latitude, ll.longitude,
ll.horizontalAccuracy, ll.heading, ll.proximityAlertRadius, replyMarkUp,
)
}
return nil, &errs.LiveLocationNotStarted{}
}
/*
Stop stops the live location.
------------------------
Official telegram doc :
Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
*/
func (ll *LiveLocation) Stop(replyMarkrup objs.InlineKeyboardMarkup) (*objs.Result[json.RawMessage], error) {
if ll.messageId != 0 {
return ll.bot.apiInterface.StopMessageLiveLocation(
ll.chatIdInt, ll.chatIdString, "", ll.messageId, &replyMarkrup,
)
} else {
return nil, &errs.LiveLocationNotStarted{}
}
}