94 lines
2.1 KiB
Go
94 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"log/slog"
|
|
"os"
|
|
"time"
|
|
|
|
_ "github.com/joho/godotenv/autoload"
|
|
"github.com/lmittmann/tint"
|
|
"go.uber.org/fx"
|
|
"go.uber.org/fx/fxevent"
|
|
"tuxpa.in/a/irc/pkg/capability"
|
|
"tuxpa.in/a/irc/pkg/capability/cap_servertime"
|
|
"tuxpa.in/a/irc/pkg/ircconn"
|
|
"tuxpa.in/a/irc/pkg/ircv3"
|
|
"tuxpa.in/a/irc/plugins/auth"
|
|
"tuxpa.in/a/irc/plugins/useful"
|
|
"tuxpa.in/a/irc/src/lainbot"
|
|
)
|
|
|
|
func exec(log *slog.Logger) error {
|
|
|
|
tlsConfig := &tls.Config{}
|
|
conn, err := tls.Dial("tcp", "put.gay:6697", tlsConfig)
|
|
//conn, err := net.Dial("tcp", "irc.libera.chat:6667")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ctx := context.Background()
|
|
name := os.Getenv("LAIN_NICKNAME")
|
|
saslPassword := os.Getenv("LAIN_PASSWORD")
|
|
reg := &capability.Registrar{}
|
|
reg.Enable(&cap_servertime.Capability{})
|
|
instance := &lainbot.Instance{
|
|
Nuh: &ircv3.NUH{
|
|
Name: name,
|
|
User: "lain",
|
|
Host: "wired",
|
|
},
|
|
}
|
|
|
|
reg.Enable(&auth.SaslPlain{
|
|
Username: name,
|
|
Password: saslPassword,
|
|
})
|
|
reg.Enable(&auth.Nick{Nick: name})
|
|
reg.Enable(&auth.User{Username: "lain", Realname: "lain a", Hostname: "wired", Server: "wired"})
|
|
|
|
handler := ircv3.Chain(
|
|
func(next ircv3.Handler) ircv3.Handler {
|
|
return ircv3.HandlerFunc(func(w ircv3.MessageWriter, e *ircv3.Event) {
|
|
log.Info("in <<", "msg", e.Msg.String())
|
|
next.Handle(w, e)
|
|
})
|
|
},
|
|
reg.NewMiddleware(),
|
|
(&useful.Autojoin{Channels: []string{"#lainmaxxing"}}).Middleware,
|
|
(&useful.Pong{}).Middleware,
|
|
func(h ircv3.Handler) ircv3.Handler {
|
|
return ircv3.HandlerFunc(func(w ircv3.MessageWriter, e *ircv3.Event) {
|
|
if e.Type != ircv3.EventTypeIRC {
|
|
return
|
|
}
|
|
h.Handle(w, e)
|
|
})
|
|
},
|
|
).Handler(instance)
|
|
mw := &ircconn.MessageWriter{R: conn, Log: log}
|
|
err = ircconn.Serve(ctx, conn, mw, handler)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
lain := fx.New(
|
|
fx.Provide(func() *slog.Logger {
|
|
return slog.New(
|
|
tint.NewHandler(os.Stderr, &tint.Options{
|
|
Level: slog.LevelDebug,
|
|
TimeFormat: time.Kitchen,
|
|
}))
|
|
}),
|
|
fx.WithLogger(func(s *slog.Logger) fxevent.Logger {
|
|
return &fxevent.SlogLogger{Logger: s}
|
|
}),
|
|
fx.Invoke(exec),
|
|
)
|
|
lain.Run()
|
|
}
|