Merge pull request #269 from godande/develop

Dice API support
This commit is contained in:
demget 2020-04-25 16:26:43 +03:00 committed by GitHub
commit 81f4447261
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 1 deletions

2
bot.go
View File

@ -487,6 +487,8 @@ func (b *Bot) handleMedia(m *Message) bool {
b.handle(OnLocation, m) b.handle(OnLocation, m)
case m.Venue != nil: case m.Venue != nil:
b.handle(OnVenue, m) b.handle(OnVenue, m)
case m.Dice != nil:
b.handle(OnDice, m)
default: default:
return false return false
} }

View File

@ -210,3 +210,8 @@ type Venue struct {
FoursquareID string `json:"foursquare_id,omitempty"` FoursquareID string `json:"foursquare_id,omitempty"`
FoursquareType string `json:"foursquare_type,omitempty"` FoursquareType string `json:"foursquare_type,omitempty"`
} }
type Dice struct {
Type DiceType `json:"emoji"`
Value int `json:"value"`
}

View File

@ -191,6 +191,8 @@ type Message struct {
// Inline keyboard attached to the message. // Inline keyboard attached to the message.
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"` ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"`
Dice *Dice `json:"dice"`
} }
// MessageEntity object represents "special" parts of text messages, // MessageEntity object represents "special" parts of text messages,

View File

@ -353,3 +353,19 @@ func (p *Poll) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
return extractMessage(data) return extractMessage(data)
} }
// Send delivers dice through bot b to recipient
func (d *Dice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
"emoji": string(d.Type),
}
embedSendOptions(params, opt)
data, err := b.Raw("sendDice", params)
if err != nil {
return nil, err
}
return extractMessage(data)
}

View File

@ -58,7 +58,7 @@ const (
OnPinned = "\apinned" OnPinned = "\apinned"
OnChannelPost = "\achan_post" OnChannelPost = "\achan_post"
OnEditedChannelPost = "\achan_edited_post" OnEditedChannelPost = "\achan_edited_post"
OnDice = "\adice"
// Will fire when bot is added to a group. // Will fire when bot is added to a group.
OnAddedToGroup = "\aadded_to_group" OnAddedToGroup = "\aadded_to_group"
// Group events: // Group events:
@ -200,3 +200,10 @@ const (
) )
const DefaultApiURL = "https://api.telegram.org" const DefaultApiURL = "https://api.telegram.org"
type DiceType string
var (
Cube = &Dice{Type: "🎲"}
Dart = &Dice{Type: "🎯"}
)