mirror of
https://github.com/hrfee/jfa-go.git
synced 2026-01-18 16:47:42 +01:00
telegram: add "always use default lang", /lang default
For #451. Setting in integrations > chat bots > telegram makes jfa-go ignore the telegram users clients lanugage setting and always use whatever is set as the default language in jfa-go. Also added /lang default, to un-set a preferred language. the start message also now shows up on typing /help or !help too.
This commit is contained in:
@@ -1056,6 +1056,12 @@ sections:
|
|||||||
value: en-us
|
value: en-us
|
||||||
description: Default telegram message language. Visit weblate if you'd like to
|
description: Default telegram message language. Visit weblate if you'd like to
|
||||||
translate.
|
translate.
|
||||||
|
- setting: ignore_client_language
|
||||||
|
name: Always use default language
|
||||||
|
depends_true: enabled
|
||||||
|
type: bool
|
||||||
|
value: false
|
||||||
|
description: When disabled, jfa-go will check the telegram user's language and use it if possible. Enable to ignore it and use your configured default language always.
|
||||||
- section: matrix
|
- section: matrix
|
||||||
meta:
|
meta:
|
||||||
name: Matrix
|
name: Matrix
|
||||||
|
|||||||
@@ -945,9 +945,9 @@
|
|||||||
<button class="button ~neutral @low center inside-input rounded-s-none settings-search-clear" aria-label="{{ .strings.clearSearch }}" text="{{ .strings.clearSearch }}"><i class="ri-close-line"></i></button>
|
<button class="button ~neutral @low center inside-input rounded-s-none settings-search-clear" aria-label="{{ .strings.clearSearch }}" text="{{ .strings.clearSearch }}"><i class="ri-close-line"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<div id="settings-loader" class="flex flex-row flex-wrap gap-2">
|
<div id="settings-loader" class="flex flex-row flex-wrap gap-2">
|
||||||
<span class="button ~neutral @low justify-center grow flex flex-row gap-2" id="setting-about"><span class="flex">{{ .strings.aboutProgram }} <i class="ri-information-line"></i></span></span>
|
<span class="button ~neutral @low justify-center grow flex flex-row gap-2" id="setting-about"><span class="flex flex-row gap-2">{{ .strings.aboutProgram }} <i class="ri-information-line"></i></span></span>
|
||||||
<a class="button ~urge dark:~d_info @low justify-center grow flex flex-row gap-2" target="_blank" href="https://wiki.jfa-go.com"><span class="flex">{{ .strings.wiki }} <i class="ri-book-shelf-line"></i></a>
|
<a class="button ~urge dark:~d_info @low justify-center grow flex flex-row gap-2" target="_blank" href="https://wiki.jfa-go.com"><span class="flex flex-row gap-2">{{ .strings.wiki }} <i class="ri-book-shelf-line"></i></a>
|
||||||
<span class="button ~neutral @low justify-center grow flex flex-row gap-2" id="setting-profiles"><span class="flex">{{ .strings.userProfiles }} <i class="ri-user-line"></i></span></span>
|
<span class="button ~neutral @low justify-center grow flex flex-row gap-2" id="setting-profiles"><span class="flex flex-row gap-2">{{ .strings.userProfiles }} <i class="ri-user-line"></i></span></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex md:flex flex-col gap-2 overflow-y-scroll" id="settings-sidebar-items"></div>
|
<div class="flex md:flex flex-col gap-2 overflow-y-scroll" id="settings-sidebar-items"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
64
telegram.go
64
telegram.go
@@ -59,15 +59,16 @@ type VerifToken struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TelegramDaemon struct {
|
type TelegramDaemon struct {
|
||||||
Stopped bool
|
Stopped bool
|
||||||
ShutdownChannel chan string
|
ShutdownChannel chan string
|
||||||
bot *tg.BotAPI
|
bot *tg.BotAPI
|
||||||
username string
|
username string
|
||||||
tokens map[string]VerifToken // Map of pins to tokens.
|
tokens map[string]VerifToken // Map of pins to tokens.
|
||||||
verifiedTokens map[string]TelegramVerifiedToken // Map of token pins to the responsible ChatID+Username.
|
verifiedTokens map[string]TelegramVerifiedToken // Map of token pins to the responsible ChatID+Username.
|
||||||
languages map[int64]string // Store of languages for chatIDs. Added to on first interaction, and loaded from app.storage.telegram on start.
|
languages map[int64]string // Store of languages for chatIDs. Added to on first interaction, and loaded from app.storage.telegram on start.
|
||||||
link string
|
ignoreClientLanguage bool // Whether to ignore the sender's client language and just use the preconfigured default language or not.
|
||||||
app *appContext
|
link string
|
||||||
|
app *appContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTelegramDaemon(app *appContext) (*TelegramDaemon, error) {
|
func newTelegramDaemon(app *appContext) (*TelegramDaemon, error) {
|
||||||
@@ -80,14 +81,15 @@ func newTelegramDaemon(app *appContext) (*TelegramDaemon, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
td := &TelegramDaemon{
|
td := &TelegramDaemon{
|
||||||
ShutdownChannel: make(chan string),
|
ShutdownChannel: make(chan string),
|
||||||
bot: bot,
|
bot: bot,
|
||||||
username: bot.Self.UserName,
|
username: bot.Self.UserName,
|
||||||
tokens: map[string]VerifToken{},
|
tokens: map[string]VerifToken{},
|
||||||
verifiedTokens: map[string]TelegramVerifiedToken{},
|
verifiedTokens: map[string]TelegramVerifiedToken{},
|
||||||
languages: map[int64]string{},
|
languages: map[int64]string{},
|
||||||
link: "https://t.me/" + bot.Self.UserName,
|
ignoreClientLanguage: app.config.Section("telegram").Key("ignore_client_language").MustBool(false),
|
||||||
app: app,
|
link: "https://t.me/" + bot.Self.UserName,
|
||||||
|
app: app,
|
||||||
}
|
}
|
||||||
for _, user := range app.storage.GetTelegram() {
|
for _, user := range app.storage.GetTelegram() {
|
||||||
if user.Lang != "" {
|
if user.Lang != "" {
|
||||||
@@ -156,12 +158,14 @@ func (t *TelegramDaemon) run() {
|
|||||||
lang := t.app.storage.lang.chosenTelegramLang
|
lang := t.app.storage.lang.chosenTelegramLang
|
||||||
storedLang, ok := t.languages[upd.Message.Chat.ID]
|
storedLang, ok := t.languages[upd.Message.Chat.ID]
|
||||||
if !ok {
|
if !ok {
|
||||||
found := false
|
found := t.ignoreClientLanguage
|
||||||
for code := range t.app.storage.lang.Telegram {
|
if !found {
|
||||||
if code[:2] == upd.Message.From.LanguageCode {
|
for code := range t.app.storage.lang.Telegram {
|
||||||
lang = code
|
if code[:2] == upd.Message.From.LanguageCode {
|
||||||
found = true
|
lang = code
|
||||||
break
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if found {
|
if found {
|
||||||
@@ -172,6 +176,8 @@ func (t *TelegramDaemon) run() {
|
|||||||
}
|
}
|
||||||
switch msg := sects[0]; msg {
|
switch msg := sects[0]; msg {
|
||||||
case "/start":
|
case "/start":
|
||||||
|
case "/help":
|
||||||
|
case "!help":
|
||||||
t.commandStart(&upd, sects, lang)
|
t.commandStart(&upd, sects, lang)
|
||||||
continue
|
continue
|
||||||
case "/lang":
|
case "/lang":
|
||||||
@@ -243,6 +249,7 @@ func (t *TelegramDaemon) commandStart(upd *tg.Update, sects []string, lang strin
|
|||||||
func (t *TelegramDaemon) commandLang(upd *tg.Update, sects []string, lang string) {
|
func (t *TelegramDaemon) commandLang(upd *tg.Update, sects []string, lang string) {
|
||||||
if len(sects) == 1 {
|
if len(sects) == 1 {
|
||||||
list := "/lang `<lang>`\n"
|
list := "/lang `<lang>`\n"
|
||||||
|
list += "`default`: " + t.app.storage.lang.Telegram[t.app.storage.lang.chosenTelegramLang].Meta.Name + "\n"
|
||||||
for code := range t.app.storage.lang.Telegram {
|
for code := range t.app.storage.lang.Telegram {
|
||||||
list += fmt.Sprintf("`%s`: %s\n", code, t.app.storage.lang.Telegram[code].Meta.Name)
|
list += fmt.Sprintf("`%s`: %s\n", code, t.app.storage.lang.Telegram[code].Meta.Name)
|
||||||
}
|
}
|
||||||
@@ -252,6 +259,17 @@ func (t *TelegramDaemon) commandLang(upd *tg.Update, sects []string, lang string
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if sects[1] == "default" {
|
||||||
|
delete(t.languages, upd.Message.Chat.ID)
|
||||||
|
for _, user := range t.app.storage.GetTelegram() {
|
||||||
|
if user.ChatID == upd.Message.Chat.ID {
|
||||||
|
user.Lang = ""
|
||||||
|
t.app.storage.SetTelegramKey(user.JellyfinID, user)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
if _, ok := t.app.storage.lang.Telegram[sects[1]]; ok {
|
if _, ok := t.app.storage.lang.Telegram[sects[1]]; ok {
|
||||||
t.languages[upd.Message.Chat.ID] = sects[1]
|
t.languages[upd.Message.Chat.ID] = sects[1]
|
||||||
for _, user := range t.app.storage.GetTelegram() {
|
for _, user := range t.app.storage.GetTelegram() {
|
||||||
|
|||||||
Reference in New Issue
Block a user