From 15e5564b1293c02f43d5739e888f84dff2afad67 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Wed, 26 Jan 2022 20:00:40 +0000 Subject: [PATCH] discord: add/move to slash commands the version of the discord library with support for this isn't necessarily stable, so normal ! commands will still be available. The user is no longer DMed for the PIN, instead they type /pin . --- config.go | 3 + config/config-base.json | 2 +- discord.go | 239 +++++++++++++++++++++++++++++++++++++-- go.mod | 9 +- go.sum | 25 +--- lang/form/en-us.json | 2 +- lang/telegram/en-us.json | 3 + views.go | 2 +- 8 files changed, 244 insertions(+), 41 deletions(-) diff --git a/config.go b/config.go index 1051f93..3a0748c 100644 --- a/config.go +++ b/config.go @@ -76,6 +76,9 @@ func (app *appContext) loadConfig() error { app.MustSetValue("smtp", "hello_hostname", "localhost") app.MustSetValue("smtp", "cert_validation", "true") + sc := app.config.Section("discord").Key("start_command").MustString("start") + app.config.Section("discord").Key("start_command").SetValue(strings.TrimPrefix(strings.TrimPrefix(sc, "/"), "!")) + jfUrl := app.config.Section("jellyfin").Key("server").String() if !(strings.HasPrefix(jfUrl, "http://") || strings.HasPrefix(jfUrl, "https://")) { app.config.Section("jellyfin").Key("server").SetValue("http://" + jfUrl) diff --git a/config/config-base.json b/config/config-base.json index 39267d3..1a39edb 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -656,7 +656,7 @@ "requires_restart": true, "depends_true": "enabled", "type": "text", - "value": "!start", + "value": "start", "description": "Command to start the user verification process." }, "channel": { diff --git a/discord.go b/discord.go index 2b96a39..150d4e2 100644 --- a/discord.go +++ b/discord.go @@ -20,6 +20,8 @@ type DiscordDaemon struct { users map[string]DiscordUser // Map of user IDs to users. Added to on first interaction, and loaded from app.storage.discord on start. roleID string app *appContext + commandHandlers map[string]func(s *dg.Session, i *dg.InteractionCreate, lang string) + commandIDs []string } func newDiscordDaemon(app *appContext) (*DiscordDaemon, error) { @@ -40,7 +42,12 @@ func newDiscordDaemon(app *appContext) (*DiscordDaemon, error) { users: map[string]DiscordUser{}, app: app, roleID: app.config.Section("discord").Key("apply_role").String(), + commandHandlers: map[string]func(s *dg.Session, i *dg.InteractionCreate, lang string){}, + commandIDs: []string{}, } + dd.commandHandlers[app.config.Section("discord").Key("start_command").MustString("start")] = dd.cmdStart + dd.commandHandlers["lang"] = dd.cmdLang + dd.commandHandlers["pin"] = dd.cmdPIN for _, user := range app.storage.discord { dd.users[user.ID] = user } @@ -74,6 +81,9 @@ func (d *DiscordDaemon) MustGetUser(channelID, userID, discrim, username string) func (d *DiscordDaemon) run() { d.bot.AddHandler(d.messageHandler) + + d.bot.AddHandler(d.commandHandler) + d.bot.Identify.Intents = dg.IntentsGuildMessages | dg.IntentsDirectMessages | dg.IntentsGuildMembers | dg.IntentsGuildInvites if err := d.bot.Open(); err != nil { d.app.err.Printf("Discord: Failed to start daemon: %v", err) @@ -107,7 +117,11 @@ func (d *DiscordDaemon) run() { d.inviteChannelName = invChannel } } + defer d.deregisterCommands() defer d.bot.Close() + + d.registerCommands() + <-d.ShutdownChannel d.ShutdownChannel <- "Down" return @@ -254,6 +268,206 @@ func (d *DiscordDaemon) Shutdown() { close(d.ShutdownChannel) } +func (d *DiscordDaemon) registerCommands() { + commands := []*dg.ApplicationCommand{ + { + Name: d.app.config.Section("discord").Key("start_command").MustString("start"), + Description: "Start the Discord linking process. The bot will send further instructions.", + }, + { + Name: "lang", + Description: "Set the language for the bot.", + Options: []*dg.ApplicationCommandOption{ + { + Type: dg.ApplicationCommandOptionString, + Name: "language", + Description: "Language Name", + Required: true, + Choices: []*dg.ApplicationCommandOptionChoice{}, + }, + }, + }, + { + Name: "pin", + Description: "Send PIN for Discord verification.", + Options: []*dg.ApplicationCommandOption{ + { + Type: dg.ApplicationCommandOptionString, + Name: "pin", + Description: "Verification PIN (e.g AB-CD-EF)", + Required: true, + }, + }, + }, + } + commands[1].Options[0].Choices = make([]*dg.ApplicationCommandOptionChoice, len(d.app.storage.lang.Telegram)) + i := 0 + for code := range d.app.storage.lang.Telegram { + commands[1].Options[0].Choices[i] = &dg.ApplicationCommandOptionChoice{ + Name: d.app.storage.lang.Telegram[code].Meta.Name, + Value: code, + } + i++ + } + + d.deregisterCommands() + + d.commandIDs = make([]string, len(commands)) + cCommands, err := d.bot.ApplicationCommandBulkOverwrite(d.bot.State.User.ID, d.guildID, commands) + if err != nil { + d.app.err.Printf("Discord: Cannot create commands: %v", err) + } + for i, cmd := range cCommands { + // command, err := d.bot.ApplicationCommandCreate(d.bot.State.User.ID, d.guildID, cmd) + // if err != nil { + // d.app.err.Printf("Discord: Cannot create command \"%s\": %v", cmd.Name, err) + // } + d.commandIDs[i] = cmd.ID + } +} + +func (d *DiscordDaemon) deregisterCommands() { + existingCommands, err := d.bot.ApplicationCommands(d.bot.State.User.ID, d.guildID) + if err != nil { + d.app.err.Printf("Discord: Failed to get commands: %v", err) + return + } + for _, cmd := range existingCommands { + if err := d.bot.ApplicationCommandDelete(d.bot.State.User.ID, "", cmd.ID); err != nil { + d.app.err.Printf("Failed to deregister command: %v", err) + } + } +} + +func (d *DiscordDaemon) commandHandler(s *dg.Session, i *dg.InteractionCreate) { + if h, ok := d.commandHandlers[i.ApplicationCommandData().Name]; ok { + if i.GuildID != "" && d.channelName != "" { + if d.channelID == "" { + channel, err := s.Channel(i.ChannelID) + if err != nil { + d.app.err.Printf("Discord: Couldn't get channel, will monitor all: %v", err) + d.channelName = "" + } + if channel.Name == d.channelName { + d.channelID = channel.ID + } + } + if d.channelID != i.ChannelID { + d.app.debug.Printf("Discord: Ignoring message as not in specified channel") + return + } + } + if i.Interaction.Member.User.ID == s.State.User.ID { + return + } + lang := d.app.storage.lang.chosenTelegramLang + if user, ok := d.users[i.Interaction.Member.User.ID]; ok { + if _, ok := d.app.storage.lang.Telegram[user.Lang]; ok { + lang = user.Lang + } + } + h(s, i, lang) + } +} + +// cmd* methods handle slash-commands, msg* methods handle ! commands. + +func (d *DiscordDaemon) cmdStart(s *dg.Session, i *dg.InteractionCreate, lang string) { + channel, err := s.UserChannelCreate(i.Interaction.Member.User.ID) + if err != nil { + d.app.err.Printf("Discord: Failed to create private channel with \"%s\": %v", i.Interaction.Member.User.Username, err) + return + } + user := 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] = user + + content := d.app.storage.lang.Telegram[lang].Strings.get("discordStartMessage") + "\n" + content += d.app.storage.lang.Telegram[lang].Strings.template("languageMessageDiscord", tmpl{"command": "/lang"}) + err = s.InteractionRespond(i.Interaction, &dg.InteractionResponse{ + // Type: dg.InteractionResponseChannelMessageWithSource, + Type: dg.InteractionResponseChannelMessageWithSource, + Data: &dg.InteractionResponseData{ + Content: content, + Flags: 64, // Ephemeral + }, + }) + if err != nil { + d.app.err.Printf("Discord: Failed to send reply: %v", err) + return + } +} + +func (d *DiscordDaemon) cmdPIN(s *dg.Session, i *dg.InteractionCreate, lang string) { + pin := i.ApplicationCommandData().Options[0].StringValue() + tokenIndex := -1 + for i, token := range d.tokens { + if pin == token { + tokenIndex = i + break + } + } + if tokenIndex == -1 { + err := s.InteractionRespond(i.Interaction, &dg.InteractionResponse{ + // Type: dg.InteractionResponseChannelMessageWithSource, + Type: dg.InteractionResponseChannelMessageWithSource, + Data: &dg.InteractionResponseData{ + Content: d.app.storage.lang.Telegram[lang].Strings.get("invalidPIN"), + Flags: 64, // Ephemeral + }, + }) + if err != nil { + d.app.err.Printf("Discord: Failed to send message to \"%s\": %v", i.Interaction.Member.User.Username, err) + } + return + } + err := s.InteractionRespond(i.Interaction, &dg.InteractionResponse{ + // Type: dg.InteractionResponseChannelMessageWithSource, + Type: dg.InteractionResponseChannelMessageWithSource, + Data: &dg.InteractionResponseData{ + Content: d.app.storage.lang.Telegram[lang].Strings.get("pinSuccess"), + Flags: 64, // Ephemeral + }, + }) + if err != nil { + d.app.err.Printf("Discord: Failed to send message to \"%s\": %v", i.Interaction.Member.User.Username, err) + } + d.verifiedTokens[pin] = d.users[i.Interaction.Member.User.ID] + d.tokens[len(d.tokens)-1], d.tokens[tokenIndex] = d.tokens[tokenIndex], d.tokens[len(d.tokens)-1] + d.tokens = d.tokens[:len(d.tokens)-1] +} + +func (d *DiscordDaemon) cmdLang(s *dg.Session, i *dg.InteractionCreate, lang string) { + code := i.ApplicationCommandData().Options[0].StringValue() + if _, ok := d.app.storage.lang.Telegram[code]; ok { + var user DiscordUser + for jfID, u := range d.app.storage.discord { + if u.ID == i.Interaction.Member.User.ID { + u.Lang = code + lang = code + d.app.storage.discord[jfID] = u + if err := d.app.storage.storeDiscordUsers(); err != nil { + d.app.err.Printf("Failed to store Discord users: %v", err) + } + user = u + break + } + } + d.users[i.Interaction.Member.User.ID] = user + err := s.InteractionRespond(i.Interaction, &dg.InteractionResponse{ + // Type: dg.InteractionResponseChannelMessageWithSource, + Type: dg.InteractionResponseChannelMessageWithSource, + Data: &dg.InteractionResponseData{ + Content: d.app.storage.lang.Telegram[lang].Strings.template("languageSet", tmpl{"language": d.app.storage.lang.Telegram[lang].Meta.Name}), + Flags: 64, // Ephemeral + }, + }) + if err != nil { + d.app.err.Printf("Discord: Failed to send reply: %v", err) + return + } + } +} + func (d *DiscordDaemon) messageHandler(s *dg.Session, m *dg.MessageCreate) { if m.GuildID != "" && d.channelName != "" { if d.channelID == "" { @@ -285,16 +499,16 @@ func (d *DiscordDaemon) messageHandler(s *dg.Session, m *dg.MessageCreate) { } } switch msg := sects[0]; msg { - case d.app.config.Section("discord").Key("start_command").MustString("!start"): - d.commandStart(s, m, lang) + case "!" + d.app.config.Section("discord").Key("start_command").MustString("start"): + d.msgStart(s, m, lang) case "!lang": - d.commandLang(s, m, sects, lang) + d.msgLang(s, m, sects, lang) default: - d.commandPIN(s, m, sects, lang) + d.msgPIN(s, m, sects, lang) } } -func (d *DiscordDaemon) commandStart(s *dg.Session, m *dg.MessageCreate, lang string) { +func (d *DiscordDaemon) msgStart(s *dg.Session, m *dg.MessageCreate, lang string) { channel, err := s.UserChannelCreate(m.Author.ID) if err != nil { d.app.err.Printf("Discord: Failed to create private channel with \"%s\": %v", m.Author.Username, err) @@ -303,7 +517,7 @@ func (d *DiscordDaemon) commandStart(s *dg.Session, m *dg.MessageCreate, lang st user := d.MustGetUser(channel.ID, m.Author.ID, m.Author.Discriminator, m.Author.Username) d.users[m.Author.ID] = user - _, err = d.bot.ChannelMessageSendReply(m.ChannelID, d.app.storage.lang.Telegram[lang].Strings.get("discordDMs"), m.MessageReference) + _, err = d.bot.ChannelMessageSendReply(m.ChannelID, d.app.storage.lang.Telegram[lang].Strings.get("discordDMs"), m.Reference()) if err != nil { d.app.err.Printf("Discord: Failed to send reply to \"%s\": %v", m.Author.Username, err) return @@ -318,7 +532,7 @@ func (d *DiscordDaemon) commandStart(s *dg.Session, m *dg.MessageCreate, lang st } } -func (d *DiscordDaemon) commandLang(s *dg.Session, m *dg.MessageCreate, sects []string, lang string) { +func (d *DiscordDaemon) msgLang(s *dg.Session, m *dg.MessageCreate, sects []string, lang string) { if len(sects) == 1 { list := "!lang \n" for code := range d.app.storage.lang.Telegram { @@ -336,13 +550,14 @@ func (d *DiscordDaemon) commandLang(s *dg.Session, m *dg.MessageCreate, sects [] } if _, ok := d.app.storage.lang.Telegram[sects[1]]; ok { var user DiscordUser - for jfID, user := range d.app.storage.discord { - if user.ID == m.Author.ID { - user.Lang = sects[1] - d.app.storage.discord[jfID] = user + for jfID, u := range d.app.storage.discord { + if u.ID == m.Author.ID { + u.Lang = sects[1] + d.app.storage.discord[jfID] = u if err := d.app.storage.storeDiscordUsers(); err != nil { d.app.err.Printf("Failed to store Discord users: %v", err) } + user = u break } } @@ -350,7 +565,7 @@ func (d *DiscordDaemon) commandLang(s *dg.Session, m *dg.MessageCreate, sects [] } } -func (d *DiscordDaemon) commandPIN(s *dg.Session, m *dg.MessageCreate, sects []string, lang string) { +func (d *DiscordDaemon) msgPIN(s *dg.Session, m *dg.MessageCreate, sects []string, lang string) { if _, ok := d.users[m.Author.ID]; ok { channel, err := s.Channel(m.ChannelID) if err != nil { diff --git a/go.mod b/go.mod index 5345329..c204fce 100644 --- a/go.mod +++ b/go.mod @@ -13,10 +13,8 @@ replace github.com/hrfee/jfa-go/logger => ./logger replace github.com/hrfee/jfa-go/linecache => ./linecache require ( - github.com/bwmarrin/discordgo v0.23.2 - github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/bwmarrin/discordgo v0.23.3-0.20211228023845-29269347e820 github.com/emersion/go-autostart v0.0.0-20210130080809-00ed301c8e9a - github.com/evanw/esbuild v0.14.14 // indirect github.com/fatih/color v1.13.0 github.com/fsnotify/fsnotify v1.5.1 github.com/getlantern/golog v0.0.0-20210606115803-bce9f9fe5a5f // indirect @@ -26,7 +24,6 @@ require ( github.com/gin-contrib/pprof v1.3.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.7.7 - github.com/go-openapi/spec v0.20.4 // indirect github.com/go-playground/validator/v10 v10.9.0 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible @@ -49,7 +46,7 @@ require ( github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/pkg/errors v0.9.1 // indirect github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 - github.com/steambap/captcha v1.4.1 // indirect + github.com/steambap/captcha v1.4.1 github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 github.com/swaggo/gin-swagger v1.3.3 github.com/swaggo/swag v1.7.8 // indirect @@ -58,7 +55,7 @@ require ( github.com/ugorji/go v1.2.6 // indirect github.com/writeas/go-strip-markdown v2.0.1+incompatible github.com/xhit/go-simple-mail/v2 v2.10.0 - golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect + golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce // indirect golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba // indirect golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect golang.org/x/tools v0.1.8 // indirect diff --git a/go.sum b/go.sum index da95915..ab081a2 100644 --- a/go.sum +++ b/go.sum @@ -20,12 +20,10 @@ github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVa github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= -github.com/bwmarrin/discordgo v0.23.2 h1:BzrtTktixGHIu9Tt7dEE6diysEF9HWnXeHuoJEt2fH4= -github.com/bwmarrin/discordgo v0.23.2/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M= +github.com/bwmarrin/discordgo v0.23.3-0.20211228023845-29269347e820 h1:MIW5DnBVJAgAy4LYBqWwIMBB0ezklvh8b7DsYvHZHb0= +github.com/bwmarrin/discordgo v0.23.3-0.20211228023845-29269347e820/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= -github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -33,8 +31,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emersion/go-autostart v0.0.0-20210130080809-00ed301c8e9a h1:M88ob4TyDnEqNuL3PgsE/p3bDujfspnulR+0dQWNYZs= github.com/emersion/go-autostart v0.0.0-20210130080809-00ed301c8e9a/go.mod h1:buzQsO8HHkZX2Q45fdfGH1xejPjuDQaXH8btcYMFzPM= -github.com/evanw/esbuild v0.14.14 h1:swuD1WwW1+EJTArWUCort1WRVA4bUXqFIa1PxY7v2Ds= -github.com/evanw/esbuild v0.14.14/go.mod h1:GG+zjdi59yh3ehDn4ZWfPcATxjPDUH53iU4ZJbp7dkY= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= @@ -147,12 +143,9 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/hrfee/mediabrowser v0.3.7 h1:F57Cmwst4fOfhPuOlanKiOuek9zCVcXm78/zP/1WB2s= -github.com/hrfee/mediabrowser v0.3.7/go.mod h1:PnHZbdxmbv1wCVdAQyM7nwPwpVj9fdKx2EcET7sAk+U= github.com/hrfee/mediabrowser v0.3.8 h1:y0iBCb6jE3QKcsiCJSYva2fFPHRn4UA+sGRzoPuJ/Dk= github.com/hrfee/mediabrowser v0.3.8/go.mod h1:PnHZbdxmbv1wCVdAQyM7nwPwpVj9fdKx2EcET7sAk+U= github.com/itchyny/timefmt-go v0.1.3 h1:7M3LGVDsqcd0VZH2U+x393obrzZisp7C0uEe921iRkU= @@ -262,8 +255,6 @@ github.com/swaggo/gin-swagger v1.3.3/go.mod h1:ymsZuGpbbu+S7ZoQ49QPpZoDBj6uqhb8W github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y= github.com/swaggo/swag v1.6.7/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc= github.com/swaggo/swag v1.7.4/go.mod h1:zD8h6h4SPv7t3l+4BKdRquqW1ASWjKZgT6Qv9z3kNqI= -github.com/swaggo/swag v1.7.6 h1:UbAqHyXkW2J+cDjs5S43MkuYR7a6stB7Am7SK8NBmRg= -github.com/swaggo/swag v1.7.6/go.mod h1:7vLqNYEtYoIsD14wXgy9oDS65MNiDANrPtbk9rnLuj0= github.com/swaggo/swag v1.7.8 h1:w249t0l/kc/DKMGlS0fppNJQxKyJ8heNaUWB6nsH3zc= github.com/swaggo/swag v1.7.8/go.mod h1:gZ+TJ2w/Ve1RwQsA2IRoSOTidHz6DX+PIG8GWvbnoLU= github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= @@ -301,16 +292,16 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce h1:Roh6XWxHFKrPgC/EQhVubSAGQ6Ozk6IdxHSzt1mR0EI= +golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -335,10 +326,6 @@ golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM= -golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d h1:62NvYBuaanGXR2ZOfwDFkhhl6X1DUgf8qg3GuQvxZsE= -golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba h1:6u6sik+bn/y7vILcYkK3iwTBWN7WtBvB0+SZswQnbf8= golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -366,10 +353,8 @@ golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/lang/form/en-us.json b/lang/form/en-us.json index 6c89726..e6bfa91 100644 --- a/lang/form/en-us.json +++ b/lang/form/en-us.json @@ -18,7 +18,7 @@ "confirmationRequiredMessage": "Please check your email inbox to verify your address.", "yourAccountIsValidUntil": "Your account will be valid until {date}.", "sendPIN": "Send the PIN below to the bot, then come back here to link your account.", - "sendPINDiscord": "Type {command} in {server_channel} on Discord, then send the PIN below via DM to the bot.", + "sendPINDiscord": "Type {command} in {server_channel} on Discord, then send the PIN below.", "matrixEnterUser": "Enter your User ID, press submit, and a PIN will be sent to you. Enter it here to continue." }, "notifications": { diff --git a/lang/telegram/en-us.json b/lang/telegram/en-us.json index 8312241..fd35ae3 100644 --- a/lang/telegram/en-us.json +++ b/lang/telegram/en-us.json @@ -4,10 +4,13 @@ }, "strings": { "startMessage": "Hi!\nEnter your Jellyfin PIN code here to verify your account.", + "discordStartMessage": "Hi!\n Enter your PIN with `/pin ` to verify your account.", "matrixStartMessage": "Hi\nEnter the below PIN in the Jellyfin sign-up page to verify your account.", "invalidPIN": "That PIN was invalid, try again.", "pinSuccess": "Success! You can now return to the sign-up page.", "languageMessage": "Note: See available languages with {command}, and set language with {command} .", + "languageMessageDiscord": "Note: set your language with /lang .", + "languageSet": "Language set to {language}.", "discordDMs": "Please check your DMs for a response." } } diff --git a/views.go b/views.go index c9709a3..3df9277 100644 --- a/views.go +++ b/views.go @@ -504,7 +504,7 @@ func (app *appContext) InviteProxy(gc *gin.Context) { data["discordUsername"] = app.discord.username data["discordRequired"] = app.config.Section("discord").Key("required").MustBool(false) data["discordSendPINMessage"] = template.HTML(app.storage.lang.Form[lang].Strings.template("sendPINDiscord", tmpl{ - "command": `` + app.config.Section("discord").Key("start_command").MustString("!start") + ``, + "command": `/` + app.config.Section("discord").Key("start_command").MustString("start") + ``, "server_channel": app.discord.serverChannelName, })) data["discordServerName"] = app.discord.serverName