Skip to content

Commit beba7dc

Browse files
authored
Fix unused and ineffectual variables (#32)
1 parent 9c2886c commit beba7dc

4 files changed

Lines changed: 51 additions & 5 deletions

File tree

cmd/agentbbs/admin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ func (r *liveReg) List() []admin.Live {
7676
// Kill closes a live session by id. Returns false if it is already gone.
7777
func (r *liveReg) Kill(id int64) bool {
7878
r.mu.Lock()
79+
defer r.mu.Unlock()
7980
e, ok := r.m[id]
80-
r.mu.Unlock()
8181
if !ok {
8282
return false
8383
}
84+
delete(r.m, id)
8485
_ = e.s.Close()
8586
return true
8687
}

cmd/agentbbs/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import (
7373
"github.com/profullstack/agentbbs/internal/store"
7474
"github.com/profullstack/agentbbs/internal/tor"
7575
"github.com/profullstack/agentbbs/plugins/about"
76+
"github.com/profullstack/agentbbs/plugins/hello"
7677
"github.com/profullstack/agentbbs/plugins/agentgames"
7778
"github.com/profullstack/agentbbs/plugins/arcade"
7879
"github.com/profullstack/agentbbs/plugins/members"
@@ -175,7 +176,7 @@ func main() {
175176
a.mm = games.NewMatchmaker(a.gamesReg, a.st,
176177
time.Duration(envInt("AGENTBBS_GAME_MOVE_TIMEOUT", 15))*time.Second,
177178
time.Duration(envInt("AGENTBBS_GAME_QUEUE_WAIT", 120))*time.Second)
178-
a.registry = []plugin.Plugin{arcade.Plugin{}, agentgames.New(a.gamesReg), members.Plugin{}, qryptinviteplugin.Plugin{}, about.Plugin{}}
179+
a.registry = []plugin.Plugin{arcade.Plugin{}, agentgames.New(a.gamesReg), members.Plugin{}, qryptinviteplugin.Plugin{}, about.Plugin{}, hello.Plugin{}}
179180

180181
// Custom domains: maintain the symlink farm Caddy serves and answer its
181182
// on-demand-TLS "ask" query so certs are only issued for mapped domains.

internal/store/store.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package store
55
import (
66
"database/sql"
77
"errors"
8+
"fmt"
89
"strings"
910
"time"
1011

@@ -42,7 +43,9 @@ func scanUser(sc interface{ Scan(...any) error }) (User, error) {
4243
u.EmailVerified = verified != 0
4344
u.Premium = premium != 0
4445
u.Banned = banned != 0
45-
u.CreatedAt, _ = time.Parse(time.RFC3339, created)
46+
if t, err := time.Parse(time.RFC3339, created); err == nil {
47+
u.CreatedAt = t
48+
}
4649
return u, nil
4750
}
4851

@@ -516,8 +519,12 @@ func (s *sqliteStore) EnsureUser(name, kind, fp string) (User, error) {
516519
if err != nil {
517520
return User{}, err
518521
}
519-
id, _ := res.LastInsertId()
520-
return User{ID: id, Name: name, Kind: kind, PubKeyFP: fp, CreatedAt: time.Now().UTC()}, nil
522+
id, err := res.LastInsertId()
523+
if err != nil {
524+
return User{}, fmt.Errorf("get user id after insert: %w", err)
525+
}
526+
return User{
527+
ID: id, Name: name, Kind: kind, PubKeyFP: fp, CreatedAt: time.Now().UTC()}, nil
521528
case err != nil:
522529
return User{}, err
523530
}

plugins/hello/hello.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package hello
2+
3+
import (
4+
tea "github.com/charmbracelet/bubbletea"
5+
"github.com/profullstack/agentbbs/internal/auth"
6+
"github.com/profullstack/agentbbs/internal/plugin"
7+
"github.com/profullstack/agentbbs/internal/ui"
8+
)
9+
10+
type Plugin struct{}
11+
12+
func (Plugin) ID() string { return "hello" }
13+
func (Plugin) Title() string { return "Hello World" }
14+
func (Plugin) Description() string { return "A simple hello world plugin by Milla-Agent" }
15+
func (Plugin) RequiresAuth() bool { return false }
16+
17+
func (Plugin) New(user auth.User, _ plugin.Context) tea.Model {
18+
return model{}
19+
}
20+
21+
type model struct{}
22+
23+
func (m model) Init() tea.Cmd { return nil }
24+
25+
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
26+
if k, ok := msg.(tea.KeyMsg); ok {
27+
switch k.String() {
28+
case "esc", "q", "enter", "ctrl+c", " ":
29+
return m, plugin.Exit
30+
}
31+
}
32+
return m, nil
33+
}
34+
35+
func (m model) View() string {
36+
return ui.Frame.Render("Hello from Milla-Agent!\nThis is a simple module submission.\n\nPress 'q' or 'esc' to exit.")
37+
}

0 commit comments

Comments
 (0)