added webhook only option
This commit is contained in:
parent
26338f6b16
commit
a8dd7c0414
@ -33,6 +33,12 @@ var commands = []*discordgo.ApplicationCommand{
|
||||
Description: "max 100",
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "webhook_only",
|
||||
Description: "bool",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
42
delete.go
Normal file
42
delete.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func deleteMessages(data discordgo.ApplicationCommandInteractionData, s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
amount, _ := strconv.Atoi(data.Options[0].Value.(string))
|
||||
if amount > 100 {
|
||||
amount = 100
|
||||
}
|
||||
messages, err := s.ChannelMessages(i.ChannelID, amount, "", "", "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = s.InteractionRespond(
|
||||
i.Interaction,
|
||||
&discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
TTS: true,
|
||||
Content: "deleting " + strconv.Itoa(len(messages)) + " messages",
|
||||
},
|
||||
},
|
||||
)
|
||||
message, err := s.ChannelMessageSend(i.ChannelID, "Please hold....")
|
||||
if err != nil {
|
||||
// Handle the error
|
||||
}
|
||||
for _, message := range messages {
|
||||
var Webhooks []*discordgo.Webhook
|
||||
Webhooks, err = s.ChannelWebhooks(i.ChannelID)
|
||||
for _, Webhook := range Webhooks {
|
||||
if message.Author.ID == Webhook.ID {
|
||||
s.ChannelMessageDelete(i.ChannelID, message.ID)
|
||||
println(message.Content + " deleted")
|
||||
}
|
||||
}
|
||||
}
|
||||
s.ChannelMessageEdit(i.ChannelID, message.ID, strconv.Itoa(len(messages))+" Message deleted")
|
||||
}
|
||||
34
handlers.go
34
handlers.go
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func MessageHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
@ -11,7 +10,10 @@ func MessageHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
return
|
||||
}
|
||||
if m.Content == "test" {
|
||||
s.ChannelMessageSend(m.ChannelID, "werkt")
|
||||
s.ChannelMessageSend(m.ChannelID, "servers:")
|
||||
for _, server := range ServerList {
|
||||
s.ChannelMessageSend(m.ChannelID, "\n"+server.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,32 +51,6 @@ func CommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
// Handle the error
|
||||
}
|
||||
case "delete":
|
||||
amount, _ := strconv.Atoi(data.Options[0].Value.(string))
|
||||
if amount > 100 {
|
||||
amount = 100
|
||||
}
|
||||
messages, err := s.ChannelMessages(i.ChannelID, amount, "", "", "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = s.InteractionRespond(
|
||||
i.Interaction,
|
||||
&discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
TTS: true,
|
||||
Content: "deleting " + strconv.Itoa(len(messages)) + " messages",
|
||||
},
|
||||
},
|
||||
)
|
||||
message, err := s.ChannelMessageSend(i.ChannelID, "Please hold....")
|
||||
if err != nil {
|
||||
// Handle the error
|
||||
}
|
||||
for _, message := range messages {
|
||||
s.ChannelMessageDelete(i.ChannelID, message.ID)
|
||||
println(message.Content + " deleted")
|
||||
}
|
||||
s.ChannelMessageEdit(i.ChannelID, message.ID, strconv.Itoa(len(messages))+" Message deleted")
|
||||
deleteMessages(data, s, i)
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,12 @@ type Server struct {
|
||||
Webhooks []*discordgo.Webhook `json:"Webhooks"`
|
||||
}
|
||||
|
||||
var ServerList []Server
|
||||
|
||||
func initServers() {
|
||||
ServerList = readJson()
|
||||
}
|
||||
|
||||
func AddServer(GuildID string, s *discordgo.Session) Server {
|
||||
servers := readJson()
|
||||
preview, err := s.GuildPreview(GuildID)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user