-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice.go
45 lines (33 loc) · 1.32 KB
/
dice.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
package telebot
import (
"math/rand"
"net/url"
"strconv"
)
// send a dice
func (b *Bot) SendDice(chatId int, options SendMessageOptions) (string, error) {
return b.SendDiceEmoji(chatId, "", options)
}
// send a random dice
func (b *Bot) SendRandomDice(chatId int, options SendMessageOptions) (string, error) {
emojiList := []string{"🎲", "🎯", "🏀", "⚽", "🎳", "🎰"}
emoji := emojiList[rand.Intn(len(emojiList))]
return b.SendDiceEmoji(chatId, emoji, options)
}
// Send a dice Emoji (Supported emojis : “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Default is “🎲”. )
func (b *Bot) SendDiceEmoji(chatId int, emoji string, options SendMessageOptions) (string, error) {
val := url.Values{
"chat_id": {strconv.Itoa(chatId)},
"disable_notification": {strconv.FormatBool(options.DisableNotification)},
"allow_sending_without_reply": {strconv.FormatBool(options.AllowSendingWithoutReply)},
}
// Emoji (Supported emojis : “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Default is “🎲”. )
if emoji != "" {
val["emoji"] = []string{emoji}
}
// Reply to message
if options.ReplyToMessageId != 0 {
val["reply_to_message_id"] = []string{strconv.Itoa(options.ReplyToMessageId)}
}
return b.makeAPICall(sendDiceEndpoint, val)
}