<commit_before>package main

import "github.com/horgh/irc"

// Channel holds everything to do with a channel.
type Channel struct {
	// Canonicalized name.
	Name string

	// Members in the channel.
	// If we have zero members, we should not exist.
	Members map[TS6UID]struct{}

	// Ops tracks users who have ops in the channel.
	Ops map[TS6UID]*User

	// Current topic. May be blank.
	Topic string

	// Topic TS. Changes on TOPIC command (or if server tells us one).
	TopicTS int64

	// The person who set the topic. nick!user@host
	TopicSetter string

	// Modes set on the channel.
	Modes map[byte]struct{}

	// Channel TS. Changes on channel creation (or if another server tells us
	// a different TS).
	TS int64
}

// Check if a user has operator status in the channel.
func (c *Channel) userHasOps(u *User) bool {
	_, exists := c.Ops[u.UID]
	return exists
}

// Remove a user from the channel.
func (c *Channel) removeUser(u *User) {
	_, exists := c.Members[u.UID]
	if exists {
		delete(c.Members, u.UID)
	}

	_, exists = c.Ops[u.UID]
	if exists {
		delete(c.Ops, u.UID)
	}

	_, exists = u.Channels[c.Name]
	if exists {
		delete(u.Channels, c.Name)
	}
}

// Grant a user ops.
func (c *Channel) grantOps(u *User) {
	c.Ops[u.UID] = u
}

// Remove ops from a user
func (c *Channel) removeOps(u *User) {
	_, exists := c.Ops[u.UID]
	if exists {
		delete(c.Ops, u.UID)
	}
}

// Remove all modes from the channel, and all ops/voices.
//
// This informs local users about the mode changes, but no one else.
func (c *Channel) clearModes(cb *Catbox) {
	// Build all the messages we need prior to sending.
	msgs := []irc.Message{}

	// Clear things like +ns

	modeStr := ""
	for k := range c.Modes {
		delete(c.Modes, k)
		modeStr += string(k)
	}
	if len(modeStr) > 0 {
		msgs = append(msgs, irc.Message{
			Prefix:  cb.Config.ServerName,
			Command: "MODE",
			Params:  []string{c.Name, "-" + modeStr},
		})
	}

	// Clear ops.

	ops := []string{}
	for _, op := range c.Ops {
		ops = append(ops, op.DisplayNick)

		if len(ops) == ChanModesPerCommand {
			modeStr := "-"
			for i := 0; i < ChanModesPerCommand; i++ {
				modeStr += "o"
			}

			params := []string{c.Name, modeStr}
			params = append(params, ops...)

			msgs = append(msgs, irc.Message{
				Prefix:  cb.Config.ServerName,
				Command: "MODE",
				Params:  params,
			})

			ops = []string{}
		}
	}

	if len(ops) > 0 {
		modeStr := "-"
		for range ops {
			modeStr += "o"
		}

		params := []string{c.Name, modeStr}
		params = append(params, ops...)

		msgs = append(msgs, irc.Message{
			Prefix:  cb.Config.ServerName,
			Command: "MODE",
			Params:  params,
		})
	}<commit_msg>Style: Use nil slice rather than empty slice<commit_after>package main

import "github.com/horgh/irc"

// Channel holds everything to do with a channel.
type Channel struct {
	// Canonicalized name.
	Name string

	// Members in the channel.
	// If we have zero members, we should not exist.
	Members map[TS6UID]struct{}

	// Ops tracks users who have ops in the channel.
	Ops map[TS6UID]*User

	// Current topic. May be blank.
	Topic string

	// Topic TS. Changes on TOPIC command (or if server tells us one).
	TopicTS int64

	// The person who set the topic. nick!user@host
	TopicSetter string

	// Modes set on the channel.
	Modes map[byte]struct{}

	// Channel TS. Changes on channel creation (or if another server tells us
	// a different TS).
	TS int64
}

// Check if a user has operator status in the channel.
func (c *Channel) userHasOps(u *User) bool {
	_, exists := c.Ops[u.UID]
	return exists
}

// Remove a user from the channel.
func (c *Channel) removeUser(u *User) {
	_, exists := c.Members[u.UID]
	if exists {
		delete(c.Members, u.UID)
	}

	_, exists = c.Ops[u.UID]
	if exists {
		delete(c.Ops, u.UID)
	}

	_, exists = u.Channels[c.Name]
	if exists {
		delete(u.Channels, c.Name)
	}
}

// Grant a user ops.
func (c *Channel) grantOps(u *User) {
	c.Ops[u.UID] = u
}

// Remove ops from a user
func (c *Channel) removeOps(u *User) {
	_, exists := c.Ops[u.UID]
	if exists {
		delete(c.Ops, u.UID)
	}
}

// Remove all modes from the channel, and all ops/voices.
//
// This informs local users about the mode changes, but no one else.
func (c *Channel) clearModes(cb *Catbox) {
	// Build all the messages we need prior to sending.
	var msgs []irc.Message

	// Clear things like +ns

	modeStr := ""
	for k := range c.Modes {
		delete(c.Modes, k)
		modeStr += string(k)
	}
	if len(modeStr) > 0 {
		msgs = append(msgs, irc.Message{
			Prefix:  cb.Config.ServerName,
			Command: "MODE",
			Params:  []string{c.Name, "-" + modeStr},
		})
	}

	// Clear ops.

	var ops []string
	for _, op := range c.Ops {
		ops = append(ops, op.DisplayNick)

		if len(ops) == ChanModesPerCommand {
			modeStr := "-"
			for i := 0; i < ChanModesPerCommand; i++ {
				modeStr += "o"
			}

			params := []string{c.Name, modeStr}
			params = append(params, ops...)

			msgs = append(msgs, irc.Message{
				Prefix:  cb.Config.ServerName,
				Command: "MODE",
				Params:  params,
			})

			ops = nil
		}
	}

	if len(ops) > 0 {
		modeStr := "-"
		for range ops {
			modeStr += "o"
		}

		params := []string{c.Name, modeStr}
		params = append(params, ops...)

		msgs = append(msgs, irc.Message{
			Prefix:  cb.Config.ServerName,
			Command: "MODE",
			Params:  params,
		})
	}
{'fraction_non_alphanumeric': 0.14191232048374905, 'fraction_numerical': 0.003401360544217687, 'mean_word_length': 2.824421965317919, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5159974', 'n_tokens_mistral': 2113, 'n_tokens_neox': 1919, 'n_words': 613}