utils

package
v0.0.0-...-78a2729 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinCommandLen minimal length of standard command
	MinCommandLen = 2
	// MinAdminCommandLen minimal length of admin command
	MinAdminCommandLen = 3
)

Variables

View Source
var (
	// AdminRoomID of the scheduler
	AdminRoomID id.RoomID

	// ErrWrongDate is returned when date is in wrong format
	ErrWrongDate = errors.New("wrong date format")
)

Functions

func CanUseAdmin

func CanUseAdmin(useAdmin bool, adminRoomID, actualRoomID id.RoomID) bool

CanUseAdmin checks if recurring/schedule/run can UseAdmin = useAdmin

func Command

func Command(evt *event.Event) ([]string, bool)

Command parse command from matrix event

func File

func File(name, content string) *mautrix.ReqUploadMedia

File parses name and content to matrix upload media request

func HomeserverCommand

func HomeserverCommand(evt *event.Event) (string, string)

Homeserver parse homeserver AND command from matrix event

func MapKeys

func MapKeys[T string, V any](data map[string]V) []string

MapKeys returns map keys only

func MessageCommand

func MessageCommand(message string) (string, string)

MessageCommand parses a message (eg 'run restart irc') to command name and args (eg: "restart", "irc")

func MessageToSchedule

func MessageToSchedule(message string) (string, string, string)

MessageToScheduler parses a schedule message (eg 'schedule resart 2006-01-02 15:04 irc') to command message, datetime and args (eg: "run restart", "2006-01-02 15:04", "irc")

func Output

func Output(out []byte, max int) string

Output parses exec.Cmd output

func OutputToMessage

func OutputToMessage(prefix, command string, out []byte, err error, logOnError bool, logsize int, useAdmin bool, homeserver string) (string, string)

OutputToMessage parses run output to human-friendly message and full log output

func ParseCommandTemplate

func ParseCommandTemplate(command string, vars any) (*exec.Cmd, string, error)

ParseCommandTemplate parses a command template and returns a executable command

func ParseDomains

func ParseDomains(text string) []string

ParseDomains parses the output of the list command (comma-separated list of domains) and returns a list of domains

func RelativeDate

func RelativeDate(in string) (time.Time, error)

RelativeDate converts "Tuesday 20:00" to time.Time

func SortRelativeDate

func SortRelativeDate(slice []string)

SortRelativeDate sorts slice by relative date

func Uniq

func Uniq(slice []string) []string

Uniq removes duplicates from slice

Types

This section is empty.

Jump to

Keyboard shortcuts

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