mirror of https://github.com/velour/catbase.git
pagecomment: omit user if using slash
This commit is contained in:
parent
b670ecc647
commit
a9a4c9274c
|
@ -63,13 +63,8 @@ func (p *PageComment) handleURLCmd(conn bot.Connector) func(*discordgo.Session,
|
||||||
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
return func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
u := i.ApplicationCommandData().Options[0].StringValue()
|
u := i.ApplicationCommandData().Options[0].StringValue()
|
||||||
cmt := i.ApplicationCommandData().Options[1].StringValue()
|
cmt := i.ApplicationCommandData().Options[1].StringValue()
|
||||||
who := i.Member.User.Username
|
msg := handleURL(u, cmt, "")
|
||||||
profile, err := conn.Profile(i.Member.User.ID)
|
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
if err == nil {
|
|
||||||
who = profile.Name
|
|
||||||
}
|
|
||||||
msg := handleURL(u, cmt, who)
|
|
||||||
err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
Content: msg,
|
Content: msg,
|
||||||
|
@ -83,6 +78,9 @@ func (p *PageComment) handleURLCmd(conn bot.Connector) func(*discordgo.Session,
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleURL(u, cmt, who string) string {
|
func handleURL(u, cmt, who string) string {
|
||||||
|
if who != "" {
|
||||||
|
who = who + ": "
|
||||||
|
}
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
req, err := http.NewRequest(http.MethodGet, u, nil)
|
req, err := http.NewRequest(http.MethodGet, u, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -101,10 +99,10 @@ func handleURL(u, cmt, who string) string {
|
||||||
wait := make(chan string, 1)
|
wait := make(chan string, 1)
|
||||||
sel := doc.Find("title")
|
sel := doc.Find("title")
|
||||||
if sel.Length() == 0 {
|
if sel.Length() == 0 {
|
||||||
return fmt.Sprintf("> %s: %s\n(<%s>)", who, cmt, u)
|
return fmt.Sprintf("%s%s\n(<%s>)", who, cmt, u)
|
||||||
}
|
}
|
||||||
sel.First().Each(func(i int, s *goquery.Selection) {
|
sel.First().Each(func(i int, s *goquery.Selection) {
|
||||||
wait <- fmt.Sprintf("> %s\n%s: %s\n(<%s>)", s.Text(), who, cmt, u)
|
wait <- fmt.Sprintf("> %s\n%s%s\n(<%s>)", s.Text(), who, cmt, u)
|
||||||
})
|
})
|
||||||
return <-wait
|
return <-wait
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue