mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-29 12:30:11 +00:00
Compare commits
9 Commits
70afc21217
...
2fb2f3ee74
Author | SHA1 | Date | |
---|---|---|---|
2fb2f3ee74 | |||
7813c8c68b | |||
e528f7c348 | |||
77f6b1042e | |||
7db94dcebf | |||
62923d5e45 | |||
10a32ad1ae | |||
e52e21a54b | |||
7c861e5763 |
@ -17,6 +17,18 @@ const (
|
|||||||
CAPTCHA_VALIDITY = 20 * 60 // Seconds
|
CAPTCHA_VALIDITY = 20 * 60 // Seconds
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GenerateInviteCode generates an invite code in the correct format.
|
||||||
|
func GenerateInviteCode() string {
|
||||||
|
// make sure code doesn't begin with number
|
||||||
|
inviteCode := shortuuid.New()
|
||||||
|
_, err := strconv.Atoi(string(inviteCode[0]))
|
||||||
|
for err == nil {
|
||||||
|
inviteCode = shortuuid.New()
|
||||||
|
_, err = strconv.Atoi(string(inviteCode[0]))
|
||||||
|
}
|
||||||
|
return inviteCode
|
||||||
|
}
|
||||||
|
|
||||||
func (app *appContext) checkInvites() {
|
func (app *appContext) checkInvites() {
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
for _, data := range app.storage.GetInvites() {
|
for _, data := range app.storage.GetInvites() {
|
||||||
@ -150,14 +162,8 @@ func (app *appContext) GenerateInvite(gc *gin.Context) {
|
|||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
validTill := currentTime.AddDate(0, req.Months, req.Days)
|
validTill := currentTime.AddDate(0, req.Months, req.Days)
|
||||||
validTill = validTill.Add(time.Hour*time.Duration(req.Hours) + time.Minute*time.Duration(req.Minutes))
|
validTill = validTill.Add(time.Hour*time.Duration(req.Hours) + time.Minute*time.Duration(req.Minutes))
|
||||||
// make sure code doesn't begin with number
|
|
||||||
inviteCode := shortuuid.New()
|
|
||||||
_, err := strconv.Atoi(string(inviteCode[0]))
|
|
||||||
for err == nil {
|
|
||||||
inviteCode = shortuuid.New()
|
|
||||||
_, err = strconv.Atoi(string(inviteCode[0]))
|
|
||||||
}
|
|
||||||
var invite Invite
|
var invite Invite
|
||||||
|
invite.Code = GenerateInviteCode()
|
||||||
if req.Label != "" {
|
if req.Label != "" {
|
||||||
invite.Label = req.Label
|
invite.Label = req.Label
|
||||||
}
|
}
|
||||||
@ -185,7 +191,7 @@ func (app *appContext) GenerateInvite(gc *gin.Context) {
|
|||||||
if req.SendTo != "" && app.config.Section("invite_emails").Key("enabled").MustBool(false) {
|
if req.SendTo != "" && app.config.Section("invite_emails").Key("enabled").MustBool(false) {
|
||||||
addressValid := false
|
addressValid := false
|
||||||
discord := ""
|
discord := ""
|
||||||
app.debug.Printf("%s: Sending invite message", inviteCode)
|
app.debug.Printf("%s: Sending invite message", invite.Code)
|
||||||
if discordEnabled && !strings.Contains(req.SendTo, "@") {
|
if discordEnabled && !strings.Contains(req.SendTo, "@") {
|
||||||
users := app.discord.GetUsers(req.SendTo)
|
users := app.discord.GetUsers(req.SendTo)
|
||||||
if len(users) == 0 {
|
if len(users) == 0 {
|
||||||
@ -202,10 +208,10 @@ func (app *appContext) GenerateInvite(gc *gin.Context) {
|
|||||||
invite.SendTo = req.SendTo
|
invite.SendTo = req.SendTo
|
||||||
}
|
}
|
||||||
if addressValid {
|
if addressValid {
|
||||||
msg, err := app.email.constructInvite(inviteCode, invite, app, false)
|
msg, err := app.email.constructInvite(invite.Code, invite, app, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
invite.SendTo = fmt.Sprintf("Failed to send to %s", req.SendTo)
|
invite.SendTo = fmt.Sprintf("Failed to send to %s", req.SendTo)
|
||||||
app.err.Printf("%s: Failed to construct invite message: %v", inviteCode, err)
|
app.err.Printf("%s: Failed to construct invite message: %v", invite.Code, err)
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
if discord != "" {
|
if discord != "" {
|
||||||
@ -215,9 +221,9 @@ func (app *appContext) GenerateInvite(gc *gin.Context) {
|
|||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
invite.SendTo = fmt.Sprintf("Failed to send to %s", req.SendTo)
|
invite.SendTo = fmt.Sprintf("Failed to send to %s", req.SendTo)
|
||||||
app.err.Printf("%s: %s: %v", inviteCode, invite.SendTo, err)
|
app.err.Printf("%s: %s: %v", invite.Code, invite.SendTo, err)
|
||||||
} else {
|
} else {
|
||||||
app.info.Printf("%s: Sent invite email to \"%s\"", inviteCode, req.SendTo)
|
app.info.Printf("%s: Sent invite email to \"%s\"", invite.Code, req.SendTo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,7 +235,7 @@ func (app *appContext) GenerateInvite(gc *gin.Context) {
|
|||||||
invite.Profile = "Default"
|
invite.Profile = "Default"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.storage.SetInvitesKey(inviteCode, invite)
|
app.storage.SetInvitesKey(invite.Code, invite)
|
||||||
respondBool(200, true, gc)
|
respondBool(200, true, gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/lithammer/shortuuid/v3"
|
|
||||||
"github.com/timshannon/badgerhold/v4"
|
"github.com/timshannon/badgerhold/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -151,13 +149,7 @@ func (app *appContext) EnableReferralForProfile(gc *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate new code for referral template
|
// Generate new code for referral template
|
||||||
inv.Code = shortuuid.New()
|
inv.Code = GenerateInviteCode()
|
||||||
// make sure code doesn't begin with number
|
|
||||||
_, err := strconv.Atoi(string(inv.Code[0]))
|
|
||||||
for err == nil {
|
|
||||||
inv.Code = shortuuid.New()
|
|
||||||
_, err = strconv.Atoi(string(inv.Code[0]))
|
|
||||||
}
|
|
||||||
inv.Created = time.Now()
|
inv.Created = time.Now()
|
||||||
inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour)
|
inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour)
|
||||||
inv.IsReferral = true
|
inv.IsReferral = true
|
||||||
|
@ -3,13 +3,11 @@ package main
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/lithammer/shortuuid/v3"
|
|
||||||
"github.com/timshannon/badgerhold/v4"
|
"github.com/timshannon/badgerhold/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -673,13 +671,7 @@ func (app *appContext) GetMyReferral(gc *gin.Context) {
|
|||||||
respondBool(400, false, gc)
|
respondBool(400, false, gc)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
inv.Code = shortuuid.New()
|
inv.Code = GenerateInviteCode()
|
||||||
// make sure code doesn't begin with number
|
|
||||||
_, err := strconv.Atoi(string(inv.Code[0]))
|
|
||||||
for err == nil {
|
|
||||||
inv.Code = shortuuid.New()
|
|
||||||
_, err = strconv.Atoi(string(inv.Code[0]))
|
|
||||||
}
|
|
||||||
inv.Created = time.Now()
|
inv.Created = time.Now()
|
||||||
inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour)
|
inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour)
|
||||||
inv.IsReferral = true
|
inv.IsReferral = true
|
||||||
@ -689,13 +681,7 @@ func (app *appContext) GetMyReferral(gc *gin.Context) {
|
|||||||
// 3. We found an invite for us, but it's expired.
|
// 3. We found an invite for us, but it's expired.
|
||||||
// We delete it from storage, and put it back with a fresh code and expiry.
|
// We delete it from storage, and put it back with a fresh code and expiry.
|
||||||
app.storage.DeleteInvitesKey(inv.Code)
|
app.storage.DeleteInvitesKey(inv.Code)
|
||||||
inv.Code = shortuuid.New()
|
inv.Code = GenerateInviteCode()
|
||||||
// make sure code doesn't begin with number
|
|
||||||
_, err := strconv.Atoi(string(inv.Code[0]))
|
|
||||||
for err == nil {
|
|
||||||
inv.Code = shortuuid.New()
|
|
||||||
_, err = strconv.Atoi(string(inv.Code[0]))
|
|
||||||
}
|
|
||||||
inv.Created = time.Now()
|
inv.Created = time.Now()
|
||||||
inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour)
|
inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour)
|
||||||
app.storage.SetInvitesKey(inv.Code, inv)
|
app.storage.SetInvitesKey(inv.Code, inv)
|
||||||
|
10
api-users.go
10
api-users.go
@ -3,14 +3,12 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/hrfee/mediabrowser"
|
"github.com/hrfee/mediabrowser"
|
||||||
"github.com/lithammer/shortuuid/v3"
|
|
||||||
"github.com/timshannon/badgerhold/v4"
|
"github.com/timshannon/badgerhold/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -707,13 +705,7 @@ func (app *appContext) EnableReferralForUsers(gc *gin.Context) {
|
|||||||
|
|
||||||
// 2. Generate referral invite.
|
// 2. Generate referral invite.
|
||||||
inv := baseInv
|
inv := baseInv
|
||||||
inv.Code = shortuuid.New()
|
inv.Code = GenerateInviteCode()
|
||||||
// make sure code doesn't begin with number
|
|
||||||
_, err := strconv.Atoi(string(inv.Code[0]))
|
|
||||||
for err == nil {
|
|
||||||
inv.Code = shortuuid.New()
|
|
||||||
_, err = strconv.Atoi(string(inv.Code[0]))
|
|
||||||
}
|
|
||||||
inv.Created = time.Now()
|
inv.Created = time.Now()
|
||||||
inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour)
|
inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour)
|
||||||
inv.IsReferral = true
|
inv.IsReferral = true
|
||||||
|
180
discord.go
180
discord.go
@ -3,11 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dg "github.com/bwmarrin/discordgo"
|
dg "github.com/bwmarrin/discordgo"
|
||||||
"github.com/lithammer/shortuuid/v3"
|
|
||||||
"github.com/timshannon/badgerhold/v4"
|
"github.com/timshannon/badgerhold/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -349,34 +347,41 @@ func (d *DiscordDaemon) registerCommands() {
|
|||||||
{
|
{
|
||||||
Type: dg.ApplicationCommandOptionUser,
|
Type: dg.ApplicationCommandOptionUser,
|
||||||
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
|
},
|
||||||
/*{
|
{
|
||||||
Type: dg.ApplicationCommandOptionInteger,
|
Type: dg.ApplicationCommandOptionInteger,
|
||||||
Name: "expire after",
|
Name: "expiry",
|
||||||
Description: "Time in minutes before expiration",
|
Description: "Time in minutes before expiration.",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
|
/* Label should be automatically set to something like "Discord invite for @username"
|
||||||
{
|
{
|
||||||
Type: dg.ApplicationCommandOptionString,
|
Type: dg.ApplicationCommandOptionString,
|
||||||
Name: "label",
|
Name: "label",
|
||||||
Description: "Label to apply to the user created with this invite",
|
Description: "Label given to this invite (shown on the Admin page)",
|
||||||
|
Required: false,
|
||||||
|
}, */
|
||||||
|
{
|
||||||
|
Type: dg.ApplicationCommandOptionString,
|
||||||
|
Name: "user_label",
|
||||||
|
Description: "Label given to users created with this invite.",
|
||||||
Required: false,
|
Required: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: dg.ApplicationCommandOptionString,
|
Type: dg.ApplicationCommandOptionString,
|
||||||
Name: "profile",
|
Name: "profile",
|
||||||
Description: "Profile to apply to the user created with this invite",
|
Description: "Profile to apply. Restart jfa-go if there's any missing.",
|
||||||
Required: false,
|
Required: false,
|
||||||
}, */
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
commands[1].Options[0].Choices = make([]*dg.ApplicationCommandOptionChoice, len(d.app.storage.lang.Telegram))
|
commands[1].Options[0].Choices = make([]*dg.ApplicationCommandOptionChoice, len(d.app.storage.lang.Telegram))
|
||||||
i := 0
|
i := 0
|
||||||
for code := range d.app.storage.lang.Telegram {
|
for code := range d.app.storage.lang.Telegram {
|
||||||
d.app.debug.Printf("Registering choice \"%s\":\"%s\"\n", d.app.storage.lang.Telegram[code].Meta.Name, code)
|
d.app.debug.Printf("Discord: registering lang choice \"%s\":\"%s\"\n", d.app.storage.lang.Telegram[code].Meta.Name, code)
|
||||||
commands[1].Options[0].Choices[i] = &dg.ApplicationCommandOptionChoice{
|
commands[1].Options[0].Choices[i] = &dg.ApplicationCommandOptionChoice{
|
||||||
Name: d.app.storage.lang.Telegram[code].Meta.Name,
|
Name: d.app.storage.lang.Telegram[code].Meta.Name,
|
||||||
Value: code,
|
Value: code,
|
||||||
@ -384,6 +389,17 @@ func (d *DiscordDaemon) registerCommands() {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Maybe make this reload when profiles change
|
||||||
|
profiles := d.app.storage.GetProfiles()
|
||||||
|
commands[3].Options[3].Choices = make([]*dg.ApplicationCommandOptionChoice, len(profiles))
|
||||||
|
for i, profile := range profiles {
|
||||||
|
d.app.debug.Printf("Discord: registering profile choice \"%s\"", profile.Name)
|
||||||
|
commands[3].Options[3].Choices[i] = &dg.ApplicationCommandOptionChoice{
|
||||||
|
Name: profile.Name,
|
||||||
|
Value: profile.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// d.deregisterCommands()
|
// d.deregisterCommands()
|
||||||
|
|
||||||
d.commandIDs = make([]string, len(commands))
|
d.commandIDs = make([]string, len(commands))
|
||||||
@ -409,7 +425,7 @@ func (d *DiscordDaemon) deregisterCommands() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, cmd := range existingCommands {
|
for _, cmd := range existingCommands {
|
||||||
if err := d.bot.ApplicationCommandDelete(d.bot.State.User.ID, "", cmd.ID); err != nil {
|
if err := d.bot.ApplicationCommandDelete(d.bot.State.User.ID, d.guildID, cmd.ID); err != nil {
|
||||||
d.app.err.Printf("Failed to deregister command: %v", err)
|
d.app.err.Printf("Failed to deregister command: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -539,82 +555,120 @@ 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)
|
if err != nil {
|
||||||
d.users[i.Interaction.Member.User.ID] = requestor
|
d.app.err.Printf("Discord: Failed to create private channel with \"%s\": %v", i.Interaction.Member.User.Username, err)
|
||||||
invuser := fmt.Sprintf("%v", i.ApplicationCommandData().Options[0].Value)
|
return
|
||||||
d.app.debug.Println(invuser)
|
}
|
||||||
|
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] = requester
|
||||||
|
recipient := i.ApplicationCommandData().Options[0].UserValue(s)
|
||||||
|
// 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())
|
||||||
expmin := 30
|
|
||||||
//if mins > 0 {
|
//if mins > 0 {
|
||||||
// expmin = mins
|
// expmin = mins
|
||||||
//}
|
//}
|
||||||
// Check whether requestor is linked to the admin account
|
// Check whether requestor is linked to the admin account
|
||||||
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")
|
||||||
//add response message
|
//add response message
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// variation of app.GenerateInvite, some parts commented to potentially add back in later with the other command options
|
|
||||||
//d.app.debug.Println("Generating new invite with options: %s: %i: %s: %s", invuser, expmin, profile, label)
|
var expiryMinutes int64 = 30
|
||||||
currentTime := time.Now()
|
userLabel := ""
|
||||||
validTill := currentTime.Add(time.Minute*time.Duration(expmin))
|
profileName := ""
|
||||||
// make sure code doesn't begin with number
|
|
||||||
inviteCode := shortuuid.New()
|
for i, opt := range i.ApplicationCommandData().Options {
|
||||||
_, err = strconv.Atoi(string(inviteCode[0]))
|
if i == 0 {
|
||||||
for err == nil {
|
continue
|
||||||
inviteCode = shortuuid.New()
|
}
|
||||||
_, err = strconv.Atoi(string(inviteCode[0]))
|
switch opt.Name {
|
||||||
|
case "expiry":
|
||||||
|
expiryMinutes = opt.IntValue()
|
||||||
|
case "user_label":
|
||||||
|
userLabel = opt.StringValue()
|
||||||
|
case "profile":
|
||||||
|
profileName = opt.StringValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var invite Invite
|
|
||||||
//if label != "" {
|
currentTime := time.Now()
|
||||||
// invite.Label = label
|
|
||||||
//}
|
validTill := currentTime.Add(time.Minute * time.Duration(expiryMinutes))
|
||||||
invite.Created = currentTime
|
|
||||||
invite.RemainingUses = 1
|
invite := Invite{
|
||||||
invite.UserExpiry = false
|
Code: GenerateInviteCode(),
|
||||||
/*if invite.UserExpiry {
|
Created: currentTime,
|
||||||
invite.UserMonths = req.UserMonths
|
RemainingUses: 1,
|
||||||
invite.UserDays = req.UserDays
|
UserExpiry: false,
|
||||||
invite.UserHours = req.UserHours
|
ValidTill: validTill,
|
||||||
invite.UserMinutes = req.UserMinutes
|
UserLabel: userLabel,
|
||||||
}*/
|
Profile: "Default",
|
||||||
invite.ValidTill = validTill
|
Label: fmt.Sprintf("Discord: %s", RenderDiscordUsername(recipient)),
|
||||||
if invuser != "" && d.app.config.Section("invite_emails").Key("enabled").MustBool(false) {
|
}
|
||||||
d.app.debug.Printf("%s: Sending invite message", inviteCode)
|
if profileName != "" {
|
||||||
invname, err := d.bot.GuildMember(d.guildID, invuser)
|
if _, ok := d.app.storage.GetProfileKey(profileName); ok {
|
||||||
|
invite.Profile = profileName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if recipient != nil && d.app.config.Section("invite_emails").Key("enabled").MustBool(false) {
|
||||||
|
d.app.debug.Printf("%s: Sending invite message", invite.Code)
|
||||||
|
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(invite.Code, 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", invite.Code, err)
|
||||||
//add response message
|
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 {
|
||||||
var err error
|
var err error
|
||||||
err = d.app.discord.SendDM(msg, invuser)
|
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", invite.Code, invite.SendTo, err)
|
||||||
//add response message
|
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\"", invite.Code, RenderDiscordUsername(recipient))
|
||||||
//add response message
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if profile != "" {
|
//if profile != "" {
|
||||||
// if _, ok := d.app.storage.GetProfileKey(profile); ok {
|
d.app.storage.SetInvitesKey(invite.Code, invite)
|
||||||
// invite.Profile = profile
|
|
||||||
// } else {
|
|
||||||
// invite.Profile = "Default"
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
d.app.storage.SetInvitesKey(inviteCode, invite)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscordDaemon) messageHandler(s *dg.Session, m *dg.MessageCreate) {
|
func (d *DiscordDaemon) messageHandler(s *dg.Session, m *dg.MessageCreate) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"name": "Angol (US)"
|
"name": "Magyar (HU)"
|
||||||
},
|
},
|
||||||
"strings": {
|
"strings": {
|
||||||
"invites": "Meghívások",
|
"invites": "Meghívások",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"name": "Angol (US)"
|
"name": "Magyar (HU)"
|
||||||
},
|
},
|
||||||
"strings": {
|
"strings": {
|
||||||
"login": "Belépés",
|
"login": "Belépés",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"name": "Angol (US)"
|
"name": "Magyar (HU)"
|
||||||
},
|
},
|
||||||
"strings": {
|
"strings": {
|
||||||
"ifItWasNotYou": "",
|
"ifItWasNotYou": "",
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"name": "Angol (US)"
|
"name": "Magyar (HU)"
|
||||||
},
|
},
|
||||||
"strings": {
|
"strings": {
|
||||||
"pageTitle": "Jellyfin fiók létrehozása",
|
"pageTitle": "Jellyfin fiók létrehozása",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"name": "Angol (US)"
|
"name": "Magyar (HU)"
|
||||||
},
|
},
|
||||||
"strings": {
|
"strings": {
|
||||||
"passwordReset": "Jelszó visszaállítás",
|
"passwordReset": "Jelszó visszaállítás",
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"name": "Angol (US)"
|
"name": "Magyar (HU)"
|
||||||
},
|
},
|
||||||
"strings": {
|
"strings": {
|
||||||
"pageTitle": "Telepítés - jfa-go",
|
"pageTitle": "Telepítés - jfa-go",
|
||||||
|
@ -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."
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"name": "Angol (US)"
|
"name": "Magyar (HU)"
|
||||||
},
|
},
|
||||||
"strings": {
|
"strings": {
|
||||||
"startMessage": "Helló!\nAdd meg a Jellyfin PIN kódodat itt, hogy megerősítsd a fiókodat.",
|
"startMessage": "Helló!\nAdd meg a Jellyfin PIN kódodat itt, hogy megerősítsd a fiókodat.",
|
Loading…
Reference in New Issue
Block a user