From 7ca4a30c146b44cdc891f27a8c7c690ec1583253 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Thu, 29 Sep 2022 11:58:06 -0400 Subject: [PATCH] url: add configurable useragent --- plugins/pagecomment/pagecomment.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/pagecomment/pagecomment.go b/plugins/pagecomment/pagecomment.go index 38292ca..32c8b81 100644 --- a/plugins/pagecomment/pagecomment.go +++ b/plugins/pagecomment/pagecomment.go @@ -53,7 +53,8 @@ func (p *PageComment) handleURLReq(r bot.Request) bool { if strings.HasPrefix(u, "<") && strings.HasSuffix(u, ">") { u = u[1 : len(u)-1] } - msg := handleURL(u, fullComment, r.Msg.User.Name) + ua := p.c.Get("url.useragent", "catbase/1.0") + msg := handleURL(u, fullComment, r.Msg.User.Name, ua) p.b.Send(r.Conn, bot.Delete, r.Msg.Channel, r.Msg.ID) p.b.Send(r.Conn, bot.Message, r.Msg.Channel, msg) return true @@ -63,7 +64,8 @@ func (p *PageComment) handleURLCmd(conn bot.Connector) func(*discordgo.Session, return func(s *discordgo.Session, i *discordgo.InteractionCreate) { u := i.ApplicationCommandData().Options[0].StringValue() cmt := i.ApplicationCommandData().Options[1].StringValue() - msg := handleURL(u, cmt, "") + ua := p.c.Get("url.useragent", "catbase/1.0") + msg := handleURL(u, cmt, "", ua) err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ @@ -77,7 +79,7 @@ func (p *PageComment) handleURLCmd(conn bot.Connector) func(*discordgo.Session, } } -func handleURL(u, cmt, who string) string { +func handleURL(u, cmt, who, ua string) string { if who != "" { who = who + ": " } @@ -86,7 +88,7 @@ func handleURL(u, cmt, who string) string { if err != nil { return "Couldn't parse that URL" } - req.Header.Set("User-Agent", "catbase/1.0") + req.Header.Set("User-Agent", ua) resp, err := client.Do(req) if err != nil || resp.StatusCode > 299 { log.Error().Err(err).Int("status", resp.StatusCode).Msgf("error with request")