Compare commits
No commits in common. "48a59a9ec71b5ee12375f39647f2cc12954e003a" and "bf458fdea9a12971d703c9fd569634e90daf21a2" have entirely different histories.
48a59a9ec7
...
bf458fdea9
3 changed files with 63 additions and 77 deletions
5
Makefile
5
Makefile
|
@ -5,10 +5,7 @@ BUILD_DATE := $(shell date -u +.%Y%m%d.%H%M%S)
|
|||
CGO_ENABLED=0
|
||||
|
||||
default:
|
||||
CGO_ENABLED=$(CGO_ENABLED) go build -o out/engibot -trimpath -ldflags "-s -w -X main.gitCommit=$(GIT_COMMIT)" .
|
||||
CGO_ENABLED=$(CGO_ENABLED) go build -o out/engibot -trimpath -ldflags "-s -w -X main.gitCommit=$(GIT_COMMIT)" main.go
|
||||
|
||||
debug:
|
||||
go build -o out/ -ldflags "-X main.gitCommit=$(GIT_COMMIT)" main.go
|
||||
|
||||
run:
|
||||
go run . --token $(TOKEN)
|
||||
|
|
62
commands.go
62
commands.go
|
@ -1,62 +0,0 @@
|
|||
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,6 +10,7 @@ import (
|
|||
"strings"
|
||||
"regexp"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/wader/goutubedl"
|
||||
|
@ -17,13 +18,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
// Lazyinator 9001
|
||||
var (
|
||||
s *discordgo.Session
|
||||
err error
|
||||
)
|
||||
|
||||
// Variables used for registering slash commands
|
||||
// Variables used for command line parameters
|
||||
var (
|
||||
commands = []*discordgo.ApplicationCommand {
|
||||
{
|
||||
|
@ -40,12 +35,68 @@ func main() {
|
|||
},
|
||||
}
|
||||
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
"ping": ping,
|
||||
"sping": sping,
|
||||
"slowping": slowping,
|
||||
"ping": 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!",
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
"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
|
||||
var (
|
||||
GuildID = flag.String("guild", "", "Test guild ID. If not passed - bot registers commands globally")
|
||||
|
@ -142,7 +193,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||
Files: []*discordgo.File{},
|
||||
}
|
||||
|
||||
log.Printf("Message %s has URLs!", m.ID)
|
||||
log.Println("URLs detected!")
|
||||
|
||||
respond := false
|
||||
|
||||
|
|
Loading…
Reference in a new issue