Commit c70265a9 authored by Mike Jones's avatar Mike Jones 🌶

Working module

parent 5b53d470
*.db
.idea
.env.yaml
.env
docker-compose.yml
scripts/test_deploy.sh
......@@ -22,4 +22,4 @@ FROM scratch
COPY --from=builder /opt /opt
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT ["/opt/modlastfm"]
ENTRYPOINT ["/opt/modlastfm", "-url=nats://nasty-nate-nats-headless:4222"]
.PHONY: deploy
deploy:
.PHONY: deploy deploy
build:
./scripts/build.sh
deploy:
./scripts/deploy.sh
package main
import (
"flag"
"fmt"
"log"
goschema "git.netsplit.uk/stella-irc/ioman/pkg/dragcarschema"
"github.com/boltdb/bolt"
"github.com/nats-io/go-nats"
"github.com/nats-io/go-nats/encoders/protobuf"
"git.netsplit.uk/stella-irc/ioman/pkg/connector"
goschema "git.netsplit.uk/stella-irc/ioman/pkg/dragcarschema"
"git.netsplit.uk/stella-irc/modlastfm/internal/app/modlastfm/gauntlet"
"git.netsplit.uk/stella-irc/modlastfm/internal/app/modlastfm/store"
"git.netsplit.uk/stella-irc/modlastfm/internal/app/modlastfm/util"
)
type Message struct {
Raw string
Target string
}
func main() {
log.Println("Initialising stella-irc Last.fm module, hold tight...")
url := flag.String("url", nats.DefaultURL, "URL For NATS server")
flag.Parse()
nc, err := nats.Connect(*url, nats.UserInfo("nats_client", "shutthefuckupbrandon"))
if err != nil {
log.Fatalf("Failed to connect to nats: %s (URL: %s)", err.Error(), *url)
}
ec, err := nats.NewEncodedConn(nc, protobuf.PROTOBUF_ENCODER)
if err != nil {
log.Fatalf("Error starting connection: %s", err.Error())
}
log.Println("Connected to nats!")
defer ec.Close()
c := &connector.Connector{}
config := util.NewConfig()
db, err := bolt.Open(config.DBPath, 0600, nil)
......@@ -59,23 +34,13 @@ func main() {
// initialise commands
gauntlet.New(config, st)
inputChannel := make(chan *goschema.IRCMessage)
ec.BindRecvChan("messaging.input", inputChannel)
outputChannel := make(chan *goschema.IRCMessage)
ec.BindSendChan("messaging.output", outputChannel)
listen(inputChannel, func(m *goschema.IRCMessage) {
connector.Listen(c, func(m *goschema.IRCMessage) {
if m != nil {
out := gauntlet.Run(m.Nick, m.Raw, st)
outputChannel <- &goschema.IRCMessage{Raw: fmt.Sprintf(out), Target: m.Target}
if out != "" {
c.OutputChannel <- &goschema.IRCMessage{Raw: out, Target: m.Target}
}
}
})
}
func listen(channel chan *goschema.IRCMessage, sendFunc func(*goschema.IRCMessage)) {
for msg := range channel {
sendFunc(msg)
}
}
......@@ -148,7 +148,7 @@ func (f *Fn) fmtNowPlaying(username string, np lastfm.UserGetRecentTracks) strin
output += "last played"
}
tags := f.GetArtistTags(lastTrack.Artist.Name)
tags := f.GetArtistTags(lastTrack.Artist.Name, "")
userTrackInfo, err := f.getUserTrackInfo(username, lastTrack.Artist.Name, lastTrack.Name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment