mid day commit
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package commands
|
||||
|
||||
import "github.com/disgoorg/disgo/discord"
|
||||
import (
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/json"
|
||||
)
|
||||
|
||||
func getPingCommand() discord.SlashCommandCreate {
|
||||
return discord.SlashCommandCreate{
|
||||
@@ -9,6 +12,41 @@ func getPingCommand() discord.SlashCommandCreate {
|
||||
}
|
||||
}
|
||||
|
||||
func getSyncCommand() discord.SlashCommandCreate {
|
||||
perms := json.NewNullable(discord.PermissionManageChannels)
|
||||
|
||||
return discord.SlashCommandCreate{
|
||||
Name: "sync",
|
||||
Description: "Register/remove a channel to sync.",
|
||||
DefaultMemberPermissions: &perms,
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
discord.ApplicationCommandOptionSubCommand{
|
||||
Name: "register",
|
||||
Description: "Register a channel for logging",
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
discord.ApplicationCommandOptionChannel{
|
||||
Name: "channel",
|
||||
Description: "Channel to register",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
discord.ApplicationCommandOptionSubCommand{
|
||||
Name: "remove",
|
||||
Description: "Remove a channel from logging",
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
discord.ApplicationCommandOptionChannel{
|
||||
Name: "channel",
|
||||
Description: "Channel to remove",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var Commands = []discord.ApplicationCommandCreate{
|
||||
getPingCommand(),
|
||||
getSyncCommand(),
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ func PingHandler(e *handler.CommandEvent) error {
|
||||
}
|
||||
|
||||
lat := float64(msLatency)
|
||||
if lat > 5000 {
|
||||
lat = 5000
|
||||
if lat > 1500 {
|
||||
lat = 1500
|
||||
}
|
||||
red := int((lat / 5000) * 255)
|
||||
red := int((lat / 1500) * 255)
|
||||
green := 255 - red
|
||||
color := (red << 16) | (green << 8)
|
||||
|
||||
@@ -40,8 +40,9 @@ func PingHandler(e *handler.CommandEvent) error {
|
||||
SetColor(color).
|
||||
Build()
|
||||
|
||||
return e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
SetEmbeds(embed).
|
||||
Build(),
|
||||
return e.CreateMessage(
|
||||
discord.NewMessageCreateBuilder().
|
||||
SetEmbeds(embed).
|
||||
Build(),
|
||||
)
|
||||
}
|
||||
|
||||
74
relay/commands/sync.go
Normal file
74
relay/commands/sync.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"homestead/homestead_to_go/relay/storage"
|
||||
"log"
|
||||
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/handler"
|
||||
)
|
||||
|
||||
var ChannelStore *storage.ChannelStorage
|
||||
|
||||
func InitStorage() error {
|
||||
var err error
|
||||
ChannelStore, err = storage.NewChannelStorage("registered_channels.json")
|
||||
return err
|
||||
}
|
||||
|
||||
func SyncHandler(e *handler.CommandEvent) error {
|
||||
data := e.SlashCommandInteractionData()
|
||||
|
||||
subcommand := data.SubCommandName
|
||||
if subcommand == nil {
|
||||
return e.CreateMessage(discord.MessageCreate{
|
||||
Content: "Invalid subcommand!",
|
||||
Flags: discord.MessageFlagEphemeral,
|
||||
})
|
||||
}
|
||||
|
||||
channelID, ok := data.OptSnowflake("channel")
|
||||
if !ok {
|
||||
return e.CreateMessage(discord.MessageCreate{
|
||||
Content: "Channel not provided!",
|
||||
Flags: discord.MessageFlagEphemeral,
|
||||
})
|
||||
}
|
||||
|
||||
switch *subcommand {
|
||||
case "register":
|
||||
if err := ChannelStore.AddChannel(channelID); err != nil {
|
||||
log.Printf("Error registering channel: %v", err)
|
||||
return e.CreateMessage(discord.MessageCreate{
|
||||
Content: "❌ Failed to register channel!",
|
||||
Flags: discord.MessageFlagEphemeral,
|
||||
})
|
||||
}
|
||||
|
||||
return e.CreateMessage(discord.MessageCreate{
|
||||
Content: fmt.Sprintf("✅ Registered <#%s> for message logging!", channelID),
|
||||
Flags: discord.MessageFlagEphemeral,
|
||||
})
|
||||
|
||||
case "remove":
|
||||
if err := ChannelStore.RemoveChannel(channelID); err != nil {
|
||||
log.Printf("Error removing channel: %v", err)
|
||||
return e.CreateMessage(discord.MessageCreate{
|
||||
Content: "❌ Failed to remove channel!",
|
||||
Flags: discord.MessageFlagEphemeral,
|
||||
})
|
||||
}
|
||||
|
||||
return e.CreateMessage(discord.MessageCreate{
|
||||
Content: fmt.Sprintf("✅ Removed <#%s> from message logging!", channelID),
|
||||
Flags: discord.MessageFlagEphemeral,
|
||||
})
|
||||
|
||||
default:
|
||||
return e.CreateMessage(discord.MessageCreate{
|
||||
Content: "Unknown subcommand!",
|
||||
Flags: discord.MessageFlagEphemeral,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user