81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"time"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
func main() {
|
|
//discordServerId := os.Getenv("DISCORD_SERVER_ID")
|
|
//discordChannelId := os.Getenv("DISCORD_CHANNEL_ID")
|
|
discordToken := os.Getenv("DISCORD_TOKEN")
|
|
|
|
discord, err := discordgo.New("Bot " + discordToken)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
discord.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
|
|
fmt.Println("Bot is now running. Press CTRL+C to exit.")
|
|
|
|
})
|
|
discord.AddHandler(func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
if i.Type == discordgo.InteractionApplicationCommand {
|
|
switch i.ApplicationCommandData().Name {
|
|
case "waitlistadd":
|
|
// Handle addwait command
|
|
roles, _ := s.GuildRoles(i.GuildID)
|
|
var discordWaintingRoleId string
|
|
for _, role := range roles {
|
|
if role.Name == "WAITING" {
|
|
discordWaintingRoleId = role.ID
|
|
}
|
|
}
|
|
fmt.Println("GuildId: ", i.GuildID, " User ID: ", i.Member.User.ID, " Role ID: ", discordWaintingRoleId)
|
|
err2 := discord.GuildMemberRoleAdd(i.GuildID, i.Member.User.ID, discordWaintingRoleId)
|
|
if err2 != nil {
|
|
panic(err2)
|
|
}
|
|
time.AfterFunc(1*time.Minute, func() {
|
|
discord.GuildMemberRoleRemove(i.GuildID, i.Member.User.ID, discordWaintingRoleId)
|
|
})
|
|
|
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Content: "User " + i.Member.User.Username + " added to waiting list. ",
|
|
},
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
openErr := discord.Open()
|
|
if openErr != nil {
|
|
panic(openErr)
|
|
}
|
|
// define command to wait
|
|
discord.ApplicationCommandCreate(discord.State.User.ID, "", &discordgo.ApplicationCommand{
|
|
Name: "waitlistadd",
|
|
Description: "Add a user to the waiting list",
|
|
Options: []*discordgo.ApplicationCommandOption{},
|
|
})
|
|
|
|
stop := make(chan os.Signal, 1)
|
|
signal.Notify(stop, os.Interrupt)
|
|
fmt.Println("Press Ctrl+C to exit")
|
|
<-stop
|
|
// add role to user
|
|
/*
|
|
err2 := discord.GuildMemberRoleAdd(discordServerId, "316091695941025793", discordWaintingRoleId)
|
|
if err2 != nil {
|
|
panic(err2)
|
|
}
|
|
*/
|
|
|
|
}
|