Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest Go is 1.26 now :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, though my OS only has packages for go1.25.7, and I'd like to avoid having to manually build/upgrade go.


- name: Check formatting
run: |
if [ "$(gofmt -l . | wc -l)" -gt 0 ]; then
echo "Unformatted files found:"
gofmt -l .
exit 1
fi

- name: Run unit tests
run: go test -v -race ./...
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22 as build-env
FROM golang:1.25 as build-env

WORKDIR /go/src/github.com/fluffle/sp0rkle
ADD . /go/src/github.com/fluffle/sp0rkle
Expand Down
3 changes: 1 addition & 2 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bot
import (
"context"
"flag"
"io/ioutil"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -124,7 +123,7 @@ func GetSecret(s string) string {
if strings.HasPrefix(s, "$") {
return os.ExpandEnv(s)
} else if strings.HasPrefix(s, "<") {
if bytes, err := ioutil.ReadFile(s[1:]); err == nil {
if bytes, err := os.ReadFile(s[1:]); err == nil {
return strings.TrimSuffix(string(bytes), "\n")
}
return ""
Expand Down
8 changes: 4 additions & 4 deletions bot/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ func (ctx *Context) Storable() (Nick, Chan) {
}

// ReplyN() adds a prefix of "nick: " to the reply text,
func (ctx *Context) ReplyN(fm string, args ...interface{}) {
args = append([]interface{}{ctx.Nick}, args...)
func (ctx *Context) ReplyN(fm string, args ...any) {
args = append([]any{ctx.Nick}, args...)
ctx.Reply("%s: "+fm, args...)
}

// whereas Reply() does not.
func (ctx *Context) Reply(fm string, args ...interface{}) {
func (ctx *Context) Reply(fm string, args ...any) {
ctx.conn.Privmsg(ctx.Target(),
ctx.rws.Rewrite(fmt.Sprintf(fm, args...), ctx))
}

func (ctx *Context) Do(fm string, args ...interface{}) {
func (ctx *Context) Do(fm string, args ...any) {
ctx.conn.Action(ctx.Target(),
ctx.rws.Rewrite(fmt.Sprintf(fm, args...), ctx))
}
Expand Down
2 changes: 1 addition & 1 deletion collections/conf/both.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (b both) Float(key string, value ...float64) float64 {
return mongo
}

func (b both) Value(key string, value ...interface{}) interface{} {
func (b both) Value(key string, value ...any) any {
switch b.Check() {
case db.MONGO_ONLY:
return b.mongo.Value(key, value...)
Expand Down
2 changes: 1 addition & 1 deletion collections/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Zone(nick string, tz ...string) string {

type Entry struct {
Ns, Key string
Value interface{}
Value any
}

func (e Entry) K() db.Key {
Expand Down
6 changes: 3 additions & 3 deletions collections/conf/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
type inMem struct {
sync.Mutex
ns string
data map[string]interface{}
data map[string]any
}

func InMem(ns string) Namespace {
return &inMem{ns: ns, data: make(map[string]interface{})}
return &inMem{ns: ns, data: make(map[string]any)}
}

func (ns *inMem) All() Entries {
Expand Down Expand Up @@ -63,7 +63,7 @@ func (ns *inMem) Float(key string, value ...float64) float64 {
return 0
}

func (ns *inMem) Value(key string, value ...interface{}) interface{} {
func (ns *inMem) Value(key string, value ...any) any {
ns.Lock()
defer ns.Unlock()
if len(value) > 0 {
Expand Down
8 changes: 4 additions & 4 deletions collections/conf/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Namespace interface {
String(key string, value ...string) string
Int(key string, value ...int) int
Float(key string, value ...float64) float64
Value(key string, value ...interface{}) interface{}
Value(key string, value ...any) any
Delete(key string)
}

Expand All @@ -27,14 +27,14 @@ func (ns *namespace) K() db.Key {

var _ db.Keyer = (*namespace)(nil)

func (ns *namespace) set(key string, value interface{}) {
func (ns *namespace) set(key string, value any) {
e := &Entry{Ns: ns.ns, Key: key, Value: value}
if err := ns.Put(e); err != nil {
logging.Error("Couldn't set config entry %q: %v", e, err)
}
}

func (ns *namespace) get(key string) interface{} {
func (ns *namespace) get(key string) any {
e := &Entry{Ns: ns.ns, Key: key}
if err := ns.Get(e.K(), e); err != nil && err != mgo.ErrNotFound && err != bbolt.ErrTxNotWritable {
logging.Error("Couldn't get config entry for ns=%q key=%q: %v", ns.ns, key, err)
Expand Down Expand Up @@ -84,7 +84,7 @@ func (ns *namespace) Float(key string, value ...float64) float64 {
return 0
}

func (ns *namespace) Value(key string, value ...interface{}) interface{} {
func (ns *namespace) Value(key string, value ...any) any {
if len(value) > 0 {
ns.set(key, value[0])
return value[0]
Expand Down
4 changes: 2 additions & 2 deletions collections/factoids/factoids.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package factoids

import (
"fmt"
"math/rand"
"math/rand/v2"
"strings"
"time"

Expand Down Expand Up @@ -273,7 +273,7 @@ func (fc *Collection) GetPseudoRand(key string) *Factoid {
logging.Debug("Creating seen data for key '%s'.", key)
fc.seen[key] = make(map[bson.ObjectId]bool)
}
res := filtered[rand.Intn(count)]
res := filtered[rand.IntN(count)]
logging.Debug("Storing id %v for key '%s'.", res.Id(), key)
fc.seen[key][res.Id()] = true
return res
Expand Down
4 changes: 2 additions & 2 deletions collections/quotes/quotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package quotes

import (
"fmt"
"math/rand"
"math/rand/v2"
"sync/atomic"
"time"

Expand Down Expand Up @@ -217,7 +217,7 @@ func (qc *Collection) GetPseudoRand(regex string) *Quote {
logging.Debug("Creating seen data for regex %q.", regex)
qc.seen[regex] = map[bson.ObjectId]bool{}
}
res := filtered[rand.Intn(count)]
res := filtered[rand.IntN(count)]
logging.Debug("Storing id %v for regex %q.", res.Id_, regex)
qc.seen[regex][res.Id_] = true
return res
Expand Down
6 changes: 3 additions & 3 deletions collections/reminders/reminders.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package reminders

import (
"fmt"
"sort"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -164,8 +164,8 @@ func (rs Reminders) Strings() []string {
}

func (rs Reminders) sortByRemindAt() {
sort.Slice(rs, func(i, j int) bool {
return rs[i].RemindAt.Before(rs[j].RemindAt)
slices.SortFunc(rs, func(a, b *Reminder) int {
return a.RemindAt.Compare(b.RemindAt)
})
}

Expand Down
11 changes: 4 additions & 7 deletions collections/seen/seen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package seen

import (
"fmt"
"sort"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -133,11 +133,6 @@ func (ns Nicks) Strings() []string {
return s
}

// Implement sort.Interface to sort by descending timestamp.
func (ns Nicks) Len() int { return len(ns) }
func (ns Nicks) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }
func (ns Nicks) Less(i, j int) bool { return ns[i].Timestamp.After(ns[j].Timestamp) }

type migrator struct {
mongo, bolt db.Collection
}
Expand Down Expand Up @@ -245,7 +240,9 @@ func (sc *Collection) SeenAnyMatching(rx string) []string {
if err := sc.Match("Nick", rx, &ns); err != nil {
return nil
}
sort.Sort(ns)
slices.SortFunc(ns, func(a, b *Nick) int {
return b.Timestamp.Compare(a.Timestamp)
})
seen := make(map[string]bool)
res := make([]string, 0, len(ns))
for _, n := range ns {
Expand Down
4 changes: 2 additions & 2 deletions collections/urls/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package urls

import (
"fmt"
"math/rand"
"math/rand/v2"
"time"

"github.com/fluffle/golog/logging"
Expand Down Expand Up @@ -225,7 +225,7 @@ func (uc *Collection) GetRand(regex string) *Url {
logging.Debug("Creating seen data for regex %q.", regex)
uc.seen[regex] = map[bson.ObjectId]bool{}
}
url := filtered[rand.Intn(count)]
url := filtered[rand.IntN(count)]
logging.Debug("Storing id %v for regex %q.", url.Id_, regex)
uc.seen[regex][url.Id_] = true
return url
Expand Down
2 changes: 1 addition & 1 deletion db/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func isBson(data []byte) bool {
return bytes.Equal(data[:prefixLen], bsonPrefix)
}

func toBson(value interface{}) ([]byte, error) {
func toBson(value any) ([]byte, error) {
marshalled, err := bson.Marshal(value)
if err != nil {
return nil, fmt.Errorf("bson marshal: %w", err)
Expand Down
16 changes: 8 additions & 8 deletions db/both.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func dupeR(vt reflect.Type, vv reflect.Value) reflect.Value {

// This function rigourously tested for all of 15 minutes
// at https://play.golang.org/p/IrEWIxm_PEH ;-)
func dupe(in interface{}) interface{} {
func dupe(in any) any {
return dupeR(reflect.TypeOf(in), reflect.ValueOf(in)).Interface()
}

Expand All @@ -64,7 +64,7 @@ func (b *Both) compareErr(method string, mErr, bErr error) error {
return bErr
}

func (b *Both) compare(method, key string, mValue, bValue interface{}, mErr, bErr error) error {
func (b *Both) compare(method, key string, mValue, bValue any, mErr, bErr error) error {
// Mongo returns ErrNotFound, Bolt returns nil, nil.
if errors.Is(mErr, mgo.ErrNotFound) && bErr == nil && bValue == nil {
return nil
Expand All @@ -82,7 +82,7 @@ func (b *Both) compare(method, key string, mValue, bValue interface{}, mErr, bEr
return b.compareErr(method, mErr, bErr)
}

func (b *Both) Get(key Key, value interface{}) error {
func (b *Both) Get(key Key, value any) error {
other := dupe(value)
switch b.Check() {
case MONGO_ONLY:
Expand All @@ -99,7 +99,7 @@ func (b *Both) Get(key Key, value interface{}) error {
return ErrInvalidState
}

func (b *Both) Match(key, re string, value interface{}) error {
func (b *Both) Match(key, re string, value any) error {
other := dupe(value)
switch b.Check() {
case MONGO_ONLY:
Expand All @@ -116,7 +116,7 @@ func (b *Both) Match(key, re string, value interface{}) error {
return ErrInvalidState
}

func (b *Both) All(key Key, value interface{}) error {
func (b *Both) All(key Key, value any) error {
other := dupe(value)
switch b.Check() {
case MONGO_ONLY:
Expand All @@ -133,7 +133,7 @@ func (b *Both) All(key Key, value interface{}) error {
return ErrInvalidState
}

func (b *Both) Put(value interface{}) error {
func (b *Both) Put(value any) error {
switch b.Check() {
case MONGO_ONLY:
return b.MongoC.Put(value)
Expand All @@ -145,7 +145,7 @@ func (b *Both) Put(value interface{}) error {
return ErrInvalidState
}

func (b *Both) BatchPut(value interface{}) error {
func (b *Both) BatchPut(value any) error {
switch b.Check() {
case MONGO_ONLY:
// BatchPut is a bolt thing, fail before migration
Expand All @@ -156,7 +156,7 @@ func (b *Both) BatchPut(value interface{}) error {
return ErrInvalidState
}

func (b *Both) Del(value interface{}) error {
func (b *Both) Del(value any) error {
switch b.Check() {
case MONGO_ONLY:
return b.MongoC.Del(value)
Expand Down
Loading