utils

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AIGeminiProvider  = "gemini"
	AICopilotProvider = "copilot"
	AIGitHubProvider  = "github"

	DefaultGeminiModel  = "gemini-3.8-flash"
	DefaultCopilotModel = "gpt-4o-mini"
)
View Source
const (
	AttachmentMarkerStart = "\x00<ATTM\x00"
	AttachmentMarkerEnd   = "\x00ATTM>\x00"
)
View Source
const BlockQuoteCharDefault = ">"

Variables

View Source
var GetEmojiMap = sync.OnceValue(func() map[string]string {
	data := emoji.Gemoji()
	aliasMap := make(map[string]string, (len(data)*6)+len(defaultAliases))

	register := func(name string, unicodeVal string, supportsSkinTone bool) {
		if name == "" {
			return
		}

		if _, exists := aliasMap[name]; !exists {
			aliasMap[name] = unicodeVal
		}

		if !supportsSkinTone {
			return
		}

		for _, st := range skinToneSuffixes {
			variantKey := name + st.suffix
			if _, exists := aliasMap[variantKey]; !exists {
				aliasMap[variantKey] = applySkinTone(unicodeVal, st.tone)
			}
		}
	}

	registerWithVariants := func(name string, unicodeVal string, supportsSkinTone bool) {
		register(name, unicodeVal, supportsSkinTone)

		if strings.ContainsRune(name, '-') {
			register(strings.ReplaceAll(name, "-", "_"), unicodeVal, supportsSkinTone)
		}

		if rest, ok := strings.CutSuffix(name, "_man"); ok {
			register("man_"+rest, unicodeVal, supportsSkinTone)
			register("man-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone)
		} else if rest, ok := strings.CutSuffix(name, "_woman"); ok {
			register("woman_"+rest, unicodeVal, supportsSkinTone)
			register("woman-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone)
		} else if rest, ok := strings.CutPrefix(name, "male_"); ok {
			register("man_"+rest, unicodeVal, supportsSkinTone)
			register("man-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone)
		} else if rest, ok := strings.CutPrefix(name, "female_"); ok {
			register("woman_"+rest, unicodeVal, supportsSkinTone)
			register("woman-"+strings.ReplaceAll(rest, "_", "-"), unicodeVal, supportsSkinTone)
		}
	}

	for _, e := range data {
		if e.Emoji == "" {
			continue
		}

		for _, alias := range e.Aliases {
			registerWithVariants(alias, e.Emoji, e.SkinTones)
		}

		for _, tag := range e.Tags {
			registerWithVariants(tag, e.Emoji, e.SkinTones)
		}
	}

	for alias, target := range defaultAliases {
		targetClean := trimColons(target)

		if unicodeVal, exists := aliasMap[targetClean]; exists {
			registerWithVariants(alias, unicodeVal, true)
		}
	}

	return aliasMap
})

GetEmojiMap initializes and returns the immutable alias-to-Unicode map once using Go 1.21+ sync.OnceValue.

Functions

func EmojiFromAlias added in v0.31.0

func EmojiFromAlias(alias string, customAliases map[string]string) (string, bool)

EmojiFromAlias looks up an emoji by shortcode, supporting with or without surrounding colons.

func EmojiReplaceAliases added in v0.31.0

func EmojiReplaceAliases(s string, customAliases map[string]string) string

EmojiReplaceAliases scans the input and replaces :alias: tokens with Unicode emojis.

func FindClosestIRCColor added in v0.32.0

func FindClosestIRCColor(hexColor string) string

FindClosestIRCColor uses the precalculated palette to quickly find the nearest match.

func FormatAndShortenSummary added in v0.32.0

func FormatAndShortenSummary(text string, opts SummaryOpts) string

FormatAndShortenSummary formats markdown/emoji, collapses newlines, and shortens text.

func FormatFullCodeBlock added in v0.32.0

func FormatFullCodeBlock(text, lexer, indent string, opts ProcessMessageOpts, yield func(string))

FormatFullCodeBlock handles syntax highlighting entirely in-memory and yields lines

func FormatMarkdownAndEmoji added in v0.32.0

func FormatMarkdownAndEmoji(msg string, disableMarkdown bool, disableEmoji bool, blockQuoteChar string, inlineCode string, customEmoji map[string]string) string

FormatMarkdownAndEmoji applies Markdown formatting and Emoji alias replacement. It utilizes a fast-path single-pass check to bypass processing entirely if no trigger characters are present, drastically reducing allocations and CPU usage.

func GetModel added in v0.33.0

func GetModel(provider, fallbackModel string, models map[string]string) string

GetModel resolves the AI model to use based on provider, fallback model, and the models map.

func Irc2Markdown added in v0.33.0

func Irc2Markdown(msg string) string

Irc2Markdown converts IRC formatting back to Markdown, handling links and text styles.

func Markdown2irc

func Markdown2irc(msg string, blockQuoteChar string, inlineCode string) string

func ProcessMessageText added in v0.32.0

func ProcessMessageText(text string, opts ProcessMessageOpts, yield func(line string))

ProcessMessageText abstracts the parsing loop, multi-line code handling, and formatting. It uses a zero-allocation callback (yield) to return lines.

func WrapMessage added in v0.31.0

func WrapMessage(msg string, maxLen int) string

WrapMessage soft-wraps msg into lines of at most maxLen bytes, breaking only at spaces/newlines. Words longer than maxLen are left unbroken and overflow their line rather than being split - fine here since IRC's real line limit (512) leaves headroom above maxLen (460), and splitting mid- word would corrupt URLs/tokens. Pure byte scanning throughout

Types

type Client added in v0.32.0

type Client struct {
	// contains filtered or unexported fields
}

func NewGeminiClient added in v0.33.0

func NewGeminiClient(ctx context.Context, saFile, project, location, model string) (*Client, error)

NewGeminiClient creates a new Gemini AI client authenticated via service account credentials.

func (*Client) Project added in v0.33.0

func (c *Client) Project() string

Project returns the resolved GCP project ID.

func (*Client) Summarize added in v0.32.0

func (c *Client) Summarize(ctx context.Context, prompt string, thinking string) (string, error)

type CopilotClient added in v0.33.0

type CopilotClient struct {
	// contains filtered or unexported fields
}

func NewCopilotClient added in v0.33.0

func NewCopilotClient(token, model string) (*CopilotClient, error)

NewCopilotClient creates a client targeting the native GitHub Copilot API.

func (*CopilotClient) Summarize added in v0.33.0

func (c *CopilotClient) Summarize(ctx context.Context, prompt string, _ string) (string, error)

type IRCColor added in v0.32.0

type IRCColor struct {
	Code    string
	R, G, B int
}

IRCColor represents a pre-parsed IRC color for fast distance calculations.

type ProcessMessageOpts added in v0.32.0

type ProcessMessageOpts struct {
	DisableEmoji bool
	CustomEmoji  map[string]string

	DisableMarkdown    bool
	SyntaxHighlighting string
	CodeBlockPrefix    string
	CodeBlockSeparator string
	BlockquoteChar     string
	InlineCodeChar     string

	PreserveNewLines string // "all" (default), "max-one", or "none" / "zero"
}

ProcessMessageOpts holds the configuration for text processing

type SkinTone added in v0.32.0

type SkinTone rune
const (
	SkinToneNeutral     SkinTone = 0
	SkinToneLight       SkinTone = 0x1f3fb
	SkinToneMediumLight SkinTone = 0x1f3fc
	SkinToneMedium      SkinTone = 0x1f3fd
	SkinToneMediumDark  SkinTone = 0x1f3fe
	SkinToneDark        SkinTone = 0x1f3ff
)

type Summarizer added in v0.33.0

type Summarizer interface {
	Summarize(ctx context.Context, prompt string, thinking string) (string, error)
}

type SummaryOpts added in v0.32.0

type SummaryOpts struct {
	DisableEmoji bool
	CustomEmoji  map[string]string

	DisableMarkdown bool
	BlockquoteChar  string
	InlineCodeChar  string
	MaxLength       int
	UncountedPrefix string
	Unicode         bool
}

SummaryOpts holds configuration for shortening and summarizing text.

Jump to

Keyboard shortcuts

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