channel

package
v0.0.0-...-431b4e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// member
	Founder prefix = 1 << iota
	Protected
	Operator
	Halfop
	Voice
)

Variables

View Source
var (
	ErrKeyMissing   = errors.New("ERR_BADCHANNELKEY")
	ErrLimitReached = errors.New("ERR_CHANNELISFULL")
	ErrNotInvited   = errors.New("ERR_INVITEONLYCHAN")
	ErrBanned       = errors.New("ERR_BANNEDFROMCHAN")
)
View Source
var (
	ErrNeedMoreParams = errors.New("")
	ErrNotInChan      = errors.New("")
	ErrUnknownMode    = errors.New("")
	ErrInvalidKey     = errors.New("")
)
View Source
var MemberPrefix = map[byte]prefix{
	'~': Founder,
	'&': Protected,
	'@': Operator,
	'%': Halfop,
	'+': Voice,
}

Functions

func PrepareModes

func PrepareModes(modes []mode.Mode, params []string)

PrepareModes performs two tasks:

  1. associates the given params with the Params field of the modes. Params are processed in index order, so something like "MODE #test +ok alice password" will associate 'o' with 'alice' and 'k' with 'password'. This skips unknown mode characters.
  2. sets the Type of a mode to mode.List if there are no more params left to be associated and that particular mode is listable

Types

type ChanType

type ChanType rune
const (
	Remote ChanType = '#'
	Local  ChanType = '&'
)

type Channel

type Channel struct {
	// Name is case-insensitive, stored internally in lower-case
	Name     string
	ChanType ChanType

	CreatedAt time.Time

	Topic      string
	TopicSetBy *client.Client
	TopicSetAt time.Time

	// array of nickmasks
	Ban          []string
	BanExcept    []string
	Limit        int
	Invite       bool
	InviteExcept []string
	Key          string
	Moderated    bool
	Secret       bool
	Protected    bool
	NoExternal   bool

	// Invited is a list of client nicks who have been INVITEd
	Invited []string

	// map of Nick to undelying client
	Members *util.SafeMap[string, *Member]
}

func New

func New(name string, t ChanType) *Channel

func (*Channel) Admit

func (ch *Channel) Admit(c *client.Client, key string) error

Admit adds a client to this channel. A client c is admitted to enter a channel if:

  1. If this channel has a key, the client supplies the correct key
  2. admitting this client does not put the channel over the chanlimit
  3. their nick has been given an INVITE
  4. if they have not been given an INVITE, their nickmask is in the inviteException list
  5. their nickmask is not included in the banlist
  6. if they are in the banlist, they are in the except list

func (*Channel) All

func (ch *Channel) All() iter.Seq[*Member]

func (*Channel) AllExcept

func (ch *Channel) AllExcept(except *client.Client) iter.Seq[*Member]

AllExcept returns an iterator of all members in the channel except ones matching the except Client.

func (*Channel) ApplyMode

func (c *Channel) ApplyMode(m mode.Mode) error

ApplyMode applies the given mode to the channel. It does not verify that the sending client has the proper permissions to make those changes. It returns a modeStr if the mode was successfully applied.

func (*Channel) DeleteMember

func (c *Channel) DeleteMember(m string)

func (*Channel) GetMember

func (c *Channel) GetMember(m string) (*Member, bool)

func (*Channel) Len

func (c *Channel) Len() int

func (*Channel) Modes

func (c *Channel) Modes() (modestr string, params []string)

func (*Channel) SetMember

func (c *Channel) SetMember(v *Member)

func (*Channel) String

func (c *Channel) String() string

func (*Channel) WriteMessage

func (c *Channel) WriteMessage(m msg.Msg)

func (*Channel) WriteMessageFrom

func (c *Channel) WriteMessageFrom(m msg.Msg, from *client.Client)

type Member

type Member struct {
	*client.Client
	Prefix prefix
}

Member is a Client that belongs to a channel. Members, unlike Clients, have the capability to be given a mode/prefix.

func (*Member) ApplyMode

func (c *Member) ApplyMode(m mode.Mode) bool

func (Member) HighestPrefix

func (m Member) HighestPrefix(multiPrefix bool) string

Returns the highest prefix that the member has. If multiPrefix is true, returns all the modes that this member has in order of rank.

func (Member) Is

func (m Member) Is(p prefix) bool

func (Member) ModeLetters

func (m Member) ModeLetters() string

Reconstruct this member's prefix string as a string of each prefix matched to its corresponding mode letter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL