[editor] Add notification in case bot is missing default-scopes

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-01-20 12:36:43 +01:00
parent 4477874330
commit 5b608b46e9
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 29 additions and 0 deletions

View file

@ -55,12 +55,14 @@ func registerEditorFrontend() {
router.HandleFunc("/editor/vars.json", func(w http.ResponseWriter, r *http.Request) { router.HandleFunc("/editor/vars.json", func(w http.ResponseWriter, r *http.Request) {
if err := json.NewEncoder(w).Encode(struct { if err := json.NewEncoder(w).Encode(struct {
DefaultBotScopes []string
IRCBadges []string IRCBadges []string
KnownEvents []*string KnownEvents []*string
TemplateFunctions []string TemplateFunctions []string
TwitchClientID string TwitchClientID string
Version string Version string
}{ }{
DefaultBotScopes: botDefaultScopes,
IRCBadges: twitch.KnownBadges, IRCBadges: twitch.KnownBadges,
KnownEvents: knownEvents, KnownEvents: knownEvents,
TemplateFunctions: tplFuncs.GetFuncNames(), TemplateFunctions: tplFuncs.GetFuncNames(),

View file

@ -268,6 +268,17 @@
<li>Open the copied URL, sign in with the bot account and accept the permissions</li> <li>Open the copied URL, sign in with the bot account and accept the permissions</li>
<li>The bot will display a message containing the authorized account. If this account is wrong, just start over, the token will be overwritten.</li> <li>The bot will display a message containing the authorized account. If this account is wrong, just start over, the token will be overwritten.</li>
</ul> </ul>
<p
v-if="botMissingScopes > 0"
class="text-warning"
>
<font-awesome-icon
fixed-width
class="mr-1"
:icon="['fas', 'exclamation-triangle']"
/>
Bot is missing {{ botMissingScopes }} of its default scopes, please re-authorize the bot.
</p>
<b-input-group> <b-input-group>
<b-form-input <b-form-input
placeholder="Loading..." placeholder="Loading..."
@ -421,6 +432,22 @@ export default {
return 'warning' return 'warning'
}, },
botMissingScopes() {
let missing = 0
if (!this.generalConfig || !this.generalConfig.channel_scopes || !this.generalConfig.bot_name || !this.generalConfig.channel_scopes[this.generalConfig.bot_name]) {
return -1
}
for (const scope of this.$root.vars.DefaultBotScopes) {
if (!this.generalConfig.channel_scopes[this.generalConfig.bot_name].includes(scope)) {
missing++
}
}
return missing
},
extendedPermissions() { extendedPermissions() {
return Object.keys(this.authURLs.available_extended_scopes || {}) return Object.keys(this.authURLs.available_extended_scopes || {})
.map(v => ({ text: this.authURLs.available_extended_scopes[v], value: v })) .map(v => ({ text: this.authURLs.available_extended_scopes[v], value: v }))