Documentation
¶
Index ¶
- Constants
- Variables
- func EmojiFromAlias(alias string, customAliases map[string]string) (string, bool)
- func EmojiReplaceAliases(s string, customAliases map[string]string) string
- func FindClosestIRCColor(hexColor string) string
- func FormatAndShortenSummary(text string, opts SummaryOpts) string
- func FormatFullCodeBlock(text, lexer, indent string, opts ProcessMessageOpts, yield func(string))
- func FormatMarkdownAndEmoji(msg string, disableMarkdown bool, disableEmoji bool, blockQuoteChar string, ...) string
- func GetModel(provider, fallbackModel string, models map[string]string) string
- func Irc2Markdown(msg string) string
- func Markdown2irc(msg string, blockQuoteChar string, inlineCode string) string
- func ProcessMessageText(text string, opts ProcessMessageOpts, yield func(line string))
- func WrapMessage(msg string, maxLen int) string
- type Client
- type CopilotClient
- type IRCColor
- type ProcessMessageOpts
- type SkinTone
- type Summarizer
- type SummaryOpts
Constants ¶
const ( AIGeminiProvider = "gemini" AICopilotProvider = "copilot" AIGitHubProvider = "github" DefaultGeminiModel = "gemini-3.8-flash" DefaultCopilotModel = "gpt-4o-mini" )
const ( AttachmentMarkerStart = "\x00<ATTM\x00" AttachmentMarkerEnd = "\x00ATTM>\x00" )
const BlockQuoteCharDefault = ">"
Variables ¶
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
EmojiFromAlias looks up an emoji by shortcode, supporting with or without surrounding colons.
func EmojiReplaceAliases ¶ added in v0.31.0
EmojiReplaceAliases scans the input and replaces :alias: tokens with Unicode emojis.
func FindClosestIRCColor ¶ added in v0.32.0
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
GetModel resolves the AI model to use based on provider, fallback model, and the models map.
func Irc2Markdown ¶ added in v0.33.0
Irc2Markdown converts IRC formatting back to Markdown, handling links and text styles.
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
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
NewGeminiClient creates a new Gemini AI client authenticated via service account credentials.
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.
type IRCColor ¶ added in v0.32.0
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