pepster/commandLink.go

54 lines
1.2 KiB
Go
Raw Permalink Normal View History

2021-07-19 22:06:54 +00:00
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
"gorm.io/gorm/clause"
"pepster/models"
)
func (p *Pepster) commandLink() Command {
return Command{
Name: "link",
Description: "Links your osu! account to your Discord account.",
Options: []*CommandOption{
&CommandOption{
Type: CommandOptionString,
Name: "username",
Description: "Your osu! username",
Required: true,
},
},
Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
var user *discordgo.User
if i.User != nil {
user = i.User
} else if i.Member != nil {
user = i.Member.User
}
dbUser := models.User{
DiscordID: user.ID,
OsuID: 2688103,
}
p.db.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "discord_id"}},
UpdateAll: true,
}).Create(&dbUser)
fmt.Println("Updated", dbUser)
p.updateStatus <- true
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf(":thumbsup: Linked osu! user **%s** to **%s**", "IOException", user.String()),
},
})
},
}
}