Skip to content

Commit

Permalink
feat(channel): add channelDisplayName/channelUserName global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Oct 15, 2023
1 parent 3cc262e commit a2dcc87
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
8 changes: 8 additions & 0 deletions docs/_master/filters/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ bot it is twitch by default

- return uptime of the stream

`$channelDisplayName`

- return channel display name

`$channelUserName`

- return channel user name

## Count subs / follows/ bits / tips in date interval

- `(count|subs|<interval>)`
Expand Down
8 changes: 8 additions & 0 deletions docs/filters/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ bot it is twitch by default

- return uptime of the stream

`$channelDisplayName`

- return channel display name

`$channelUserName`

- return channel user names

## Count subs / follows/ bits / tips in date interval

- `(count|subs|<interval>)`
Expand Down
7 changes: 6 additions & 1 deletion src/helpers/api/stats.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Types } from '~/plugins/ListenTo';
import { persistent } from '../core/persistent';
import { eventEmitter } from '../events';

import { Types } from '~/plugins/ListenTo';

const old = new Map<string, any>();
const stats = persistent({
value: {
language: 'en',
channelDisplayName: '',
channelUserName: '',
currentWatchedTime: 0,
currentViewers: 0,
maxViewers: 0,
Expand All @@ -21,6 +24,8 @@ const stats = persistent({

} as {
language: string;
channelDisplayName: string;
channelUserName: string;
currentWatchedTime: number;
currentViewers: number;
maxViewers: number;
Expand Down
24 changes: 13 additions & 11 deletions src/helpers/checkFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,19 @@ class HelpersFilter {
const uptime = vars.get('services.twitch.uptime') as number;

const variables: Record<string, any> = {
$game: stats.value.currentGame,
$language: stats.value.language,
$viewers: isStreamOnline.value ? stats.value.currentViewers : 0,
$followers: stats.value.currentFollowers,
$subscribers: stats.value.currentSubscribers,
$bits: isStreamOnline.value ? stats.value.currentBits : 0,
$title: stats.value.currentTitle,
$source: opts.sender && typeof opts.discord !== 'undefined' ? 'discord' : 'twitch',
$isBotSubscriber: isBotSubscriber(),
$isStreamOnline: isStreamOnline.value,
$uptime: getTime(Date.now() - uptime, false),
$game: stats.value.currentGame,
$language: stats.value.language,
$viewers: isStreamOnline.value ? stats.value.currentViewers : 0,
$followers: stats.value.currentFollowers,
$subscribers: stats.value.currentSubscribers,
$bits: isStreamOnline.value ? stats.value.currentBits : 0,
$title: stats.value.currentTitle,
$source: opts.sender && typeof opts.discord !== 'undefined' ? 'discord' : 'twitch',
$isBotSubscriber: isBotSubscriber(),
$isStreamOnline: isStreamOnline.value,
$uptime: getTime(Date.now() - uptime, false),
$channelDisplayName: stats.value.channelDisplayName,
$channelUserName: stats.value.channelUserName,
};

if (message.includes('$thumbnail') && stats.value.currentGame) {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/Sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export const runScriptInSandbox = (plugin: Plugin,
game: stats.value.currentGame,
status: stats.value.currentTitle,
currentWatched: stats.value.currentWatchedTime,
channelDisplayName: stats.value.channelDisplayName,
channelUserName: stats.value.channelUserName,
};

eval(getTranspiledCode(___code___.id, ___code___.source));
Expand Down
2 changes: 2 additions & 0 deletions src/services/twitch/calls/getChannelInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export async function getChannelInformation (opts: any) {
apiStats.value.contentClasificationLabels = getChannelInfo[rawDataSymbol].content_classification_labels;
apiStats.value.currentGame = getChannelInfo.gameName;
apiStats.value.currentTitle = getChannelInfo.title;
apiStats.value.channelDisplayName = getChannelInfo.displayName;
apiStats.value.channelUserName = getChannelInfo.name;

gameCache.value = getChannelInfo.gameName;
rawStatus.value = _rawStatus;
Expand Down

0 comments on commit a2dcc87

Please sign in to comment.