Cleanup
This commit is contained in:
parent
c0469667b1
commit
48a59a9ec7
2 changed files with 73 additions and 62 deletions
62
commands.go
Normal file
62
commands.go
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ping(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
if i.Interaction.Member != nil {
|
||||||
|
log.Printf("%s#%s invoked ping command", i.Interaction.Member.User.Username, i.Interaction.Member.User.Discriminator)
|
||||||
|
} else if i.Interaction.User != nil {
|
||||||
|
log.Printf("%s#%s invoked ping command", i.Interaction.User.Username, i.Interaction.User.Discriminator)
|
||||||
|
}
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
//Flags: 1 << 6, // Only lets issuer see initial response
|
||||||
|
Content: "Pong!",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func sping(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
if i.Interaction.Member != nil {
|
||||||
|
log.Printf("%s#%s invoked ping command", i.Interaction.Member.User.Username, i.Interaction.Member.User.Discriminator)
|
||||||
|
} else if i.Interaction.User != nil {
|
||||||
|
log.Printf("%s#%s invoked ping command", i.Interaction.User.Username, i.Interaction.User.Discriminator)
|
||||||
|
}
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Flags: 1 << 6, // Only lets issuer see initial response
|
||||||
|
Content: "Pong!",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func slowping(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
if i.Interaction.Member != nil {
|
||||||
|
log.Printf("%s#%s invoked ping command", i.Interaction.Member.User.Username, i.Interaction.Member.User.Discriminator)
|
||||||
|
} else if i.Interaction.User != nil {
|
||||||
|
log.Printf("%s#%s invoked ping command", i.Interaction.User.Username, i.Interaction.User.Discriminator)
|
||||||
|
}
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
//Flags: 1 << 6, // Only lets issuer see initial response
|
||||||
|
Content: "...",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
time.Sleep(time.Second * 10)
|
||||||
|
|
||||||
|
_, err := s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
|
||||||
|
Content: "Pong!",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
73
main.go
73
main.go
|
@ -10,7 +10,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"regexp"
|
"regexp"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/wader/goutubedl"
|
"github.com/wader/goutubedl"
|
||||||
|
@ -18,7 +17,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Variables used for command line parameters
|
// Lazyinator 9001
|
||||||
|
var (
|
||||||
|
s *discordgo.Session
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
// Variables used for registering slash commands
|
||||||
var (
|
var (
|
||||||
commands = []*discordgo.ApplicationCommand {
|
commands = []*discordgo.ApplicationCommand {
|
||||||
{
|
{
|
||||||
|
@ -35,68 +40,12 @@ func main() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
"ping": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
"ping": ping,
|
||||||
if i.Interaction.Member != nil {
|
"sping": sping,
|
||||||
log.Printf("%s#%s invoked ping command", i.Interaction.Member.User.Username, i.Interaction.Member.User.Discriminator)
|
"slowping": slowping,
|
||||||
} else if i.Interaction.User != nil {
|
|
||||||
log.Printf("%s#%s invoked ping command", i.Interaction.User.Username, i.Interaction.User.Discriminator)
|
|
||||||
}
|
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
//Flags: 1 << 6, // Only lets issuer see initial response
|
|
||||||
Content: "Pong!",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
"sping": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
||||||
if i.Interaction.Member != nil {
|
|
||||||
log.Printf("%s#%s invoked ping command", i.Interaction.Member.User.Username, i.Interaction.Member.User.Discriminator)
|
|
||||||
} else if i.Interaction.User != nil {
|
|
||||||
log.Printf("%s#%s invoked ping command", i.Interaction.User.Username, i.Interaction.User.Discriminator)
|
|
||||||
}
|
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Flags: 1 << 6, // Only lets issuer see initial response
|
|
||||||
Content: "Pong!",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
"slowping": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
||||||
if i.Interaction.Member != nil {
|
|
||||||
log.Printf("%s#%s invoked ping command", i.Interaction.Member.User.Username, i.Interaction.Member.User.Discriminator)
|
|
||||||
} else if i.Interaction.User != nil {
|
|
||||||
log.Printf("%s#%s invoked ping command", i.Interaction.User.Username, i.Interaction.User.Discriminator)
|
|
||||||
}
|
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
//Flags: 1 << 6, // Only lets issuer see initial response
|
|
||||||
Content: "No problem.",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
time.Sleep(time.Second * 10)
|
|
||||||
|
|
||||||
_, err := s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
|
|
||||||
Content: "Pong!",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Lazyinator 9001
|
|
||||||
var (
|
|
||||||
s *discordgo.Session
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
// Bot params
|
// Bot params
|
||||||
var (
|
var (
|
||||||
GuildID = flag.String("guild", "", "Test guild ID. If not passed - bot registers commands globally")
|
GuildID = flag.String("guild", "", "Test guild ID. If not passed - bot registers commands globally")
|
||||||
|
@ -193,7 +142,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
Files: []*discordgo.File{},
|
Files: []*discordgo.File{},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("URLs detected!")
|
log.Printf("Message %s has URLs!", m.ID)
|
||||||
|
|
||||||
respond := false
|
respond := false
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue