Fetch Channel, convert IMs to string

This commit is contained in:
Ian Gulliver
2022-10-23 23:14:24 +00:00
parent 133d958029
commit 7a44aa2f5f

View File

@@ -10,8 +10,8 @@ import (
) )
type ChannelResponse struct { type ChannelResponse struct {
Ok bool `json:"ok"` Ok bool `json:"ok"`
Error string `json:"error"` Error string `json:"error"`
Channel *Channel `json:"channel"` Channel *Channel `json:"channel"`
} }
@@ -28,11 +28,11 @@ type UserResponse struct {
} }
type Channel struct { type Channel struct {
Id string `json:"id"` Id string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
IsChannel bool `json:"is_channel"` IsChannel bool `json:"is_channel"`
IsGroup bool `json:"is_group"` IsGroup bool `json:"is_group"`
IsIm bool `json:"is_im"` IsIm bool `json:"is_im"`
} }
type Item struct { type Item struct {
@@ -67,22 +67,31 @@ func main() {
continue continue
} }
fmt.Printf("%#v\n", item) user, err := getUser(c, item.Message.User)
fmt.Printf("\t%#v\n", item.Message) if err != nil {
panic(err)
}
user, err := getUser(c, item.Message.User) channel, err := getChannel(c, item.Channel)
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Printf("\t%#v\n", user) title, err := getTitle(item, user, channel)
if err != nil {
panic(err)
}
channel, err := getChannel(c, item.Channel) fmt.Printf("%s\n", title)
if err != nil { }
panic(err) }
}
fmt.Printf("\t%#v\n", channel) func getTitle(item *Item, user *User, channel *Channel) (string, error) {
switch {
case channel.IsIm:
return fmt.Sprintf("[%s] %s", user.Name, item.Message.Text), nil
default:
return "", fmt.Errorf("unknown channel type: %#v", channel)
} }
} }