Compare commits

...

3 Commits

Author SHA1 Message Date
ffbfb6ae1d new command! 2023-12-08 18:39:52 +06:00
f82a89f9b5 removed some stuff 2023-11-23 23:22:20 +06:00
d9eef1c1f3 always use celcius 2023-05-26 18:11:46 +06:00

65
main.go
View File

@ -7,9 +7,8 @@ import (
"os/signal" "os/signal"
"syscall" "syscall"
"strings" "strings"
"regexp" "time"
"io" "math/rand"
"net/http"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -67,6 +66,31 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
return return
} }
if strings.HasPrefix(m.Content, "!ask") {
possibleAnswers := []string{
"Better not tell you now.",
"Signs point to yes.",
"My reply is no.",
"Yes.",
"Without a doubt.",
"I don't think so.",
"I doubt it.",
"NO!",
"Well... can't say for sure but maybe.",
"I think you need sleep.",
"Depends.",
"Skibidi dop dop dop yes yes yes gang gang!!!111",
"I don't think this is a good idea, honestly.",
"SHUT. THE. FUCK. UP",
"Hmm, let me think about that for a bit.",
}
rand.Seed(time.Now().Unix())
reply := possibleAnswers[rand.Intn(len(possibleAnswers))]
s.ChannelMessageSend(m.ChannelID, reply)
return
}
if strings.HasPrefix(m.Content, "!fart") { if strings.HasPrefix(m.Content, "!fart") {
c := strings.Fields(m.Content) c := strings.Fields(m.Content)
if len(c) == 1 { if len(c) == 1 {
@ -75,40 +99,5 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf(":whale2: :dash: %s", c[1])) s.ChannelMessageSend(m.ChannelID, fmt.Sprintf(":whale2: :dash: %s", c[1]))
} }
return return
} else if strings.HasPrefix(m.Content, "!weather") {
c := strings.Fields(m.Content)
if len(c) == 2 {
// contact wttr.in
url := fmt.Sprintf("https://wttr.in/%s?0QAT", c[1])
resp, err := http.Get(url)
if err != nil {
fmt.Printf("ERROR while running $weather: %s", err)
return
}
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("ERROR while running $weather: %s", err)
return
}
body_string := string(body[:])
if strings.Contains(body_string, "404 UNKNOWN") {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("That's not a city, silly!"))
return
}
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("```%s```", body_string))
}
return
}
// check for reddit/twitter links and replace them with open source frontends
re := regexp.MustCompile(`(?i)((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)`)
result := re.FindStringSubmatch(m.Content)
// hard coded, group 2 contains the base url
if len(result) >= 3 {
if result[2] == "https://www.reddit.com" || result[2] == "https://reddit.com"{
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("<https://tedd.it%s>", result[4]))
} else if result[2] == "https://www.twitter.com" || result[2] == "https://twitter.com" {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("<https://nitter.lacontrevoie.fr%s>", result[4]))
}
} }
} }