<commit_before>package notify

import (
	"errors"

	"github.com/godbus/dbus"
)

// Returns the capabilities of the notification server as a string array
func GetCapabilities() (c []string, err error) {

	connection, err := dbus.SessionBus()
	if err != nil {

		return
	}

	call := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications").Call("org.freedesktop.Notifications.GetCapabilities", 0)

	if call.Err != nil {

		return nil, call.Err
	}

	if err := call.Store(&c); err != nil {

		return nil, err
	}

	return
}

// Create a new notification object with some basic information
func NewNotification(summary, body string) (n *Notification, err error) {

	if len(summary) == 0 {

		return nil, errors.New("The Notification must contain a summary")
	}

	n = &Notification{

		Summary: summary,
		Body:    body,
		Timeout: -1,
	}
	return
}

// Send the notification
func (n *Notification) Send() (id uint32, err error) {

	hints := map[string]dbus.Variant{}
	if len(n.Hints) != 0 {

		for k, v := range n.Hints {

			hints[k] = dbus.MakeVariant(v)
		}
	}

	connection, err := dbus.SessionBus()
	if err != nil {

		return
	}
	obj := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")

	call := obj.Call(
		"org.freedesktop.Notifications.Notify",
		0,
		n.AppName,
		n.ReplacesID,
		n.AppIcon,
		n.Summary,
		n.Body,
		n.Actions,
		hints,
		n.Timeout)

	if call.Err != nil {

		return 0, call.Err
	}

	if err := call.Store(&id); err != nil {

		return 0, err
	}

	return
}

// Closes the notification if it exists using its id
func CloseNotification(id uint32) (err error) {

	connection, err := dbus.SessionBus()
	if err != nil {

		return
	}

	call := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications").Call("org.freedesktop.Notifications.GetCapabilities", 0, id)

	if call.Err != nil {

		return call.Err
	}

	return
}
<commit_msg>Added server capabilities method, categories, and  urgency levels.<commit_after>package notify

import (
	"errors"

	"github.com/godbus/dbus"
)

// Categories
const (
	Device              = "device"
	DeviceAdded         = "device.added"
	DeviceError         = "device.error"
	DeviceRemoved       = "device.removed"
	Email               = "email"
	EmailArrived        = "email.arrived"
	EmailBounced        = "email.bounced"
	Im                  = "im"
	ImError             = "im.error"
	ImReceived          = "im.received"
	Network             = "network"
	NetworkConnected    = "network.connected"
	NetworkDisconnected = "network.disconnected"
	NetworkError        = "network.error"
	Presence            = "presence"
	PresenceOffline     = "presence.offline"
	PresenceOnline      = "presence.online"
	Transfer            = "transfer"
	TransferComplete    = "transfer.complete"
	TransferError       = "transfer.error"
)

// Urgency Levels
const (
	Low      = 0
	Normal   = 1
	Critical = 2
)

// Capabilities
const (
	ActionIcons    = "action-icons"
	Actions        = "actions"
	Body           = "body"
	BodyHyperlinks = "body-hyperlinks"
	BodyImages     = "body-images"
	BodyMarkup     = "body-markup"
	IconMulti      = "icon-multi"
	IconStatic     = "icon-static"
	Persistence    = "persistence"
	Sound          = "sound"
)

type Capabilities struct {
	ActionIcons    bool
	Actions        bool
	Body           bool
	BodyHyperlinks bool
	BodyImages     bool
	BodyMarkup     bool
	IconMulti      bool
	IconStatic     bool
	Persistence    bool
	Sound          bool
}

// Returns the capabilities of the notification server as a string array
func GetCapabilities() (c *Capabilities, err error) {

	connection, err := dbus.SessionBus()
	if err != nil {

		return
	}
	obj := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")

	call := obj.Call("org.freedesktop.Notifications.GetCapabilities", 0)
	if call.Err != nil {

		return nil, call.Err
	}

	c = &Capabilities{}
	s := []string{}

	if err := call.Store(&s); err != nil {

		return nil, err
	}

	for _, v := range s {

		if v == ActionIcons {

			c.ActionIcons = true
			continue
		}

		if v == Actions {

			c.Actions = true
			continue
		}

		if v == Body {

			c.Body = true
			continue
		}

		if v == BodyHyperlinks {

			c.BodyHyperlinks = true
			continue
		}

		if v == BodyImages {

			c.BodyImages = true
			continue
		}

		if v == BodyMarkup {

			c.BodyMarkup = true
			continue
		}

		if v == IconMulti {

			c.IconMulti = true
			continue
		}

		if v == IconStatic {

			c.IconStatic = true
			continue
		}

		if v == Persistence {

			c.Persistence = true
			continue
		}

		if v == Sound {

			c.Sound = true
			continue
		}
	}

	return
}

// Create a new notification object with some basic information
func NewNotification(summary, body string) (n *Notification, err error) {

	if len(summary) == 0 {

		return nil, errors.New("The Notification must contain a summary")
	}

	n = &Notification{

		Summary: summary,
		Body:    body,
		Timeout: -1,
	}
	return
}

// Send the notification
func (n *Notification) Send() (id uint32, err error) {

	hints := map[string]dbus.Variant{}
	if len(n.Hints) != 0 {

		for k, v := range n.Hints {

			hints[k] = dbus.MakeVariant(v)
		}
	}

	connection, err := dbus.SessionBus()
	if err != nil {

		return
	}
	obj := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")

	call := obj.Call(
		"org.freedesktop.Notifications.Notify",
		0,
		n.AppName,
		n.ReplacesID,
		n.AppIcon,
		n.Summary,
		n.Body,
		n.Actions,
		hints,
		n.Timeout)

	if call.Err != nil {

		return 0, call.Err
	}

	if err := call.Store(&id); err != nil {

		return 0, err
	}

	return
}

// Closes the notification if it exists using its id
func CloseNotification(id uint32) (err error) {

	connection, err := dbus.SessionBus()
	if err != nil {

		return
	}
	obj := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")

	call := obj.Call("org.freedesktop.Notifications.GetCapabilities", 0, id)
	if call.Err != nil {

		return call.Err
	}

	return
}

type ServerInformation struct {
	Name        string
	Vendor      string
	Version     string
	SpecVersion string
}

// Gets information about the notification server
func GetServerInformation() (i *ServerInformation, err error) {

	connection, err := dbus.SessionBus()
	if err != nil {

		return
	}
	obj := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")

	call := obj.Call("org.freedesktop.Notifications.GetServerInformation", 0)
	if call.Err != nil {

		return nil, call.Err
	}

	i = &ServerInformation{}
	if err := call.Store(&i.Name, i.Vendor, i.Version, i.SpecVersion); err != nil {

		return nil, err
	}

	return
}

{'fraction_non_alphanumeric': 0.12226032503354704, 'fraction_numerical': 0.004174742806023557, 'mean_word_length': 2.8507462686567164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3776332', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2237, 'n_words': 585}