Skip to content

Commit

Permalink
Merge pull request #533 from negue/merge/release-into-develop
Browse files Browse the repository at this point in the history
Merge release into develop
  • Loading branch information
negue authored Oct 27, 2022
2 parents 24c42a9 + 91f3a7b commit a1df1cb
Show file tree
Hide file tree
Showing 25 changed files with 473 additions and 153 deletions.
42 changes: 42 additions & 0 deletions API_ENDPOINTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
| Method | Endpoint | Class method |
|--------|------------------------------------------------|-----------------------------------------------------------|
| GET | /api/action/simpleList | ActionController.getList() |
| GET | /api/action/last_actions | ActionController.getLast20Events() |
| GET | /api/action/lastOverrides/:actionId | ActionController.getLastActionOverrides() |
| POST | /api/action/trigger/:actionId | ActionController.triggerAction() |
| GET | /api/actionActivity/current | ActionActivityController.getCurrentState() |
| GET | /api/config/ | ConfigController.getConfig() |
| PUT | /api/config/twitch | ConfigController.updateTwitchConfig() |
| PUT | /api/config/obs | ConfigController.updateObsConfig() |
| PUT | /api/config/ | ConfigController.updateConfig() |
| PUT | /api/config/customPort | ConfigController.updatePort() |
| DELETE | /api/config/twitchRevoke/:authType | ConfigController.revokeToken() |
| GET | /api/file/ | FileController.getList() |
| GET | /api/file/fileById/:mediaId | FileController.getById() |
| GET | /api/file/preview/:mediaId | FileController.getPreviewById() |
| GET | /api/screen/ | ScreenController.listAllScreens() |
| POST | /api/screen/ | ScreenController.addScreen() |
| PUT | /api/screen/:screenId | ScreenController.updateScreen() |
| DELETE | /api/screen/:screenId | ScreenController.deleteScreen() |
| PUT | /api/screen/:screenId/clips/bulk | ScreenController.updateScreenMediaBulk() |
| PUT | /api/screen/:screenId/clips/:mediaId | ScreenController.updateScreenMedia() |
| DELETE | /api/screen/:screenId/clips/:mediaId | ScreenController.deleteScreenMedia() |
| GET | /api/widget-state/:mediaId | WidgetStateController.getWidgetState() |
| PUT | /api/widget-state/:mediaId/:widgetInstance | WidgetStateController.updateScreen() |
| GET | /api/open/config | OpenController.openConfigPath() |
| GET | /api/open/files | OpenController.openFilePath() |
| GET | /api/twitchData/helix/* | TwitchDataController.getHelixData() |
| GET | /api/twitchData/authInformations | TwitchDataController.getTwitchAuthInformations() |
| GET | /api/twitchData/currentChannelPointRedemptions | TwitchDataController.listCurrentChannelPointRedemptions() |
| GET | /api/twitch_events/ | TwitchEventsController.getTwitchEvents() |
| POST | /api/twitch_events/ | TwitchEventsController.addTwitchEvent() |
| PUT | /api/twitch_events/:eventId | TwitchEventsController.updateTwitchEvent() |
| DELETE | /api/twitch_events/:eventId | TwitchEventsController.deleteTwitchEvent() |
| POST | /api/twitch_events/trigger_config_example | TwitchEventsController.triggerConfigExample() |
| POST | /api/twitch_events/trigger_event | TwitchEventsController.triggerEvent() |
| GET | /api/twitch_events/last_events | TwitchEventsController.getLast20Events() |
| GET | /api/obsData/currentBrowserSources | ObsDataController.listBrowserSources() |
| POST | /api/obsData/refreshBrowserSource/:sourceName | ObsDataController.refreshBrowserSource() |
| GET | /api/obsData/sceneList | ObsDataController.getSceneList() |
| GET | /api/obsData/sourceList | ObsDataController.getSourceList() |
| GET | /api/obsData/sourceFilters/:sourceName | ObsDataController.getSourceFilterList() |
File renamed without changes.
2 changes: 1 addition & 1 deletion projects/contracts/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ChatUserstate} from "tmi.js";
import {ActionType} from "./media.types";
import {ActionType} from "./action.types";
import {ActionOverridableProperties, TriggerAction} from "./actions";
import {AllTwitchEvents} from "./twitch.connector.types";
import {DefaultImage} from "./twitch-data.types";
Expand Down
2 changes: 1 addition & 1 deletion projects/contracts/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

export * from './lib/types';
export * from './lib/types.outdated';
export * from './lib/media.types';
export * from './lib/action.types';
export * from './lib/createInitialState';
export * from './lib/constants';
export * from './lib/actions';
Expand Down
3 changes: 3 additions & 0 deletions projects/recipe-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from './lib/recipe.types';
export * from './lib/utils';
export * from './lib/generateCodeByRecipe';
export {RecipeCommandBlockGroups} from "./lib/recipeCommandBlockGroups";
export {RecipeCommandRegistry} from "./lib/recipeCommandRegistry";
export * from "./lib/recipeStepConfigArgument";
111 changes: 111 additions & 0 deletions projects/recipe-core/src/lib/command-blocks.generic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {generateCodeByStep, RecipeCommandBlockRegistry} from "./recipe.types";
import {generateRandomCharacters} from "./utils";

export function registerGenericCommandBlocks(
registry: RecipeCommandBlockRegistry,
generateCodeByStep: generateCodeByStep
): void {
registry["sleepSeconds"] = {
pickerLabel: "Wait for Seconds",
commandGroup: "generic",
configArguments: [
{
name: "seconds",
label: "Seconds",
type: "number"
}
],
toScriptCode: (step, context) => `sleep.secondsAsync(${step.payload.seconds});`,
commandEntryLabelAsync: (queries, payload, parentStep) => {
return Promise.resolve(`sleep: ${payload.seconds} seconds`);
},
entryIcon: () => 'hourglass_top'
};


registry["sleepMs"] = {
pickerLabel: "Wait for Milliseconds",
commandGroup: "generic",
configArguments: [
{
name: "ms",
label: "Milliseconds",
type: "number"
}
],
toScriptCode: (step, context) => `sleep.msAsync(${step.payload.ms});`,
commandEntryLabelAsync: (queries, payload, parentStep) => {
return Promise.resolve(`sleep: ${payload.ms}ms`);
},
entryIcon: () => 'hourglass_top'
};

registry["randomCommandGroup"] = {
pickerLabel: "Random Command Group",
commandGroup: "generic",
configArguments: [
{
name: 'amountOfGroups',
label: 'Amount of Groups',
type: "number"
}
],
extendCommandBlockOnEdit: true,
extendCommandBlock: (step) => {
const amountOfGroups = step.payload.amountOfGroups as number;

if (step.subCommandBlocks.length === amountOfGroups) {
return;
}

if (amountOfGroups < step.subCommandBlocks.length) {
step.subCommandBlocks.length = amountOfGroups;
return;
}


const newSubCommandBlockArray = [...step.subCommandBlocks];

for (let i = step.subCommandBlocks.length; i < amountOfGroups; i++) {
newSubCommandBlockArray.push({
labelId: generateRandomCharacters(5),
entries: []
});
}

step.subCommandBlocks = newSubCommandBlockArray
},
subCommandBlockLabelAsync: (queries, commandBlock, labelId) => {
return Promise.resolve('');
},
awaitCodeHandledInternally: true,
toScriptCode: (step, context, userData) => {
const awaitCode = step.awaited ? 'await ' : '';

const functionNames: string[] = [];

const generatedFunctions = generateCodeByStep(step, context, userData).map(g => {

const functionName = `randomGroup_${g.subCommand.labelId}`;

functionNames.push(functionName);

return `async function ${functionName}() {
${g.generatedScript}
}`;
}).join('\r\n');

return `
${awaitCode} (() => {
${generatedFunctions}
const functionsToChoose = [${functionNames.join(',')}];
return utils.randomElement(functionsToChoose)();
})();`;
},
commandEntryLabelAsync: (queries, payload, parentStep) => {
return 'trigger any of these command groups randomly';
}
};
}
86 changes: 58 additions & 28 deletions projects/recipe-core/src/lib/command-blocks.memebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import {map, take} from "rxjs/operators";
import {generateRandomCharacters, listActionsOfActionListPayload} from "./utils";
import {ACTION_TYPE_INFORMATION} from "@memebox/contracts";
import {AppQueries} from "@memebox/app-state";

function createMemeboxApiVariable(
actionPayload: RecipeCommandConfigActionPayload
Expand All @@ -27,18 +28,43 @@ function createMemeboxApiVariable(
return actionApiVariable;
}

export function registerMemeboxCommandBlocks (
async function getActionLabel(
queries: AppQueries,
actionPayload: RecipeCommandConfigActionPayload,
prefix = ''
): Promise<string> {
const actionName = await queries.getActionById$(actionPayload.actionId).pipe(
map(actionInfo => actionInfo?.name ?? 'unknown action'),
take(1)
).toPromise();

const screenIdExist = !!actionPayload.screenId;

const screenName = screenIdExist
? await queries.screenMap$.pipe(
map(screenMap => screenMap[actionPayload.screenId!].name),
take(1)
).toPromise()
: 'All Screens';

return `${prefix} [${actionName}] on [${screenName}]`.trim();
}

export function registerMemeboxCommandBlocks(
registry: RecipeCommandBlockRegistry,
generateCodeByStep: generateCodeByStep
): void {
): void {
registry["triggerAction"] = {
pickerLabel: "Trigger Action",
commandGroup: "memebox",
configArguments: [
{
name: "action",
label: "Action to trigger",
type: "action"
type: "action",
flags: {
allowAllScreens: true
}
}
],
toScriptCode: (step) => {
Expand All @@ -52,10 +78,7 @@ export function registerMemeboxCommandBlocks (
commandEntryLabelAsync: (queries, payload) => {
const actionPayload = payload.action as RecipeCommandConfigActionPayload;

return queries.getActionById$(actionPayload.actionId).pipe(
map(actionInfo => actionInfo?.name ?? 'unknown action'),
take(1)
).toPromise();
return getActionLabel(queries, actionPayload);
},
entryIcon: (queries, payload) => {
const actionPayload = payload.action as RecipeCommandConfigActionPayload;
Expand All @@ -64,7 +87,7 @@ export function registerMemeboxCommandBlocks (
map(action => ACTION_TYPE_INFORMATION[action.type].icon),
take(1)
).toPromise();
},
}
};

const keepTriggeredActionActiveWhileLabel = 'Keep Triggered Action active, while';
Expand All @@ -76,29 +99,31 @@ export function registerMemeboxCommandBlocks (
{
name: "action",
label: "Action to trigger, keep active",
type: "action"
type: "action",
flags: {
allowAllScreens: false
}
}
],
subCommandBlockLabelAsync: (queries, commandBlock, labelId) => {
subCommandBlockLabelAsync: async (queries, commandBlock, labelId) => {
const actionPayload = commandBlock.entryType === "command"
&& commandBlock.payload.action as RecipeCommandConfigActionPayload;

if (!actionPayload) {
return Promise.resolve('Unknown Action');
}

return queries.getActionById$(actionPayload.actionId).pipe(
map(action => `Keep Triggered Action ${action.name} active, while these commands are running: `),
take(1)
).toPromise();
const actionLabel = await getActionLabel(queries, actionPayload, 'Keep Triggered Action');

return actionLabel+' active, while these commands are running:';
},
extendCommandBlock: (step) => {
step.payload = {
...step.payload,
_suffix: generateRandomCharacters(5)
};

step.subCommandBlocks.push( {
step.subCommandBlocks.push({
labelId: "keepVisibleWhile",
entries: []
});
Expand All @@ -110,15 +135,20 @@ export function registerMemeboxCommandBlocks (

return `${createMemeboxApiVariable(actionPayload)}
.triggerWhile(async (helpers_${step.payload._suffix}) => {
${generateCodeByStep(step, context, userData)}
${generateCodeByStep(step, context, userData)[0].generatedScript}
}
${actionOverrides ? ',' + JSON.stringify(actionOverrides) : ''});`;
},
commandEntryLabelAsync: (queries, payload) => {
const actionPayload = payload.action as RecipeCommandConfigActionPayload;

return getActionLabel(queries, actionPayload);
},
entryIcon: (queries, payload) => {
const actionPayload = payload.action as RecipeCommandConfigActionPayload;

return queries.getActionById$(actionPayload.actionId).pipe(
map(actionInfo => actionInfo?.name ?? 'unknown action'),
map(action => ACTION_TYPE_INFORMATION[action.type].icon),
take(1)
).toPromise();
}
Expand All @@ -142,7 +172,7 @@ export function registerMemeboxCommandBlocks (
},
commandEntryLabelAsync: () => {
return Promise.resolve('reset');
},
}
};

registry["triggerRandom"] = {
Expand All @@ -157,7 +187,7 @@ export function registerMemeboxCommandBlocks (
],
awaitCodeHandledInternally: true,
toScriptCode: (step, context, userData) => {
const awaitCode = step.awaited ? 'await ': '';
const awaitCode = step.awaited ? 'await ' : '';

const actionsToChooseFrom = listActionsOfActionListPayload(
step.payload.actions as RecipeCommandConfigActionListPayload,
Expand All @@ -184,11 +214,11 @@ export function registerMemeboxCommandBlocks (
const tagName = tags.find(t => t.id === actionListPayload.actionsByTag)?.name
?? `\r\nUnknown Tag: ${actionListPayload.actionsByTag}`;

return `trigger any action with the tag: ${tagName}`;
return `trigger any action with the tag: [${tagName}]`;
}

return `trigger any of the following: ${actionListPayload.selectedActions.length}`;
},
}
};


Expand All @@ -199,8 +229,11 @@ export function registerMemeboxCommandBlocks (
{
name: "action",
label: "Action to update properties",
type: "action"
},
type: "action",
flags: {
allowAllScreens: true
}
}
/* {
name: "overrides",
label: "Properties to update",
Expand All @@ -212,7 +245,7 @@ export function registerMemeboxCommandBlocks (
const actionPayload = step.payload.action as RecipeCommandConfigActionPayload;
const overrides = actionPayload.overrides;

const awaitCode = step.awaited ? 'await ': '';
const awaitCode = step.awaited ? 'await ' : '';

const updateVariables = overrides.action?.variables
? `promisesArray.push(action.updateVariables(${JSON.stringify(overrides.action)}));`
Expand All @@ -239,10 +272,7 @@ ${awaitCode} (() => {
commandEntryLabelAsync: (queries, payload) => {
const actionPayload = payload.action as RecipeCommandConfigActionPayload;

return queries.getActionById$(actionPayload.actionId).pipe(
map(actionInfo => 'Update Properties of: ' + actionInfo?.name ?? 'unknown action'),
take(1)
).toPromise();
return getActionLabel(queries, actionPayload, 'Update Properties of:');
}
};
}
Loading

1 comment on commit a1df1cb

@vercel
Copy link

@vercel vercel bot commented on a1df1cb Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

meme-box – ./

meme-box.vercel.app
meme-box-negu3.vercel.app
meme-box-git-develop-negu3.vercel.app

Please sign in to comment.