-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'ZusorCode/action-commercial' into master
# Conflicts: # website/src/views/Dashboard.vue
- Loading branch information
Showing
5 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { ApiClient } = require("@twurple/api"); | ||
const { StaticAuthProvider } = require("@twurple/auth"); | ||
module.exports = { | ||
key: "start-commercial", | ||
auth: ["client"], | ||
requiredParams: ["commercialDuration"], | ||
/*** | ||
* @param {ActionSuccessCallback} success | ||
* @param {ActionErrorCallback} error | ||
* @param {30 | 60 | 90 | 120 | 150 | 180} commercialDuration | ||
* @param {ClientData} client | ||
* @param {CacheGetFunction} get | ||
* @param {CacheAuthFunctions} auth | ||
* @param {SimpleUpdateRecord} updateRecord | ||
* @returns {Promise<void>} | ||
*/ | ||
// eslint-disable-next-line no-empty-pattern | ||
async handler(success, error, { commercialDuration }, { client, user }, { get, auth }) { | ||
if (!user.airtable?.website_settings?.includes("Full broadcast permissions")) return error("You don't have permission to start a commercial", 403); | ||
|
||
const broadcast = await get(client?.broadcast?.[0]); | ||
if (!broadcast) return error("No broadcast associated"); | ||
if (!broadcast.channel) return error("No channel associated with broadcast"); | ||
|
||
const channel = await auth.getChannel(broadcast?.channel?.[0]); | ||
if (!channel.twitch_refresh_token) return error("No twitch auth token associated with channel"); | ||
if (!channel.channel_id || !channel.name || !channel.twitch_scopes) return error("Invalid channel data"); | ||
let scopes = channel.twitch_scopes.split(" "); | ||
if (!["channel:edit:commercial"].every(scope => scopes.includes(scope))) return error("Token doesn't have the required scopes"); | ||
|
||
const accessToken = await auth.getTwitchAccessToken(channel); | ||
|
||
const authProvider = new StaticAuthProvider(process.env.TWITCH_CLIENT_ID, accessToken); | ||
const api = new ApiClient({authProvider}); | ||
|
||
try { | ||
await api.channels.startChannelCommercial(channel.channel_id, commercialDuration); | ||
} catch (e) { | ||
console.log(e); | ||
return error("Failed to start commercial"); | ||
} | ||
return success(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<div class="mt-2"> | ||
<b-button-group> | ||
<b-button class="label-button"><i class="fas fa-fw fa-dollar-sign"></i> Start Commercial</b-button> | ||
<b-button @click="commercial(30)">30s</b-button> | ||
<b-button @click="commercial(60)">1m</b-button> | ||
<b-button @click="commercial(90)">1m30</b-button> | ||
<b-button @click="commercial(120)">2m</b-button> | ||
<b-button @click="commercial(150)">2m30</b-button> | ||
<b-button @click="commercial(180)">3m</b-button> | ||
</b-button-group> | ||
|
||
</div> | ||
</template> | ||
|
||
<script> | ||
import { startCommercial } from "@/utils/dashboard"; | ||
import { BButton, BButtonGroup } from "bootstrap-vue"; | ||
export default { | ||
name: "Commercials", | ||
props: ["client"], | ||
components: { BButton, BButtonGroup }, | ||
methods: { | ||
async commercial(commercialDuration) { | ||
await startCommercial(this.$root.auth, "self", commercialDuration); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
.label-button { | ||
pointer-events: none; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters