Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/backend/chat/commands/command-runner.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { CommandDefinition, UserCommand } from "../../../types/commands";
import { FirebotChatMessage } from "../../../types/chat";
import { CommandDefinition, UserCommand } from "../../../types/commands";
import { Trigger } from "../../../types/triggers";
import { TriggerType } from "../../common/EffectType";

import logger from "../../logwrapper";
import frontendCommunicator from "../../common/frontend-communicator";
import accountAccess from "../../common/account-access";
import chatHelpers from "../chat-helpers";
import effectRunner from "../../common/effect-runner";
import frontendCommunicator from "../../common/frontend-communicator";
import logger from "../../logwrapper";
import twitchStreamInfoManager from "../../twitch-api/stream-info-manager";
import chatHelpers from "../chat-helpers";
import commandManager from "./command-manager";

interface TriggerWithArgs {
Expand Down Expand Up @@ -99,6 +100,10 @@ class CommandRunner {
}

private execute(command: CommandDefinition, userCommand: UserCommand, firebotChatMessage?: FirebotChatMessage, manual = false) {
if (command.onlyTriggerWhenChannelIsLive && !twitchStreamInfoManager.streamInfo.isLive && !manual) {
return;
}

let effects = command.effects;
if (command.subCommands && command.subCommands.length > 0 && userCommand.subcommandId != null) {
if (userCommand.subcommandId === "fallback-subcommand" && command.fallbackSubcommand) {
Expand Down
53 changes: 53 additions & 0 deletions src/backend/events/filters/builtin/twitch/channel-live.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ComparisonType } from "../../../../../shared/filter-constants";
import { EventFilter } from "../../../../../types/events";
import twitchStreamInfoManager from "../../../../twitch-api/stream-info-manager";

const filter: EventFilter = {
id: "firebot:channel-live",
name: "Channel is Live",
description: "Filter by whether or not channel is live",
events: [
{ eventSourceId: "firebot", eventId: "category-changed" },
{ eventSourceId: "twitch", eventId: "announcement" },
{ eventSourceId: "twitch", eventId: "bits-badge-unlocked" },
{ eventSourceId: "twitch", eventId: "category-changed" },
{ eventSourceId: "twitch", eventId: "channel-reward-redemption" },
{ eventSourceId: "twitch", eventId: "chat-message" },
{ eventSourceId: "twitch", eventId: "chat-mode-changed" },
{ eventSourceId: "twitch", eventId: "cheer" },
{ eventSourceId: "twitch", eventId: "community-subs-gifted" },
{ eventSourceId: "twitch", eventId: "first-time-chat" },
{ eventSourceId: "twitch", eventId: "gift-sub-upgraded" },
{ eventSourceId: "twitch", eventId: "hype-train-end" },
{ eventSourceId: "twitch", eventId: "hype-train-progress" },
{ eventSourceId: "twitch", eventId: "hype-train-start" },
{ eventSourceId: "twitch", eventId: "prime-sub-upgraded" },
{ eventSourceId: "twitch", eventId: "raid" },
{ eventSourceId: "twitch", eventId: "raid-sent-off" },
{ eventSourceId: "twitch", eventId: "sub" },
{ eventSourceId: "twitch", eventId: "subs-gifted" },
{ eventSourceId: "twitch", eventId: "viewer-arrived" }
],
comparisonTypes: [ComparisonType.IS],
valueType: "preset",
presetValues: async () => {
return [
{
value: "true",
display: "True"
},
{
value: "false",
display: "False"
}
];
},
predicate: async (filterSettings) => {
const { value } = filterSettings;
const { isLive } = twitchStreamInfoManager.streamInfo;

return isLive.toString() === value;
}
};

export default filter;
6 changes: 4 additions & 2 deletions src/backend/events/filters/builtin/twitch/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import bitsBadgeTier from "./bits-badge-tier";
import channelLive from "./channel-live";
import chatMode from "./chat-mode";
import chatModeDuration from "./chat-mode-duration";
import chatModeSetting from "./chat-mode-setting";
import chatMode from "./chat-mode";
import cheerBitsAmount from "./cheer-bits-amount";
import giftCount from "./gift-count";
import giftDuration from "./gift-duration";
Expand All @@ -10,8 +11,8 @@ import isAnonymous from "./is-anonymous";
import lifetimeGiftCount from "./lifetime-gift-count";
import message from "./message";
import raidViewerCount from "./raid-viewer-count";
import rewardName from "./reward-name";
import reward from "./reward";
import rewardName from "./reward-name";
import sharedChat from "./shared-chat";
import sharedTrain from "./shared-train";
import streamCategory from "./stream-category";
Expand All @@ -22,6 +23,7 @@ import username from "./username";

export default [
bitsBadgeTier,
channelLive,
chatModeDuration,
chatModeSetting,
chatMode,
Expand Down
2 changes: 2 additions & 0 deletions src/backend/variables/builtin/twitch/stream/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import category from './category';
import categoryImageUrl from './category-image-url';
import currentViewerCount from './current-viewer-count';
import isChannelLive from './is-channel-live';
import streamTitle from './stream-title';

export default [
category,
categoryImageUrl,
currentViewerCount,
isChannelLive,
streamTitle
];
48 changes: 48 additions & 0 deletions src/backend/variables/builtin/twitch/stream/is-channel-live.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { OutputDataType, VariableCategory } from "../../../../../shared/variable-constants";
import { ReplaceVariable } from "../../../../../types/variables";
import logger from "../../../../logwrapper";
import twitchStreamInfoManager from "../../../../twitch-api/stream-info-manager";

const TwitchApi = require("../../../../twitch-api/api");

const model : ReplaceVariable = {
definition: {
handle: "isChannelLive",
usage: "isChannelLive",
description: "Outputs `true` if the Twitch channel is currently live, `false` if not",
examples: [
{
usage: "isChannelLive[$target]",
description: "When in a command, gets whether the associated user's channel is live."
},
{
usage: "isChannelLive[$user]",
description: "Gets whether the associated user's channel is live (Ie who triggered command, pressed button, etc)."
},
{
usage: "isChannelLive[Oceanity]",
description: "Gets whether a specific channel is live."
}
],
categories: [VariableCategory.COMMON, VariableCategory.USER],
possibleDataOutput: [OutputDataType.TEXT]
},
evaluator: async (_trigger, username) => {
if (!username) {
return twitchStreamInfoManager.streamInfo.isLive;
}

let stream;

try {
stream = await TwitchApi.streamerClient.streams.getStreamByUserName(username);
} catch (error) {
logger.debug(`Unable to find channel with username "${username}"`, error);
return "[Channel not Found]";
}

return !!stream;
}
};

export default model;
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ <h3>Settings</h3>
/>
<div class="control__indicator"></div>
</label>
<label class="control-fb control--checkbox"
>Only trigger when channel is live
<tooltip
text="'When this option is enabled, users will only be able to trigger this command when the channel is live.'"
></tooltip>
<input
type="checkbox"
ng-model="$ctrl.command.onlyTriggerWhenChannelIsLive"
aria-label="..."
/>
<div class="control__indicator"></div>
</label>
</div>
<div class="controls-fb-inline mt-4">
<div class="settings-title">
Expand Down
1 change: 1 addition & 0 deletions src/types/commands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export type CommandDefinition = {
subCommands?: SubCommand[] | undefined;
fallbackSubcommand?: SubCommand | undefined;
treatQuotedTextAsSingleArg?: boolean | undefined;
onlyTriggerWhenChannelIsLive?: boolean | undefined;
minArgs?: number;
options?: Record<keyof OptionsModel, CommandOption>;
/**
Expand Down