Skip to content

Commit

Permalink
Hook botauth against events
Browse files Browse the repository at this point in the history
in order to update frontend info when backend changes

Signed-off-by: Knut Ahlers <knut@ahlers.me>
  • Loading branch information
Luzifer committed Jul 13, 2024
1 parent 35eb383 commit c5a0e1e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = {
'keyword-spacing': ['error'],
'linebreak-style': ['error', 'unix'],
'lines-between-class-members': ['error'],
'multiline-comment-style': ['warn'],
'multiline-comment-style': ['off'],
'newline-per-chained-call': ['error'],
'no-alert': ['error'],
'no-console': ['off'],
Expand Down
28 changes: 27 additions & 1 deletion src/components/botauth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<script lang="ts">
import BusEventTypes from '../helpers/busevents'
import { defineComponent } from 'vue'
export default defineComponent({
Expand All @@ -72,6 +73,10 @@ export default defineComponent({
},
methods: {
/**
* Copies auth-url for the bot into clipboard and gives user feedback
* by colorizing copy-button for a short moment
*/
copyAuthURL(): void {
navigator.clipboard.writeText(this.authURLs.update_bot_token)
.then(() => {
Expand All @@ -81,32 +86,53 @@ export default defineComponent({
})
},
/**
* Fetches auth-URLs from the backend
*/
fetchAuthURLs(): Promise<void> | undefined {
return this.$root?.fetchJSON('config-editor/auth-urls')
.then((data: any) => {
this.authURLs = data
})
},
/**
* Fetches the bot profile (including display-name and profile
* image) and stores it locally
*
* @param user Login-name of the user to fetch the profile for
*/
fetchBotProfile(user: string): Promise<void> | undefined {
return this.$root?.fetchJSON(`config-editor/user?user=${user}`)
.then((data: any) => {
this.botProfile = data
})
},
/**
* Fetches the general config object from the backend including the
* authorized bot-name
*/
fetchGeneralConfig(): Promise<void> | undefined {
return this.$root?.fetchJSON('config-editor/general')
.then((data: any) => {
this.generalConfig = data
})
.then(() => this.fetchBotProfile(this.generalConfig.bot_name))
},
},
mounted() {
// Reload config after it changed
this.bus.on(BusEventTypes.ConfigReload, () => this.fetchGeneralConfig())
// Socket-reconnect could mean we need new auth-urls as the state
// may have changed due to bot-restart
this.bus.on(BusEventTypes.NotifySocketConnected, () => this.fetchAuthURLs())
// Do initial fetches
this.fetchAuthURLs()
this.fetchGeneralConfig()
?.then(() => this.fetchBotProfile(this.generalConfig.bot_name))
},
name: 'TwitchBotEditorBotAuth',
Expand Down

0 comments on commit c5a0e1e

Please sign in to comment.