Skip to content

Commit

Permalink
Merge pull request #205 from LordTocs/dev
Browse files Browse the repository at this point in the history
0.5 Hotfix
  • Loading branch information
LordTocs authored Jul 14, 2024
2 parents d645518 + ff6f630 commit 19b2b2c
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 34 deletions.
2 changes: 1 addition & 1 deletion libs/castmate-core/src/accounts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import util, { InspectOptions } from "util"

import { AccountConfig, AccountSecrets, AccountState } from "castmate-schema"

interface AccountConstructor extends ResourceConstructor {
export interface AccountConstructor extends ResourceConstructor {
new (...args: any[]): any
accountDirectory: string
storage: ResourceStorage<Account>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "castmate-monorepo",
"version": "0.5.0",
"version": "0.5.1",
"description": "",
"private": true,
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/castmate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "castmate",
"version": "0.5.0",
"version": "0.5.1",
"description": "CastMate",
"author": "LordTocs",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion plugins/obs/main/src/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function setupAudio(obsDefault: ReactiveRef<OBSConnection>) {
},
muted: {
type: Toggle,
name: "muted",
name: "Muted",
required: true,
default: true,
template: true,
Expand Down Expand Up @@ -74,6 +74,7 @@ export function setupAudio(obsDefault: ReactiveRef<OBSConnection>) {
defineAction({
id: "changeVolume",
name: "Change Volume",
icon: "mdi mdi-volume-high",
config: {
type: Object,
properties: {
Expand Down
19 changes: 19 additions & 0 deletions plugins/obs/main/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ export class OBSConnection extends FileResource<OBSConnectionConfig, OBSConnecti

ResourceRegistry.getInstance().exposeIPCFunction<OBSConnection>(OBSConnection, "getPreview")
ResourceRegistry.getInstance().exposeIPCFunction<OBSConnection>(OBSConnection, "openProcess")
ResourceRegistry.getInstance().exposeIPCFunction<OBSConnection>(OBSConnection, "refreshAllBrowsers")
ResourceRegistry.getInstance().exposeIPCFunction<OBSConnection>(OBSConnection, "findBrowserByUrlPattern")
ResourceRegistry.getInstance().exposeIPCFunction<OBSConnection>(OBSConnection, "getRemoteHost")
ResourceRegistry.getInstance().exposeIPCFunction<OBSConnection>(OBSConnection, "createNewSource")
Expand Down Expand Up @@ -427,6 +428,24 @@ export class OBSConnection extends FileResource<OBSConnectionConfig, OBSConnecti
return input
}

async refreshAllBrowsers() {
if (!this.state.connected) return

const { inputs } = await this.connection.call("GetInputList", {
inputKind: "browser_source",
})

await Promise.allSettled(
inputs.map(async (i) => {
logger.log("Refreshing", i.inputName)
await this.connection.call("PressInputPropertiesButton", {
inputName: i.inputName as string,
propertyName: "refreshnocache",
})
})
)
}

async refreshBrowsersByUrlPattern(urlPattern: string) {
if (!this.state.connected) return undefined

Expand Down
2 changes: 2 additions & 0 deletions plugins/obs/main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { setupToggles } from "./toggles"
import { setupTransforms } from "./transform"

import { attemptQRReading, setupAutoConnect } from "./auto-connect"
import { setupAudio } from "./audio"

export default definePlugin(
{
Expand Down Expand Up @@ -125,6 +126,7 @@ export default definePlugin(
setupScenes(obsDefault)
setupSources(obsDefault)
setupMedia(obsDefault)
setupAudio(obsDefault)
setupToggles(obsDefault)
setupTransforms(obsDefault)

Expand Down
15 changes: 14 additions & 1 deletion plugins/obs/renderer/src/components/DashboardObsCard.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<template>
<dashboard-card v-if="obs">
<template #header> <i class="obsi obsi-obs" /> {{ obs?.config?.name }} </template>
<template #header>
<div class="flex flex-row">
<i class="obsi obsi-obs" /> {{ obs?.config?.name }}
<div class="flex-grow-1" />
<p-button
icon="mdi mdi-refresh"
size="small"
class="extra-small-button"
v-tooltip="'Refresh All Browsers'"
@click="refreshAllBrowsers"
/>
</div>
</template>
<dashboard-card-item v-if="!obs.state.connected" label="Disconnected">
<p-button v-if="isLocal" text @click="openObs">Open</p-button>
<div
Expand Down Expand Up @@ -48,6 +60,7 @@ const isLocal = computed(() => {
})
const openProcess = useResourceIPCCaller<() => any>("OBSConnection", () => props.obsId, "openProcess")
const refreshAllBrowsers = useResourceIPCCaller<() => any>("OBSConnection", () => props.obsId, "refreshAllBrowsers")
async function openObs() {
if (!props.obsId) return
Expand Down
47 changes: 38 additions & 9 deletions plugins/overlays/renderer/src/components/OverlayAddToObsButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
<div class="display-box" v-else>
<i class="mdi mdi-web-box"></i>
{{ sourceName }}
<p-button v-if="hasError" icon="mdi mdi-wrench" v-tooltip="'Fix Issues'" @click="fixErrorsClick"></p-button>
<p-button
v-if="hasError"
class="extra-small-button ml-1"
size="small"
icon="mdi mdi-wrench"
v-tooltip="'Fix Issues'"
@click="fixErrorsClick"
></p-button>
</div>
</template>

Expand All @@ -28,10 +35,11 @@ import { OverlayConfig } from "castmate-plugin-overlays-shared"
import { computed, onMounted, ref, watch } from "vue"
import PButton from "primevue/button"
import { useResource, useResourceIPCCaller, useSettingValue } from "castmate-ui-core"
import { NameDialog, useResource, useResourceIPCCaller, useSettingValue } from "castmate-ui-core"
import { ResourceData } from "castmate-schema"
import { OBSConnectionConfig, OBSConnectionState } from "castmate-plugin-obs-shared"
import { asyncComputed } from "@vueuse/core"
import { useDialog } from "primevue/usedialog"
const obs = useResource<ResourceData<OBSConnectionConfig, OBSConnectionState>>("OBSConnection", () => props.obsId)
Expand Down Expand Up @@ -130,22 +138,43 @@ async function getBrowserSourceSettings() {
}
}
const dialog = useDialog()
async function createSourceClick(ev: MouseEvent) {
if (!obs.value) return
const newSourceName = await createNewSource(
"browser_source",
"CastMate Overlay!",
obs.value.state.scene,
await getBrowserSourceSettings()
)
sourceName.value = newSourceName
dialog.open(NameDialog, {
props: {
header: "Create Browser Source",
style: {
width: "25vw",
},
modal: true,
},
async onClose(options) {
if (!options?.data) {
return
}
if (!obs.value) return
await createNewSource(
"browser_source",
options.data,
obs.value.state.scene,
await getBrowserSourceSettings()
)
setTimeout(findBrowserSource, 200)
},
})
}
async function fixErrorsClick(ev: MouseEvent) {
if (!sourceName.value) return
await updateSourceSettings(sourceName.value, await getBrowserSourceSettings())
await findBrowserSource()
}
async function openObs() {
Expand Down
43 changes: 26 additions & 17 deletions plugins/twitch/main/src/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
defineAction,
definePluginResource,
onLoad,
usePluginLogger,
} from "castmate-core"
import {
TwitchViewerGroupConfig,
Expand All @@ -17,6 +18,8 @@ import { nanoid } from "nanoid/non-secure"
import { ViewerCache } from "./viewer-cache"
import { TwitchAccount } from "./twitch-auth"

const logger = usePluginLogger("twitch")

interface SerializedConfig {
name: string
userIds: string[]
Expand Down Expand Up @@ -158,24 +161,29 @@ async function satisfiesRule(userId: string, rule: TwitchViewerGroupRule): Promi
}
}
return false
} else if ("property" in rule) {
} else if ("properties" in rule) {
//Todo: Make this not silly hardcoded
if (rule.property === "following") {
return await ViewerCache.getInstance().getIsFollowing(userId)
} else if (rule.property === "subscribed") {
return await ViewerCache.getInstance().getIsSubbed(userId)
} else if (rule.property === "sub-tier-1") {
return (await ViewerCache.getInstance().getSubInfo(userId))?.tier == 1
} else if (rule.property === "sub-tier-2") {
return (await ViewerCache.getInstance().getSubInfo(userId))?.tier == 2
} else if (rule.property === "sub-tier-3") {
return (await ViewerCache.getInstance().getSubInfo(userId))?.tier == 3
} else if (rule.property === "mod") {
return await ViewerCache.getInstance().getIsMod(userId)
} else if (rule.property === "vip") {
return await ViewerCache.getInstance().getIsVIP(userId)
} else if (rule.property === "broadcaster") {
return userId === TwitchAccount.channel.twitchId
if (rule.properties.following) {
if (await ViewerCache.getInstance().getIsFollowing(userId)) return true
}

if (rule.properties.subTier1) {
if ((await ViewerCache.getInstance().getSubInfo(userId))?.tier == 1) return true
}
if (rule.properties.subTier2) {
if ((await ViewerCache.getInstance().getSubInfo(userId))?.tier == 2) return true
}
if (rule.properties.subTier3) {
if ((await ViewerCache.getInstance().getSubInfo(userId))?.tier == 3) return true
}
if (rule.properties.mod) {
if (await ViewerCache.getInstance().getIsMod(userId)) return true
}
if (rule.properties.vip) {
if (await ViewerCache.getInstance().getIsVIP(userId)) return true
}
if (rule.properties.broadcaster) {
if (userId === TwitchAccount.channel.twitchId) return true
}
return false
} else if ("group" in rule) {
Expand All @@ -186,6 +194,7 @@ async function satisfiesRule(userId: string, rule: TwitchViewerGroupRule): Promi
} else if ("userIds" in rule) {
return rule.userIds.includes(userId)
}
logger.log("Unknown Group Rule", rule)
return false
}

Expand Down
14 changes: 13 additions & 1 deletion plugins/twitch/main/src/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { ApiClient } from "@twurple/api"
import { EventSubWsListener } from "@twurple/eventsub-ws"
import { TwitchAccount } from "./twitch-auth"
import { defineState, defineTrigger } from "castmate-core"
import { defineState, defineTrigger, usePluginLogger } from "castmate-core"
import { Range } from "castmate-schema"
import { TwitchAPIService, onChannelAuth } from "./api-harness"
import { ViewerCache } from "./viewer-cache"
import { TwitchViewer, TwitchViewerGroup } from "castmate-plugin-twitch-shared"
import { inTwitchViewerGroup } from "./group"

export function setupSubscriptions() {
const logger = usePluginLogger()

const subscription = defineTrigger({
id: "subscription",
name: "Subscriber",
Expand Down Expand Up @@ -123,6 +125,16 @@ export function setupSubscriptions() {
})

service.eventsub.onChannelSubscriptionMessage(channel.twitchId, async (event) => {
logger.log(
"Sub Message Received: ",
event.userDisplayName,
event.userId,
event.tier,
event.cumulativeMonths,
event.durationMonths,
event.streakMonths
)

let tier = 1
if (event.tier == "2000") {
tier = 2
Expand Down
15 changes: 13 additions & 2 deletions plugins/twitch/main/src/twitch-auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TwitchAccountConfig, TwitchAccountSecrets } from "castmate-plugin-twitch-shared"
import { Account, ResourceStorage, usePluginLogger } from "castmate-core"
import { Account, AccountConstructor, ResourceStorage, loadYAML, usePluginLogger } from "castmate-core"
import { getTokenInfo, AuthProvider, AccessTokenWithUserId, AccessTokenMaybeWithUserId } from "@twurple/auth"
import { BrowserWindow } from "electron"
import { ApiClient, UserIdResolvable } from "@twurple/api"
Expand Down Expand Up @@ -37,6 +37,7 @@ const defaultScopes = [

"moderation:read",
"channel:manage:moderators",
"moderator:manage:banned_users",

"channel:read:ads", //Get ad schedule
"channel:manage:ads", //Snooze ad
Expand Down Expand Up @@ -299,7 +300,7 @@ export class TwitchAccount extends Account<TwitchAccountSecrets, TwitchAccountCo

private forceLogin(scopes: string[]) {
return new Promise<string>((resolve, reject) => {
const authUrl = this.getAuthURL(scopes, false)
const authUrl = this.getAuthURL(scopes, true)

const window = new BrowserWindow({
width: 600,
Expand Down Expand Up @@ -389,6 +390,16 @@ export class TwitchAccount extends Account<TwitchAccountSecrets, TwitchAccountCo
return false
}

protected async loadConfig() {
const accountDir = (this.constructor as AccountConstructor).accountDirectory
try {
const loadedConfig = await loadYAML("accounts", accountDir, `${this.id}.yaml`)
delete loadedConfig.scopes

await super.applyConfig(loadedConfig)
} catch (err) {}
}

static async initialize(): Promise<void> {
await super.initialize()

Expand Down

0 comments on commit 19b2b2c

Please sign in to comment.