M handlers.go => handlers.go +8 -1
@@ 5,6 5,7 @@ import (
"errors"
"fmt"
"log"
+ "strings"
"git.sr.ht/~handlerug/handlebot/database"
"git.sr.ht/~handlerug/handlebot/geocoding"
@@ 31,7 32,7 @@ func handleJisho(ctx context.Context, req HandlerRequest) (string, error) {
return humanizeJisho(result), nil
}
-func HandleWeather(ctx context.Context, req HandlerRequest) (string, error) {
+func handleWeather(ctx context.Context, req HandlerRequest) (string, error) {
db := database.ForContext(ctx)
f := weather.ForContext(ctx)
geocoder := geocoding.ForContext(ctx)
@@ 39,6 40,12 @@ func HandleWeather(ctx context.Context, req HandlerRequest) (string, error) {
query := req.Args
server := req.ServerHost
nick := req.Event.Source.Name
+
+ if strings.HasPrefix(query, "@") && !strings.Contains(query, " ") {
+ nick = query[1:]
+ query = ""
+ }
+
if query == "" {
var err error
query, err = db.GetUserLocation(ctx, server, nick)
M main.go => main.go +1 -1
@@ 121,7 121,7 @@ func main() {
ServerHost: cfg.IRC.Server,
CmdPrefix: cfg.CommandPrefix,
})
- h.Add(HandleWeather, "weather", "w")
+ h.Add(handleWeather, "weather", "w")
h.Add(handleWolframAlpha, "wolframalpha", "wa")
h.Add(handleJisho, "jisho")
h.Add(handleBots, "bots")