Changed pepe function

This commit is contained in:
DutchEllie 2021-09-08 22:35:03 +02:00
parent d6d8eb01f3
commit cd788bab4a
1 changed files with 61 additions and 50 deletions

View File

@ -3,10 +3,8 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"math/rand"
"net/http" "net/http"
"regexp"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -15,7 +13,7 @@ import (
) )
func (app *application) getPepeLink() (string, error) { 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 {
return "", err return "", err
} }
@ -33,9 +31,22 @@ func (app *application) getPepeLink() (string, error) {
} }
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 // The above function is old and useless. The website bbwroller.com is down
// o7
resp, err := http.Get(app.pepeServer + "/pepe")
if err != nil {
return "", err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
} }
func (app *application) sendPepe(s *discordgo.Session, m *discordgo.MessageCreate) { func (app *application) sendPepe(s *discordgo.Session, m *discordgo.MessageCreate) {
@ -157,7 +168,7 @@ func (app *application) sendManyPepes(s *discordgo.Session, m *discordgo.Message
//s.ChannelMessageSend(m.ChannelID, "You have to be admin to override, not overriding") //s.ChannelMessageSend(m.ChannelID, "You have to be admin to override, not overriding")
override = true override = true
} }
} }
} }
@ -189,12 +200,12 @@ func (app *application) sendManyPepes(s *discordgo.Session, m *discordgo.Message
app.errorLog.Print(err) app.errorLog.Print(err)
return return
} }
if len(msg + link) > 1950 { if len(msg+link) > 1950 {
s.ChannelMessageSend(m.ChannelID, msg) s.ChannelMessageSend(m.ChannelID, msg)
msg = "" msg = ""
time.Sleep(time.Millisecond * 500) time.Sleep(time.Millisecond * 500)
} }
msg += link msg += link
msg += "\n" msg += "\n"
@ -213,7 +224,7 @@ func (app *application) stopRequest(s *discordgo.Session, m *discordgo.MessageCr
app.stop = false app.stop = false
s.ChannelMessageSend(m.ChannelID, "But I wasn't doing anything!") s.ChannelMessageSend(m.ChannelID, "But I wasn't doing anything!")
} }
} }
func (app *application) findTrigger(s *discordgo.Session, m *discordgo.MessageCreate) { func (app *application) findTrigger(s *discordgo.Session, m *discordgo.MessageCreate) {
@ -221,7 +232,7 @@ func (app *application) findTrigger(s *discordgo.Session, m *discordgo.MessageCr
Check if the message contains that word Check if the message contains that word
if it doesn't continue, if it doesn't continue,
if it does then get the word from the database, update the new time, format a message and send it */ if it does then get the word from the database, update the new time, format a message and send it */
for i := 0; i < len(app.allBadWords[m.GuildID]); i++{ for i := 0; i < len(app.allBadWords[m.GuildID]); i++ {
if strings.Contains(strings.ToLower(m.Content), strings.ToLower(app.allBadWords[m.GuildID][i])) { if strings.Contains(strings.ToLower(m.Content), strings.ToLower(app.allBadWords[m.GuildID][i])) {
/* Found the bad word */ /* Found the bad word */
word, err := app.badwords.GetWord(strings.ToLower(app.allBadWords[m.GuildID][i]), m.GuildID) word, err := app.badwords.GetWord(strings.ToLower(app.allBadWords[m.GuildID][i]), m.GuildID)
@ -238,7 +249,7 @@ func (app *application) findTrigger(s *discordgo.Session, m *discordgo.MessageCr
user := m.Author.Mention() user := m.Author.Mention()
eyesEmoji := ":eyes:" eyesEmoji := ":eyes:"
message := fmt.Sprintf("%s mentioned the forbidden word '%s'. They broke a streak of %s...\nYou better watch out, I am always watching %s", user, word.Word, format, eyesEmoji) message := fmt.Sprintf("%s mentioned the forbidden word '%s'. They broke a streak of %s...\nYou better watch out, I am always watching %s", user, word.Word, format, eyesEmoji)
_ ,err = s.ChannelMessageSend(m.ChannelID, message) _, err = s.ChannelMessageSend(m.ChannelID, message)
if err != nil { if err != nil {
app.errorLog.Print(err) app.errorLog.Print(err)
return return
@ -248,84 +259,84 @@ func (app *application) findTrigger(s *discordgo.Session, m *discordgo.MessageCr
} }
} }
func formatTimeCheck(last time.Time) string{ func formatTimeCheck(last time.Time) string {
now := time.Now() now := time.Now()
sinceLast := now.Sub(last) sinceLast := now.Sub(last)
var realSeconds uint64 = uint64(sinceLast.Seconds()) var realSeconds uint64 = uint64(sinceLast.Seconds())
var seconds, minutes, hours, days uint64 var seconds, minutes, hours, days uint64
realBackup := realSeconds realBackup := realSeconds
days = realSeconds / ( 24 * 3600 ) days = realSeconds / (24 * 3600)
realSeconds -= days * ( 24 * 3600 ) realSeconds -= days * (24 * 3600)
hours = realSeconds / 3600 hours = realSeconds / 3600
realSeconds -= hours * 3600 realSeconds -= hours * 3600
minutes = realSeconds / 60 minutes = realSeconds / 60
realSeconds -= minutes * 60 realSeconds -= minutes * 60
seconds = realSeconds seconds = realSeconds
if realBackup < 60{ if realBackup < 60 {
if seconds == 1{ if seconds == 1 {
return fmt.Sprintf("%d second", seconds) return fmt.Sprintf("%d second", seconds)
} }
return fmt.Sprintf("%d seconds", seconds) return fmt.Sprintf("%d seconds", seconds)
}else if realBackup > 60 && realBackup < 3600 { } else if realBackup > 60 && realBackup < 3600 {
if seconds == 1 && minutes == 1{ if seconds == 1 && minutes == 1 {
return fmt.Sprintf("%d minute and %d second", minutes, seconds) return fmt.Sprintf("%d minute and %d second", minutes, seconds)
}else if minutes == 1 && seconds != 1{ } else if minutes == 1 && seconds != 1 {
return fmt.Sprintf("%d minute and %d seconds", minutes, seconds) return fmt.Sprintf("%d minute and %d seconds", minutes, seconds)
}else if minutes != 1 && seconds == 1{ } else if minutes != 1 && seconds == 1 {
return fmt.Sprintf("%d minutes and %d second", minutes, seconds) return fmt.Sprintf("%d minutes and %d second", minutes, seconds)
} }
return fmt.Sprintf("%d minutes and %d seconds", minutes, seconds) return fmt.Sprintf("%d minutes and %d seconds", minutes, seconds)
}else if realBackup > 60 && realBackup < ( 24 * 3600 ){ } else if realBackup > 60 && realBackup < (24*3600) {
if hours == 1 && minutes == 1 && seconds == 1{ if hours == 1 && minutes == 1 && seconds == 1 {
return fmt.Sprintf("%d hour, %d minute and %d second", hours, minutes, seconds) return fmt.Sprintf("%d hour, %d minute and %d second", hours, minutes, seconds)
}else if hours == 1 && minutes == 1 && seconds != 1 { } else if hours == 1 && minutes == 1 && seconds != 1 {
return fmt.Sprintf("%d hour, %d minute and %d seconds", hours, minutes, seconds) return fmt.Sprintf("%d hour, %d minute and %d seconds", hours, minutes, seconds)
}else if hours == 1 && minutes != 1 && seconds == 1{ } else if hours == 1 && minutes != 1 && seconds == 1 {
return fmt.Sprintf("%d hour, %d minutes and %d second", hours, minutes, seconds) return fmt.Sprintf("%d hour, %d minutes and %d second", hours, minutes, seconds)
}else if hours == 1 && minutes != 1 && seconds != 1{ } else if hours == 1 && minutes != 1 && seconds != 1 {
return fmt.Sprintf("%d hour, %d minutes and %d seconds", hours, minutes, seconds) return fmt.Sprintf("%d hour, %d minutes and %d seconds", hours, minutes, seconds)
}else if hours != 1 && minutes == 1 && seconds == 1{ } else if hours != 1 && minutes == 1 && seconds == 1 {
return fmt.Sprintf("%d hours, %d minute and %d second", hours, minutes, seconds) return fmt.Sprintf("%d hours, %d minute and %d second", hours, minutes, seconds)
}else if hours != 1 && minutes == 1 && seconds != 1{ } else if hours != 1 && minutes == 1 && seconds != 1 {
return fmt.Sprintf("%d hours, %d minute and %d seconds", hours, minutes, seconds) return fmt.Sprintf("%d hours, %d minute and %d seconds", hours, minutes, seconds)
}else if hours != 1 && minutes != 1 && seconds == 1{ } else if hours != 1 && minutes != 1 && seconds == 1 {
return fmt.Sprintf("%d hours, %d minutes and %d second", hours, minutes, seconds) return fmt.Sprintf("%d hours, %d minutes and %d second", hours, minutes, seconds)
}else if hours != 1 && minutes != 1 && seconds != 1{ } else if hours != 1 && minutes != 1 && seconds != 1 {
return fmt.Sprintf("%d hours, %d minutes and %d seconds", hours, minutes, seconds) return fmt.Sprintf("%d hours, %d minutes and %d seconds", hours, minutes, seconds)
} }
return fmt.Sprintf("%d hours, %d minutes and %d seconds", hours, minutes, seconds) return fmt.Sprintf("%d hours, %d minutes and %d seconds", hours, minutes, seconds)
}else if realBackup > ( 24 * 3600 ){ } else if realBackup > (24 * 3600) {
if days != 1 && hours != 1 && minutes != 1 && seconds != 1{ if days != 1 && hours != 1 && minutes != 1 && seconds != 1 {
return fmt.Sprintf("%d days, %d hours, %d minutes and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hours, %d minutes and %d seconds", days, hours, minutes, seconds)
}else if days != 1 && hours != 1 && minutes != 1 && seconds == 1{ } else if days != 1 && hours != 1 && minutes != 1 && seconds == 1 {
return fmt.Sprintf("%d days, %d hours, %d minutes and %d second", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hours, %d minutes and %d second", days, hours, minutes, seconds)
}else if days != 1 && hours != 1 && minutes == 1 && seconds != 1{ } else if days != 1 && hours != 1 && minutes == 1 && seconds != 1 {
return fmt.Sprintf("%d days, %d hours, %d minute and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hours, %d minute and %d seconds", days, hours, minutes, seconds)
}else if days != 1 && hours != 1 && minutes == 1 && seconds == 1{ } else if days != 1 && hours != 1 && minutes == 1 && seconds == 1 {
return fmt.Sprintf("%d days, %d hours, %d minute and %d second", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hours, %d minute and %d second", days, hours, minutes, seconds)
}else if days != 1 && hours == 1 && minutes != 1 && seconds != 1{ } else if days != 1 && hours == 1 && minutes != 1 && seconds != 1 {
return fmt.Sprintf("%d days, %d hour, %d minutes and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hour, %d minutes and %d seconds", days, hours, minutes, seconds)
}else if days != 1 && hours == 1 && minutes != 1 && seconds == 1{ } else if days != 1 && hours == 1 && minutes != 1 && seconds == 1 {
return fmt.Sprintf("%d days, %d hour, %d minutes and %d second", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hour, %d minutes and %d second", days, hours, minutes, seconds)
}else if days != 1 && hours == 1 && minutes == 1 && seconds != 1{ } else if days != 1 && hours == 1 && minutes == 1 && seconds != 1 {
return fmt.Sprintf("%d days, %d hour, %d minute and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hour, %d minute and %d seconds", days, hours, minutes, seconds)
}else if days != 1 && hours == 1 && minutes == 1 && seconds == 1{ } else if days != 1 && hours == 1 && minutes == 1 && seconds == 1 {
return fmt.Sprintf("%d days, %d hour, %d minute and %d second", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hour, %d minute and %d second", days, hours, minutes, seconds)
}else if days == 1 && hours != 1 && minutes != 1 && seconds != 1{ } else if days == 1 && hours != 1 && minutes != 1 && seconds != 1 {
return fmt.Sprintf("%d day, %d hours, %d minutes and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d day, %d hours, %d minutes and %d seconds", days, hours, minutes, seconds)
}else if days == 1 && hours != 1 && minutes != 1 && seconds == 1{ } else if days == 1 && hours != 1 && minutes != 1 && seconds == 1 {
return fmt.Sprintf("%d day, %d hours, %d minutes and %d second", days, hours, minutes, seconds) return fmt.Sprintf("%d day, %d hours, %d minutes and %d second", days, hours, minutes, seconds)
}else if days == 1 && hours != 1 && minutes == 1 && seconds != 1{ } else if days == 1 && hours != 1 && minutes == 1 && seconds != 1 {
return fmt.Sprintf("%d day, %d hours, %d minute and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d day, %d hours, %d minute and %d seconds", days, hours, minutes, seconds)
}else if days == 1 && hours != 1 && minutes == 1 && seconds == 1{ } else if days == 1 && hours != 1 && minutes == 1 && seconds == 1 {
return fmt.Sprintf("%d day, %d hours, %d minute and %d second", days, hours, minutes, seconds) return fmt.Sprintf("%d day, %d hours, %d minute and %d second", days, hours, minutes, seconds)
}else if days == 1 && hours == 1 && minutes != 1 && seconds != 1{ } else if days == 1 && hours == 1 && minutes != 1 && seconds != 1 {
return fmt.Sprintf("%d day, %d hour, %d minutes and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d day, %d hour, %d minutes and %d seconds", days, hours, minutes, seconds)
}else if days == 1 && hours == 1 && minutes != 1 && seconds == 1{ } else if days == 1 && hours == 1 && minutes != 1 && seconds == 1 {
return fmt.Sprintf("%d day, %d hour, %d minutes and %d second", days, hours, minutes, seconds) return fmt.Sprintf("%d day, %d hour, %d minutes and %d second", days, hours, minutes, seconds)
}else if days == 1 && hours == 1 && minutes == 1 && seconds != 1{ } else if days == 1 && hours == 1 && minutes == 1 && seconds != 1 {
return fmt.Sprintf("%d day, %d hour, %d minute and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d day, %d hour, %d minute and %d seconds", days, hours, minutes, seconds)
}else if days == 1 && hours == 1 && minutes == 1 && seconds == 1{ } else if days == 1 && hours == 1 && minutes == 1 && seconds == 1 {
return fmt.Sprintf("%d day, %d hour, %d minute and %d second", days, hours, minutes, seconds) return fmt.Sprintf("%d day, %d hour, %d minute and %d second", days, hours, minutes, seconds)
} }
return fmt.Sprintf("%d days, %d hours, %d minutes and %d seconds", days, hours, minutes, seconds) return fmt.Sprintf("%d days, %d hours, %d minutes and %d seconds", days, hours, minutes, seconds)
@ -361,7 +372,7 @@ func (app *application) checkIfAdmin(s *discordgo.Session, m *discordgo.MessageC
return false, nil return false, nil
} }
func (app *application) contextLength(splitCommand []string) (error) { func (app *application) contextLength(splitCommand []string) error {
if !(len(splitCommand) > 2) { if !(len(splitCommand) > 2) {
app.errorLog.Printf("The command's context was not enough.\n") app.errorLog.Printf("The command's context was not enough.\n")
return errors.New("not enough context") return errors.New("not enough context")
@ -375,4 +386,4 @@ func (app *application) successMessage(s *discordgo.Session, m *discordgo.Messag
app.unknownError(err, s, true, m.ChannelID) app.unknownError(err, s, true, m.ChannelID)
return return
} }
} }