diff --git a/connectors/discord/discord.go b/connectors/discord/discord.go index 66834a6..b81ea9c 100644 --- a/connectors/discord/discord.go +++ b/connectors/discord/discord.go @@ -431,6 +431,9 @@ func (d *Discord) SetRole(userID, roleID string) error { type CmdHandler func(s *discordgo.Session, i *discordgo.InteractionCreate) func (d *Discord) RegisterSlashCmd(c discordgo.ApplicationCommand, handler CmdHandler) error { + if !d.config.GetBool("registerSlash", true) { + return nil + } cmd, err := d.client.ApplicationCommandCreate(d.client.State.User.ID, d.guildID, &c) d.cmdHandlers[c.Name] = handler if err != nil { diff --git a/plugins/emojy/list.html b/plugins/emojy/list.html deleted file mode 100644 index a32eaa5..0000000 --- a/plugins/emojy/list.html +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - - - - Memes - - - -
- - Emojys - - {{ item.name - }} - - - - - - - Stats - List - Upload - - - -
- {{ err }} -
- -
-
-
- - - -
{{name}}
-
-
-
-
- - - - \ No newline at end of file diff --git a/plugins/emojy/stats.html b/plugins/emojy/stats.html deleted file mode 100644 index 25d8575..0000000 --- a/plugins/emojy/stats.html +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - - - - - - - - - - Memes - - - -
- - Emojys - - {{ item.name - }} - - - - - - - Stats - List - Upload - - - -
- {{ err }} -
- - -
- - - - \ No newline at end of file diff --git a/plugins/emojy/web.go b/plugins/emojy/web.go index ca08bc3..3fb78c2 100644 --- a/plugins/emojy/web.go +++ b/plugins/emojy/web.go @@ -25,15 +25,40 @@ func (p *EmojyPlugin) registerWeb() { r.HandleFunc("/allFiles", p.handleAllFiles) r.HandleFunc("/upload", p.handleUpload) r.HandleFunc("/file/{name}", p.handleEmojy) - r.HandleFunc("/stats", p.handlePage("stats.html")) - r.HandleFunc("/list", p.handlePage("list.html")) - r.HandleFunc("/new", p.handlePage("upload.html")) - r.HandleFunc("/", p.handleIndex) + r.HandleFunc("/stats", p.handleStats) + r.HandleFunc("/list", p.handleList) + r.HandleFunc("/new", p.handleUploadForm) + r.HandleFunc("/", p.handleStats) p.b.GetWeb().RegisterWebName(r, "/emojy", "Emojys") } -func (p *EmojyPlugin) handleIndex(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/emojy/stats", http.StatusPermanentRedirect) +type emojyMap map[string][]EmojyCount + +func (p *EmojyPlugin) handleUploadForm(w http.ResponseWriter, r *http.Request) { + p.b.GetWeb().Index("Emojy", p.uploadIndex()).Render(r.Context(), w) +} + +func (p *EmojyPlugin) handleList(w http.ResponseWriter, r *http.Request) { + threshold := p.c.GetInt("emojy.statthreshold", 1) + emojy, err := p.allCounts(threshold) + if err != nil { + fmt.Fprintf(w, "Error: %s", err) + return + } + p.b.GetWeb().Index("Emojy", p.listTempl(emojy)).Render(r.Context(), w) +} + +func (p *EmojyPlugin) handleStats(w http.ResponseWriter, r *http.Request) { + threshold := p.c.GetInt("emojy.statthreshold", 1) + emojy, err := p.allCounts(threshold) + if err != nil { + w.WriteHeader(500) + log.Error().Err(err).Msgf("handleAll") + out, _ := json.Marshal(struct{ err error }{err}) + w.Write(out) + return + } + p.b.GetWeb().Index("Emojy", p.statsIndex(emojy)).Render(r.Context(), w) } func (p *EmojyPlugin) handlePage(file string) func(w http.ResponseWriter, r *http.Request) { @@ -74,18 +99,16 @@ func (p *EmojyPlugin) handleAllFiles(w http.ResponseWriter, r *http.Request) { } func (p *EmojyPlugin) handleUpload(w http.ResponseWriter, r *http.Request) { - enc := json.NewEncoder(w) newFilePath, err := p.FileSave(r) if err != nil { log.Error().Err(err).Msgf("could not upload file") w.WriteHeader(500) - enc.Encode(struct{ err error }{fmt.Errorf("file not saved: %s", err)}) + fmt.Fprintf(w, "Error with file upload") return } log.Debug().Msgf("uploaded file to %s", newFilePath) w.WriteHeader(200) - enc.Encode(struct{ file string }{newFilePath}) - + fmt.Fprintf(w, "success") } func (p *EmojyPlugin) FileSave(r *http.Request) (string, error) { @@ -101,7 +124,7 @@ func (p *EmojyPlugin) FileSave(r *http.Request) (string, error) { return "", fmt.Errorf("no files") } - password := r.Form.Get("password") + password := r.FormValue("password") if password != p.b.GetPassword() { return "", fmt.Errorf("incorrect password") } diff --git a/plugins/meme/meme_templ.go b/plugins/meme/meme_templ.go index 1520a2b..1b2aa45 100644 --- a/plugins/meme/meme_templ.go +++ b/plugins/meme/meme_templ.go @@ -65,7 +65,20 @@ func (p *MemePlugin) Show(meme webResp) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">
\"")
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(meme.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `plugins/meme/meme.templ`, Line: 35, Col: 23} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" \"") ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(meme.Name) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `plugins/meme/meme.templ`, Line: 39, Col: 27} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">
")
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}