123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package main
- import (
- "embed"
- "fmt"
- "io/fs"
- "net/http"
- "git.riomhaire.com/gremlin/elizaservice/eliza"
- "github.com/jaffee/commandeer"
- )
- var templates embed.FS
- type Main struct {
- BotName string `help:"What This Bot is Called."`
- Port int `help:"What port bot is listening too"`
- }
- func NewMain() *Main {
- return &Main{
- BotName: "Eliza",
- Port: 8070,
- }
- }
- func inputhandler(w http.ResponseWriter, r *http.Request) {
-
- question := r.URL.Query().Get("value")
-
- answer := eliza.ReplyTo(question)
-
- fmt.Fprintf(w, "%s", answer)
- }
- func (m *Main) Run() error {
- fmt.Println(`
- ####### # ### ####### #
- # # # # # #
- # # # # # #
- ##### # # # # #
- # # # # #######
- # # # # # #
- ####### ####### ### ####### # #
- `)
- fmt.Println()
-
- fsys, err := fs.Sub(templates, "web")
- if err != nil {
- panic(err)
- }
- webroot := http.FileServer(http.FS(fsys))
- http.Handle("/", webroot)
-
- http.HandleFunc("/user-input", inputhandler)
- fmt.Printf(" [*] %s ... Awaiting Conversations on port %d\n", m.BotName, m.Port)
- http.ListenAndServe(fmt.Sprintf(":%d", m.Port), nil)
- return nil
- }
- func main() {
- err := commandeer.Run(NewMain())
- if err != nil {
- fmt.Println(err)
- }
- }
|