mirror of
https://github.com/jeremyd/ergo.git
synced 2026-07-11 19:08:09 -07:00
initial persistent history implementation
This commit is contained in:
+21
-2
@@ -5,7 +5,13 @@ package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
IRCv3TimestampFormat = "2006-01-02T15:04:05.000Z"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -45,9 +51,9 @@ func ArgsToStrings(maxLength int, arguments []string, delim string) []string {
|
||||
|
||||
func StringToBool(str string) (result bool, err error) {
|
||||
switch strings.ToLower(str) {
|
||||
case "on", "true", "t", "yes", "y":
|
||||
case "on", "true", "t", "yes", "y", "disabled":
|
||||
result = true
|
||||
case "off", "false", "f", "no", "n":
|
||||
case "off", "false", "f", "no", "n", "enabled":
|
||||
result = false
|
||||
default:
|
||||
err = ErrInvalidParams
|
||||
@@ -63,3 +69,16 @@ func SafeErrorParam(param string) string {
|
||||
}
|
||||
return param
|
||||
}
|
||||
|
||||
type IncompatibleSchemaError struct {
|
||||
CurrentVersion string
|
||||
RequiredVersion string
|
||||
}
|
||||
|
||||
func (err *IncompatibleSchemaError) Error() string {
|
||||
return fmt.Sprintf("Database requires update. Expected schema v%s, got v%s", err.RequiredVersion, err.CurrentVersion)
|
||||
}
|
||||
|
||||
func NanoToTimestamp(nanotime int64) string {
|
||||
return time.Unix(0, nanotime).Format(IRCv3TimestampFormat)
|
||||
}
|
||||
|
||||
@@ -18,14 +18,6 @@ var (
|
||||
validHostnameLabelRegexp = regexp.MustCompile(`^[0-9A-Za-z.\-]+$`)
|
||||
)
|
||||
|
||||
// AddrIsLocal returns whether the address is from a trusted local connection (loopback or unix).
|
||||
func AddrIsLocal(addr net.Addr) bool {
|
||||
if tcpaddr, ok := addr.(*net.TCPAddr); ok {
|
||||
return tcpaddr.IP.IsLoopback()
|
||||
}
|
||||
return AddrIsUnix(addr)
|
||||
}
|
||||
|
||||
// AddrToIP returns the IP address for a net.Addr; unix domain sockets are treated as IPv4 loopback
|
||||
func AddrToIP(addr net.Addr) net.IP {
|
||||
if tcpaddr, ok := addr.(*net.TCPAddr); ok {
|
||||
|
||||
+5
-8
@@ -23,9 +23,9 @@ type MessagePair struct {
|
||||
// SplitMessage represents a message that's been split for sending.
|
||||
// Two possibilities:
|
||||
// (a) Standard message that can be relayed on a single 512-byte line
|
||||
// (MessagePair contains the message, Wrapped == nil)
|
||||
// (MessagePair contains the message, Split == nil)
|
||||
// (b) multiline message that was split on the client side
|
||||
// (Message == "", Wrapped contains the split lines)
|
||||
// (Message == "", Split contains the split lines)
|
||||
type SplitMessage struct {
|
||||
Message string
|
||||
Msgid string
|
||||
@@ -36,7 +36,7 @@ type SplitMessage struct {
|
||||
func MakeMessage(original string) (result SplitMessage) {
|
||||
result.Message = original
|
||||
result.Msgid = GenerateSecretToken()
|
||||
result.Time = time.Now().UTC()
|
||||
result.SetTime()
|
||||
|
||||
return
|
||||
}
|
||||
@@ -52,7 +52,8 @@ func (sm *SplitMessage) Append(message string, concat bool) {
|
||||
}
|
||||
|
||||
func (sm *SplitMessage) SetTime() {
|
||||
sm.Time = time.Now().UTC()
|
||||
// strip the monotonic time, it's a potential source of problems:
|
||||
sm.Time = time.Now().UTC().Round(0)
|
||||
}
|
||||
|
||||
func (sm *SplitMessage) LenLines() int {
|
||||
@@ -88,10 +89,6 @@ func (sm *SplitMessage) IsRestrictedCTCPMessage() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (sm *SplitMessage) IsMultiline() bool {
|
||||
return sm.Message == "" && len(sm.Split) != 0
|
||||
}
|
||||
|
||||
func (sm *SplitMessage) Is512() bool {
|
||||
return sm.Message != ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user