initial code commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package commands
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var BoopCommand = &discordgo.ApplicationCommand{
|
||||
Name: "boop",
|
||||
Description: "Say Boop!",
|
||||
}
|
||||
|
||||
func HandleBoop(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
var username string
|
||||
if i.Member != nil {
|
||||
username = i.Member.User.Username
|
||||
} else if i.User != nil {
|
||||
username = i.User.Username
|
||||
}
|
||||
response := &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: username + ", Boop!",
|
||||
},
|
||||
}
|
||||
s.InteractionRespond(i.Interaction, response)
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
helpers "ion606_bot/Bot/Helpers"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var CatfactCommand = &discordgo.ApplicationCommand{
|
||||
Name: "catfact",
|
||||
Description: "Fetches a random cat fact",
|
||||
}
|
||||
|
||||
type CatFactAPIResponse struct {
|
||||
Facts []struct {
|
||||
FactNumber int `json:"fact_number"`
|
||||
Fact string `json:"fact"`
|
||||
} `json:"facts"`
|
||||
}
|
||||
|
||||
func HandleCatfact(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
client := http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
resp, err := client.Get("https://www.catfacts.net/api/")
|
||||
if err != nil {
|
||||
helpers.HandleError(s, i, err)
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
helpers.HandleError(s, i, err)
|
||||
return
|
||||
}
|
||||
|
||||
var result CatFactAPIResponse
|
||||
err = json.Unmarshal(body, &result)
|
||||
if err != nil || len(result.Facts) == 0 {
|
||||
helpers.HandleError(s, i, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Pick a random fact from the array.
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
randomFact := result.Facts[rand.Intn(len(result.Facts))].Fact
|
||||
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: randomFact,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package commands
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var CuddleCommand = &discordgo.ApplicationCommand{
|
||||
Name: "cuddle",
|
||||
Description: "Gently cuddle for your day!",
|
||||
}
|
||||
|
||||
func HandleCuddle(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
response := &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Here's a gentle cuddle for your day! 💕",
|
||||
},
|
||||
}
|
||||
s.InteractionRespond(i.Interaction, response)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package commands
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var HugCommand = &discordgo.ApplicationCommand{
|
||||
Name: "hug",
|
||||
Description: "Sends you a big warm hug!",
|
||||
}
|
||||
|
||||
func HandleHug(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
response := &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Sending you a big warm hug! 🤗",
|
||||
},
|
||||
}
|
||||
s.InteractionRespond(i.Interaction, response)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
Helpers "ion606_bot/Bot/Helpers"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var MeowCommand = &discordgo.ApplicationCommand{
|
||||
Name: "meow",
|
||||
Description: "Sends a random cat image",
|
||||
}
|
||||
|
||||
type SefinekAPIResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Status int `json:"status"`
|
||||
Info struct {
|
||||
Category string `json:"category"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
} `json:"info"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func HandleMeow(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
client := http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
resp, err := client.Get("https://api.sefinek.net/api/v2/random/animal/cat")
|
||||
if err != nil {
|
||||
Helpers.HandleError(s, i, fmt.Errorf("fetching cat image: %w", err))
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
Helpers.HandleError(s, i, fmt.Errorf("reading cat image response: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
var apiResp SefinekAPIResponse
|
||||
err = json.Unmarshal(body, &apiResp)
|
||||
if err != nil || !apiResp.Success {
|
||||
Helpers.HandleError(s, i, fmt.Errorf("parsing cat image response"))
|
||||
return
|
||||
}
|
||||
|
||||
// Use the "message" field which contains the image URL.
|
||||
imageURL := apiResp.Message
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: imageURL,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package commands
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var PurrCommand = &discordgo.ApplicationCommand{
|
||||
Name: "purr",
|
||||
Description: "Purr...",
|
||||
}
|
||||
|
||||
func HandlePurr(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
response := &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Purr...",
|
||||
},
|
||||
}
|
||||
s.InteractionRespond(i.Interaction, response)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package commands
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var SnuggleCommand = &discordgo.ApplicationCommand{
|
||||
Name: "snuggle",
|
||||
Description: "Time to snuggle up and feel cozy!",
|
||||
}
|
||||
|
||||
func HandleSnuggle(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
response := &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Time to snuggle up and feel cozy! 🥰",
|
||||
},
|
||||
}
|
||||
s.InteractionRespond(i.Interaction, response)
|
||||
}
|
||||
Reference in New Issue
Block a user