Skip to content
Merged
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
11 changes: 10 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,16 @@ plugins:
docker: {enabled: true, timeout_seconds: 8, max_length: 300}
```

`status`, `calc`, `foods`, `sports`, `car`, and `weapons` are local. The
`calc`, `foods`, `sports`, `car`, and `weapons` are local. Without a target,
`status` (and its `uptime`/`ping` aliases) also uses only local bot state.
With a public hostname or HTTP(S) URL it checks that website's HTTP status
and response time on port 80/443, independently of the IRC network. Website
checks default to a six-second timeout; `plugins.status.timeout_seconds`
accepts 1–15 seconds. They are not ICMP probes or historical uptime monitors.
See [Status and uptime](plugins.md#status-and-uptime) for examples and safety
limits.

The
`ask` plugin uses DuckDuckGo Search Assist first when `search_assist_enabled` is true.
This is a best-effort web integration that first uses the lightweight Search
Assist request and then, when enabled, a local Chromium/Chrome browser to read
Expand Down
35 changes: 32 additions & 3 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Plugins are enabled or disabled under plugins.<name>.enabled in config.yaml.
- port: local bidirectional well-known port/service lookup
- audit: package vulnerability discovery through OSV
- docker: Docker Hub image metadata lookup
- status: local connection, uptime, and counter status
- status: public website HTTP status/response time, or local bot connection, uptime, and counters
- xkcd: latest or numbered XKCD comics
- lastfm: current or recently played Last.fm tracks
- cats: short cat facts
Expand Down Expand Up @@ -839,8 +839,37 @@ returns one cleaned and length-limited message, and does not download images.

## Status and uptime

These commands use only GoBot's local state and do not call an external
service:
With a hostname or HTTP(S) URL, these commands check that website from the
GoBot host, independently of the IRC network:

~~~text
!status example.org
!status https://example.org/health
!ping example.org
!ping https://example.org/
!uptime example.org
~~~

Bare hostnames default to HTTPS. Results include the HTTP status code and
elapsed HTTP response time (including connection setup and redirects), not
ICMP ping/round-trip time. HTTP 403/404/429 responses still mean the server
responded; they are reported accurately rather than called a connection
failure. DNS, TLS verification, timeout, and blocked-target failures are
reported separately. A single check cannot measure a remote site's historical
uptime, including when invoked as `!uptime <target>`.

Only public HTTP(S) targets on ports 80/443 are allowed. Credentials, private,
loopback, link-local, shared, reserved, and other special-purpose addresses
are blocked, including redirects and DNS answers containing a private address.
Connections are pinned to validated IPs; environment proxies are disabled and
TLS certificates are verified. Response headers and redirects are bounded,
page bodies are not read or parsed, and URL query parameters/fragments are not
echoed. Up to four checks can run concurrently across networks. Configure
`plugins.status.timeout_seconds` from 1 to 15 seconds (default 6); existing
command cooldowns also apply.

Without a target, the commands retain their original local-only behavior and
do not call an external service:

~~~text
!status
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/variablenix/GoBot
go 1.26.10

require (
github.com/agnivade/levenshtein v1.2.1
github.com/agnivade/levenshtein v1.2.2
github.com/chromedp/chromedp v0.21.0
github.com/spf13/viper v1.21.0
go.etcd.io/bbolt v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/agnivade/levenshtein v1.2.1 h1:EHBY3UOn1gwdy/VbFwgo4cxecRznFk7fKWN1KOX7eoM=
github.com/agnivade/levenshtein v1.2.1/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU=
github.com/agnivade/levenshtein v1.2.2 h1:fI8RgiztYX1Nn5pBHHqQ9EMCCklhrmXqPRIedFmx5M4=
github.com/agnivade/levenshtein v1.2.2/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/chromedp/cdproto v0.157.8 h1:Tkq0AjsUlC3Z4sJfHBzV/uAAxnTF/AZyuSTjfV/1gvk=
Expand Down
53 changes: 47 additions & 6 deletions plugins/status.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,70 @@
package plugins

import (
"context"
"fmt"
"net/http"
"strings"
"time"

"github.com/variablenix/GoBot/bot"
"github.com/variablenix/GoBot/storage"
)

// Status reports local process and connection state without making a network
// request. It is intentionally useful when external APIs are unavailable.
type Status struct{}
// Status reports local state without a target, or checks a public website when
// a host/URL is supplied. Website checks do not depend on the IRC network.
type Status struct {
client *http.Client
timeout time.Duration
}

func (p *Status) Name() string { return "status" }
func (p *Status) Commands() []string { return []string{"status", "uptime", "ping"} }
func (p *Status) Help() string {
return "!status — show connection, uptime, and counters (aliases: !uptime, !ping)"
return "!status [public host|http(s) URL] — HTTP status and response time (ports 80/443); without a target: bot connection, uptime, counters (aliases: !uptime, !ping; HTTP, not ICMP)"
}
func (p *Status) Init(cfg bot.PluginConfig, _ *storage.DB) error {
seconds := cfg.Int("timeout_seconds", 6)
if seconds < 1 || seconds > 15 {
seconds = 6
}
p.timeout = time.Duration(seconds) * time.Second
p.client = newStatusHTTPClient(p.timeout)
return nil
}
func (p *Status) Init(_ bot.PluginConfig, _ *storage.DB) error { return nil }

func (p *Status) Handle(b *bot.Bot, m bot.Message) bool {
cmd, _, ok := bot.IsCommand(m, b.Config.CommandPrefix)
cmd, arg, ok := bot.IsCommand(m, b.Config.CommandPrefix)
if !ok || !isStatusCommand(cmd) {
return false
}
if strings.TrimSpace(arg) != "" {
target, err := parseStatusTarget(arg)
if err != nil {
b.Send(m.ReplyTarget(), ircColor(ircYellow, "Use one public hostname or http(s) URL on port 80/443; private addresses and credentials are not allowed."))
return true
}
select {
case statusCheckSlots <- struct{}{}:
defer func() { <-statusCheckSlots }()
default:
b.Send(m.ReplyTarget(), ircColor(ircYellow, "Website checks are busy; try again shortly."))
return true
}
timeout := p.timeout
if timeout <= 0 {
timeout = 6 * time.Second
}
client := p.client
if client == nil {
client = newStatusHTTPClient(timeout)
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
result, err := checkStatusSite(ctx, client, target)
b.Send(m.ReplyTarget(), formatStatusSite(target, result, err))
return true
}
if b.Stats == nil {
b.Send(m.ReplyTarget(), ircColor(ircYellow, "GoBot status is unavailable"))
return true
Expand Down
Loading
Loading