mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 17:10:10 +00:00
discord: fix up /inv basic functionality
sending now succeeds, and a reponse of "Invite sent." is given to the requester. Also some formatting changes.
This commit is contained in:
parent
dd93758b0e
commit
e52e21a54b
51
discord.go
51
discord.go
@ -2,8 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dg "github.com/bwmarrin/discordgo"
|
dg "github.com/bwmarrin/discordgo"
|
||||||
@ -351,7 +351,7 @@ func (d *DiscordDaemon) registerCommands() {
|
|||||||
Name: "user",
|
Name: "user",
|
||||||
Description: "User to Invite",
|
Description: "User to Invite",
|
||||||
Required: true,
|
Required: true,
|
||||||
}, // running with just one option for now to mesh with what we've got, also may have the syntax wrong here
|
}, // running with just one option for now to mesh with what we've got, also may have the syntax wrong here
|
||||||
/*{
|
/*{
|
||||||
Type: dg.ApplicationCommandOptionInteger,
|
Type: dg.ApplicationCommandOptionInteger,
|
||||||
Name: "expire after",
|
Name: "expire after",
|
||||||
@ -539,10 +539,10 @@ func (d *DiscordDaemon) cmdLang(s *dg.Session, i *dg.InteractionCreate, lang str
|
|||||||
|
|
||||||
func (d *DiscordDaemon) cmdInvite(s *dg.Session, i *dg.InteractionCreate, lang string) {
|
func (d *DiscordDaemon) cmdInvite(s *dg.Session, i *dg.InteractionCreate, lang string) {
|
||||||
channel, err := s.UserChannelCreate(i.Interaction.Member.User.ID)
|
channel, err := s.UserChannelCreate(i.Interaction.Member.User.ID)
|
||||||
requestor := d.MustGetUser(channel.ID, i.Interaction.Member.User.ID, i.Interaction.Member.User.Discriminator, i.Interaction.Member.User.Username)
|
requester := d.MustGetUser(channel.ID, i.Interaction.Member.User.ID, i.Interaction.Member.User.Discriminator, i.Interaction.Member.User.Username)
|
||||||
d.users[i.Interaction.Member.User.ID] = requestor
|
d.users[i.Interaction.Member.User.ID] = requester
|
||||||
invuser := fmt.Sprintf("%v", i.ApplicationCommandData().Options[0].Value)
|
recipient := i.ApplicationCommandData().Options[0].UserValue(s)
|
||||||
d.app.debug.Println(invuser)
|
// d.app.debug.Println(invuser)
|
||||||
//label := i.ApplicationCommandData().Options[2].StringValue()
|
//label := i.ApplicationCommandData().Options[2].StringValue()
|
||||||
//profile := i.ApplicationCommandData().Options[3].StringValue()
|
//profile := i.ApplicationCommandData().Options[3].StringValue()
|
||||||
//mins, err := strconv.Atoi(i.ApplicationCommandData().Options[1].StringValue())
|
//mins, err := strconv.Atoi(i.ApplicationCommandData().Options[1].StringValue())
|
||||||
@ -551,17 +551,17 @@ func (d *DiscordDaemon) cmdInvite(s *dg.Session, i *dg.InteractionCreate, lang s
|
|||||||
// expmin = mins
|
// expmin = mins
|
||||||
//}
|
//}
|
||||||
// Need to check whether requestor is linked to the admin account *possibly add Admin bool to DiscordUser struct
|
// Need to check whether requestor is linked to the admin account *possibly add Admin bool to DiscordUser struct
|
||||||
requestoremail, ok := d.app.storage.GetEmailsKey(requestor.JellyfinID)
|
requesterEmail, ok := d.app.storage.GetEmailsKey(requester.JellyfinID)
|
||||||
if !ok {
|
if !ok {
|
||||||
d.app.err.Printf("Failed to verify admin")
|
d.app.err.Printf("Failed to verify admin")
|
||||||
}
|
}
|
||||||
if !requestoremail.Admin {
|
if !requesterEmail.Admin {
|
||||||
d.app.err.Printf("User is not admin")
|
d.app.err.Printf("User is not admin")
|
||||||
}
|
}
|
||||||
// variation of app.GenerateInvite, some parts commented to potentially add back in later with the other options
|
// variation of app.GenerateInvite, some parts commented to potentially add back in later with the other options
|
||||||
//d.app.debug.Println("Generating new invite with options: %s: %i: %s: %s", invuser, expmin, profile, label)
|
//d.app.debug.Println("Generating new invite with options: %s: %i: %s: %s", invuser, expmin, profile, label)
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
validTill := currentTime.Add(time.Minute*time.Duration(expmin))
|
validTill := currentTime.Add(time.Minute * time.Duration(expmin))
|
||||||
// make sure code doesn't begin with number
|
// make sure code doesn't begin with number
|
||||||
inviteCode := shortuuid.New()
|
inviteCode := shortuuid.New()
|
||||||
_, err = strconv.Atoi(string(inviteCode[0]))
|
_, err = strconv.Atoi(string(inviteCode[0]))
|
||||||
@ -583,24 +583,43 @@ func (d *DiscordDaemon) cmdInvite(s *dg.Session, i *dg.InteractionCreate, lang s
|
|||||||
invite.UserMinutes = req.UserMinutes
|
invite.UserMinutes = req.UserMinutes
|
||||||
}*/
|
}*/
|
||||||
invite.ValidTill = validTill
|
invite.ValidTill = validTill
|
||||||
if invuser != "" && d.app.config.Section("invite_emails").Key("enabled").MustBool(false) {
|
if recipient != nil && d.app.config.Section("invite_emails").Key("enabled").MustBool(false) {
|
||||||
discord := ""
|
|
||||||
d.app.debug.Printf("%s: Sending invite message", inviteCode)
|
d.app.debug.Printf("%s: Sending invite message", inviteCode)
|
||||||
invname, err := d.bot.GuildMember(d.guildID, invuser)
|
invname, err := d.bot.GuildMember(d.guildID, recipient.ID)
|
||||||
invite.SendTo = invname.User.Username
|
invite.SendTo = invname.User.Username
|
||||||
|
|
||||||
msg, err := d.app.email.constructInvite(inviteCode, invite, d.app, false)
|
msg, err := d.app.email.constructInvite(inviteCode, invite, d.app, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
invite.SendTo = fmt.Sprintf("Failed to send to %s", invuser)
|
invite.SendTo = fmt.Sprintf("Failed to send to %s", RenderDiscordUsername(recipient))
|
||||||
d.app.err.Printf("%s: Failed to construct invite message: %v", inviteCode, err)
|
d.app.err.Printf("%s: Failed to construct invite message: %v", inviteCode, err)
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
err = d.app.discord.SendDM(msg, discord)
|
err = d.app.discord.SendDM(msg, recipient.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
invite.SendTo = fmt.Sprintf("Failed to send to %s", invuser)
|
invite.SendTo = fmt.Sprintf("Failed to send to %s", RenderDiscordUsername(recipient))
|
||||||
d.app.err.Printf("%s: %s: %v", inviteCode, invite.SendTo, err)
|
d.app.err.Printf("%s: %s: %v", inviteCode, invite.SendTo, err)
|
||||||
|
err := s.InteractionRespond(i.Interaction, &dg.InteractionResponse{
|
||||||
|
Type: dg.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &dg.InteractionResponseData{
|
||||||
|
Content: d.app.storage.lang.Telegram[lang].Strings.get("sentInviteFailure"),
|
||||||
|
Flags: 64, // Ephemeral
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
d.app.err.Printf("Discord: Failed to send message to \"%s\": %v", RenderDiscordUsername(requester), err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
d.app.info.Printf("%s: Sent invite email to \"%s\"", inviteCode, invuser)
|
d.app.info.Printf("%s: Sent invite email to \"%s\"", inviteCode, RenderDiscordUsername(recipient))
|
||||||
|
err := s.InteractionRespond(i.Interaction, &dg.InteractionResponse{
|
||||||
|
Type: dg.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &dg.InteractionResponseData{
|
||||||
|
Content: d.app.storage.lang.Telegram[lang].Strings.get("sentInvite"),
|
||||||
|
Flags: 64, // Ephemeral
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
d.app.err.Printf("Discord: Failed to send message to \"%s\": %v", RenderDiscordUsername(requester), err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
"languageMessage": "Note: See available languages with {command}, and set language with {command} <language code>.",
|
"languageMessage": "Note: See available languages with {command}, and set language with {command} <language code>.",
|
||||||
"languageMessageDiscord": "Note: set your language with /lang <language name>.",
|
"languageMessageDiscord": "Note: set your language with /lang <language name>.",
|
||||||
"languageSet": "Language set to {language}.",
|
"languageSet": "Language set to {language}.",
|
||||||
"discordDMs": "Please check your DMs for a response."
|
"discordDMs": "Please check your DMs for a response.",
|
||||||
|
"sentInvite": "Sent invite.",
|
||||||
|
"sentInviteFailure": "Failed to send invite, check logs."
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user