Add exchange code discord command
This commit is contained in:
parent
7d51c8dd07
commit
169948fff5
|
@ -2,6 +2,7 @@ package discord
|
|||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/ectrc/snow/aid"
|
||||
|
@ -174,4 +175,34 @@ func meHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func codeHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
player := person.FindByDiscord(i.Member.User.ID)
|
||||
if player == nil {
|
||||
s.InteractionRespond(i.Interaction, &ErrorNoAccount)
|
||||
return
|
||||
}
|
||||
|
||||
code := player.ID + "=" + time.Now().Format("2006-01-02T15:04:05.999Z")
|
||||
encrypted, sig := aid.KeyPair.EncryptAndSignB64([]byte(code))
|
||||
decrypt, err := aid.KeyPair.DecryptAndVerifyB64(encrypted, sig)
|
||||
|
||||
if err || string(decrypt) != code {
|
||||
aid.Print("Failed to verify code that was just generated so we're not going to send it")
|
||||
return
|
||||
}
|
||||
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Embeds: []*discordgo.MessageEmbed{
|
||||
NewEmbedBuilder().
|
||||
SetColor(0x2b2d31).
|
||||
SetDescription("`" + encrypted + "`").
|
||||
Build(),
|
||||
},
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
}
|
|
@ -49,7 +49,7 @@ func IntialiseClient() {
|
|||
addCommands()
|
||||
|
||||
if len(StaticClient.Commands) != len(StaticClient.GetRegisteredCommands()) {
|
||||
StaticClient.UnregisterCommands()
|
||||
// StaticClient.UnregisterCommands()
|
||||
StaticClient.RegisterCommands()
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,30 @@ func addCommands() {
|
|||
Handler: createModalHandler,
|
||||
})
|
||||
|
||||
addCommand(&DiscordCommand{
|
||||
Command: &discordgo.ApplicationCommand{
|
||||
Name: "me",
|
||||
Description: "Lookup your own information.",
|
||||
},
|
||||
Handler: meHandler,
|
||||
})
|
||||
|
||||
addCommand(&DiscordCommand{
|
||||
Command: &discordgo.ApplicationCommand{
|
||||
Name: "delete",
|
||||
Description: "Delete your account with the bot.",
|
||||
},
|
||||
Handler: deleteHandler,
|
||||
})
|
||||
|
||||
addCommand(&DiscordCommand{
|
||||
Command: &discordgo.ApplicationCommand{
|
||||
Name: "code",
|
||||
Description: "Generate a one-time use code to link your account.",
|
||||
},
|
||||
Handler: codeHandler,
|
||||
})
|
||||
|
||||
addCommand(&DiscordCommand{
|
||||
Command: &discordgo.ApplicationCommand{
|
||||
Name: "information",
|
||||
|
@ -63,22 +87,6 @@ func addCommands() {
|
|||
AdminOnly: true,
|
||||
})
|
||||
|
||||
addCommand(&DiscordCommand{
|
||||
Command: &discordgo.ApplicationCommand{
|
||||
Name: "me",
|
||||
Description: "Lookup your own information.",
|
||||
},
|
||||
Handler: meHandler,
|
||||
})
|
||||
|
||||
addCommand(&DiscordCommand{
|
||||
Command: &discordgo.ApplicationCommand{
|
||||
Name: "delete",
|
||||
Description: "Delete your account with the bot.",
|
||||
},
|
||||
Handler: deleteHandler,
|
||||
})
|
||||
|
||||
addCommand(&DiscordCommand{
|
||||
Command: &discordgo.ApplicationCommand{
|
||||
Name: "ban",
|
||||
|
|
|
@ -171,7 +171,7 @@ func PostTokenPassword(c *fiber.Ctx, body *FortniteTokenBody) error {
|
|||
})
|
||||
}
|
||||
|
||||
func GetOAuthVerify(c *fiber.Ctx) error {
|
||||
func GetTokenVerify(c *fiber.Ctx) error {
|
||||
auth := c.Get("Authorization")
|
||||
if auth == "" {
|
||||
return c.Status(fiber.StatusForbidden).JSON(aid.ErrorBadRequest("Authorization Header is empty"))
|
||||
|
@ -216,6 +216,10 @@ func GetOAuthVerify(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
func DeleteToken(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(aid.JSON{})
|
||||
}
|
||||
|
||||
func MiddlewareFortnite(c *fiber.Ctx) error {
|
||||
auth := c.Get("Authorization")
|
||||
if auth == "" {
|
||||
|
@ -279,10 +283,6 @@ func MiddlewareWeb(c *fiber.Ctx) error {
|
|||
return c.Next()
|
||||
}
|
||||
|
||||
func DeleteToken(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(aid.JSON{})
|
||||
}
|
||||
|
||||
func GetPublicAccount(c *fiber.Ctx) error {
|
||||
person := p.Find(c.Params("accountId"))
|
||||
if person == nil {
|
||||
|
|
2
main.go
2
main.go
|
@ -70,7 +70,7 @@ func main() {
|
|||
account.Get("/public/account/:accountId", handlers.GetPublicAccount)
|
||||
account.Get("/public/account/:accountId/externalAuths", handlers.GetPublicAccountExternalAuths)
|
||||
account.Get("/public/account/displayName/:displayName", handlers.GetPublicAccountByDisplayName)
|
||||
account.Get("/oauth/verify", handlers.GetOAuthVerify)
|
||||
account.Get("/oauth/verify", handlers.GetTokenVerify)
|
||||
account.Post("/oauth/token", handlers.PostFortniteToken)
|
||||
account.Delete("/oauth/sessions/kill", handlers.DeleteToken)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user