79 lines
1.8 KiB
Go
79 lines
1.8 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/ircconn"
|
|
"tuxpa.in/a/irc/pkg/ircmw"
|
|
"tuxpa.in/a/irc/pkg/ircv3"
|
|
"tuxpa.in/a/irc/plugins/auth"
|
|
"tuxpa.in/a/irc/plugins/useful"
|
|
)
|
|
|
|
func exec(log *slog.Logger) error {
|
|
tlsConfig := &tls.Config{}
|
|
conn, err := tls.Dial("tcp", "irc.libera.chat:6697", tlsConfig)
|
|
//conn, err := net.Dial("tcp", "irc.libera.chat:6667")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
irc := ircconn.New(log, conn, conn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ctx := context.Background()
|
|
name := os.Getenv("LAIN_NICKNAME")
|
|
saslPassword := os.Getenv("LAIN_PASSWORD")
|
|
c := &ircmw.Capabilities{}
|
|
handler := ircv3.Chain(
|
|
func(next ircv3.Handler) ircv3.Handler {
|
|
return ircv3.HandlerFunc(func(ctx context.Context, w ircv3.MessageWriter, m *ircv3.Message) {
|
|
log.Info("in <<", "msg", m.String())
|
|
next.Handle(ctx, w, m)
|
|
})
|
|
},
|
|
c.Middleware,
|
|
(&auth.SaslPlain{
|
|
Username: name,
|
|
Password: saslPassword,
|
|
}).Middleware,
|
|
(&auth.Nick{Nick: name}).Middleware,
|
|
(&auth.User{Username: "lain", Realname: "lain a", Hostname: "wired", Server: "wired"}).Middleware,
|
|
ircmw.CapabilityServerTime,
|
|
(&useful.Autojoin{Channels: []string{"#lainmaxxing"}}).Middleware,
|
|
).Handler(ircv3.HandlerFunc(func(ctx context.Context, w ircv3.MessageWriter, m *ircv3.Message) {
|
|
}))
|
|
|
|
err = irc.Serve(ctx, 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()
|
|
}
|