mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2024-12-24 05:07:32 +00:00
42 lines
886 B
Go
42 lines
886 B
Go
|
package shared
|
||
|
|
||
|
import (
|
||
|
"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) {
|
||
|
return ch.State.Store.Guild(ch.GuildID)
|
||
|
}
|
||
|
|
||
|
func (ch Channel) Self() (*discord.Channel, error) {
|
||
|
return ch.State.Store.Channel(ch.ID)
|
||
|
}
|