2020-10-07 01:53:15 +00:00
|
|
|
package shared
|
|
|
|
|
|
|
|
import (
|
2020-12-17 08:01:58 +00:00
|
|
|
"errors"
|
|
|
|
|
2020-10-07 01:53:15 +00:00
|
|
|
"github.com/diamondburned/arikawa/discord"
|
|
|
|
"github.com/diamondburned/cchat-discord/internal/discord/state"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Channel struct {
|
|
|
|
ID discord.ChannelID
|
|
|
|
GuildID discord.GuildID
|
|
|
|
State *state.Instance
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasPermission returns true if the current user has the given permissions in
|
|
|
|
// the channel.
|
|
|
|
func (ch Channel) HasPermission(perms ...discord.Permissions) bool {
|
|
|
|
p, err := ch.State.StateOnly().Permissions(ch.ID, ch.State.UserID)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, perm := range perms {
|
|
|
|
if !p.Has(perm) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ch Channel) Messages() ([]discord.Message, error) {
|
|
|
|
return ch.State.Store.Messages(ch.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ch Channel) Guild() (*discord.Guild, error) {
|
2020-12-17 08:01:58 +00:00
|
|
|
if !ch.GuildID.IsValid() {
|
|
|
|
return nil, errors.New("channel not in guild")
|
|
|
|
}
|
2020-10-07 01:53:15 +00:00
|
|
|
return ch.State.Store.Guild(ch.GuildID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ch Channel) Self() (*discord.Channel, error) {
|
|
|
|
return ch.State.Store.Channel(ch.ID)
|
|
|
|
}
|