Browse Source

Add bot advertisement methods

main
Sam 5 years ago
parent
commit
2e7df5deef
  1. 38
      chat.go
  2. 8
      keybase.go
  3. 42
      types.go

38
chat.go

@ -489,3 +489,41 @@ func (c Chat) Mark(messageID int) (ChatAPI, error) { @@ -489,3 +489,41 @@ func (c Chat) Mark(messageID int) (ChatAPI, error) {
}
return r, nil
}
// ClearCommands clears bot advertisements
func (k *Keybase) ClearCommands() (ChatAPI, error) {
m := ChatAPI{}
m.Method = "clearcommands"
r, err := chatAPIOut(k, m)
if err != nil {
return ChatAPI{}, err
}
return r, nil
}
// AdvertiseCommands sets up bot command advertisements
// This method allows you to set up multiple different types of advertisements at once.
// Use this method if you have commands whose visibility differs from each other.
func (k *Keybase) AdvertiseCommands(advertisements []BotAdvertisement) (ChatAPI, error) {
m := ChatAPI{
Params: &params{},
}
m.Method = "advertisecommands"
m.Params.Options.BotAdvertisements = advertisements
r, err := chatAPIOut(k, m)
if err != nil {
return ChatAPI{}, err
}
return r, nil
}
// AdvertiseCommand sets up bot command advertisements
// This method allows you to set up one type of advertisement.
// Use this method if you have commands whose visibility should all be the same.
func (k *Keybase) AdvertiseCommand(advertisement BotAdvertisement) (ChatAPI, error) {
return k.AdvertiseCommands([]BotAdvertisement{
advertisement,
})
}

8
keybase.go

@ -36,6 +36,14 @@ func NewKeybase(path ...string) *Keybase { @@ -36,6 +36,14 @@ func NewKeybase(path ...string) *Keybase {
return k
}
// NewBotCommand returns a new BotCommand instance
func NewBotCommand(name string, description string) BotCommand {
return BotCommand{
Name: name,
Description: description,
}
}
// Exec executes the given Keybase command
func (k *Keybase) Exec(command ...string) ([]byte, error) {
out, err := exec.Command(k.Path, command...).Output()

42
types.go

@ -296,23 +296,36 @@ type Channel struct { @@ -296,23 +296,36 @@ type Channel struct {
TopicName string `json:"topic_name,omitempty"`
}
type BotCommand struct {
Name string `json:"name"`
Description string `json:"description"`
}
type BotAdvertisement struct {
Type string `json:"type"` // "public", "teamconvs", "teammembers"
TeamName string `json:"team_name,omitempty"` // required if Type is not "public"
BotCommands []BotCommand `json:"commands"`
}
type mesg struct {
Body string `json:"body"`
}
type options struct {
Channel *Channel `json:"channel,omitempty"`
MessageID int `json:"message_id,omitempty"`
Message *mesg `json:"message,omitempty"`
Pagination *pagination `json:"pagination,omitempty"`
Filename string `json:"filename,omitempty,omitempty"`
Title string `json:"title,omitempty,omitempty"`
Output string `json:"output,omitempty,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
FlipConversationID string `json:"flip_conversation_id,omitempty"`
MsgID int `json:"msg_id,omitempty"`
ReplyTo int `json:"reply_to,omitempty"`
GameID string `json:"game_id,omitempty"`
Channel *Channel `json:"channel,omitempty"`
MessageID int `json:"message_id,omitempty"`
Message *mesg `json:"message,omitempty"`
Pagination *pagination `json:"pagination,omitempty"`
Filename string `json:"filename,omitempty,omitempty"`
Title string `json:"title,omitempty,omitempty"`
Output string `json:"output,omitempty,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
FlipConversationID string `json:"flip_conversation_id,omitempty"`
MsgID int `json:"msg_id,omitempty"`
ReplyTo int `json:"reply_to,omitempty"`
GameID string `json:"game_id,omitempty"`
Alias string `json:"alias,omitempty"`
BotAdvertisements []BotAdvertisement `json:"advertisements,omitempty"`
Name string `json:"name,omitempty"`
Public bool `json:"public,omitempty"`
@ -641,14 +654,17 @@ type wallet interface { @@ -641,14 +654,17 @@ type wallet interface {
}
type keybase interface {
AdvertiseCommand(advertisement BotAdvertisement) (ChatAPI, error)
AdvertiseCommands(advertisements []BotAdvertisement) (ChatAPI, error)
ChatList() (ChatAPI, error)
ClearCommands() (ChatAPI, error)
CreateTeam(name string) (TeamAPI, error)
NewChat(channel Channel) Chat
NewTeam(name string) Team
NewWallet() Wallet
Run(handler func(ChatAPI), options ...RunOptions)
version() string
status() status
version() string
}
type status struct {

Loading…
Cancel
Save