increased spam speed

This commit is contained in:
DutchEllie 2021-05-25 13:17:30 +02:00
parent 634b93bcfa
commit 394cb914b5
1 changed files with 33 additions and 11 deletions

View File

@ -14,34 +14,41 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
) )
func (app *application) sendPepe(s *discordgo.Session, m *discordgo.MessageCreate) { func (app *application) getPepeLink() (string, error) {
resp, err := http.Get("http://bbwroller.com/random") resp, err := http.Get("http://bbwroller.com/random")
if err != nil { if err != nil {
app.errorLog.Print(err) return "", err
return
} }
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
app.errorLog.Print(err) return "", err
return
} }
rep, err := regexp.Compile("/static.*\\.jpg") rep, err := regexp.Compile("/static.*\\.jpg")
if err != nil { if err != nil {
app.errorLog.Print(err) return "", err
return
} }
pepes := rep.FindAllString(string(body), 200) pepes := rep.FindAllString(string(body), 200)
if pepes == nil { if pepes == nil {
app.errorLog.Printf("No pepes were found\n") return "", err
return
} }
randomIndex := rand.Intn(35) randomIndex := rand.Intn(35)
url := "https://bbwroller.com" url := "https://bbwroller.com"
url += pepes[randomIndex] url += pepes[randomIndex]
return url, nil
}
func (app *application) sendPepe(s *discordgo.Session, m *discordgo.MessageCreate) {
url, err := app.getPepeLink()
if err != nil {
app.errorLog.Print(err)
return
}
_, err = s.ChannelMessageSend(m.ChannelID, url) _, err = s.ChannelMessageSend(m.ChannelID, url)
if err != nil { if err != nil {
app.errorLog.Print(err) app.errorLog.Print(err)
return
} }
} }
@ -155,15 +162,30 @@ func (app *application) sendManyPepes(s *discordgo.Session, m *discordgo.Message
app.active = true app.active = true
var msg string = ""
for i := 0; i < val; i++ { for i := 0; i < val; i++ {
if app.stop { if app.stop {
app.stop = false app.stop = false
break break
} }
app.sendPepe(s, m) link, err := app.getPepeLink()
time.Sleep(time.Millisecond * 500) if err != nil {
app.errorLog.Print(err)
return
}
if len(msg + link) > 1950 {
s.ChannelMessageSend(m.ChannelID, msg)
msg = ""
time.Sleep(time.Millisecond * 500)
}
msg += link
msg += "\n"
} }
s.ChannelMessageSend(m.ChannelID, msg)
app.active = false app.active = false
} }