diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 526705e9d..564fc1896 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -6,22 +6,38 @@ env: on: issue_comment: types: [created] + pull_request: jobs: deploy: runs-on: ubuntu-latest # todo skip already created deploys on that commit if: >- - github.event.issue.pull_request != '' && ( - contains(github.event.comment.body, '/deploy') + github.event.issue.pull_request != '' && + ( + contains(github.event.comment.body, '/deploy') + ) + ) || + ( + github.event_name == 'pull_request' && ( + env.AUTO_DEPLOY_PRS contains $'\n' + toString(github.event.pull_request.number) + $'\n' || + startsWith(env.AUTO_DEPLOY_PRS, toString(github.event.pull_request.number) + $'\n') || + endsWith(env.AUTO_DEPLOY_PRS, $'\n' + toString(github.event.pull_request.number)) || + env.AUTO_DEPLOY_PRS == toString(github.event.pull_request.number) + ) ) permissions: pull-requests: write steps: - - name: Checkout + - name: Checkout PR (comment) uses: actions/checkout@v2 + if: github.event_name == 'issue_comment' with: ref: refs/pull/${{ github.event.issue.number }}/head + - name: Checkout PR (pull_request) + uses: actions/checkout@v2 + if: github.event_name == 'pull_request' + - run: npm i -g pnpm@9.0.4 - uses: actions/setup-node@v4 with: @@ -59,7 +75,7 @@ jobs: id: alias env: ALIASES: ${{ env.ALIASES }} - PULL_URL: ${{ github.event.issue.pull_request.url }} + PULL_URL: ${{ github.event.issue.pull_request.url || github.event.pull_request.url }} - name: Set deployment alias if: ${{ steps.alias.outputs.alias != '' && steps.alias.outputs.alias != 'mcraft.fun' && steps.alias.outputs.alias != 's.mcraft.fun' }} run: vercel alias set ${{ steps.deploy.outputs.stdout }} ${{ steps.alias.outputs.alias }} --token=${{ secrets.VERCEL_TOKEN }} --scope=zaro diff --git a/src/builtinCommands.ts b/src/builtinCommands.ts index ede5480e8..51c98f2ad 100644 --- a/src/builtinCommands.ts +++ b/src/builtinCommands.ts @@ -81,7 +81,7 @@ const writeText = (text) => { const commands: Array<{ command: string[], - invoke (): Promise | void + invoke (args: string[]): Promise | void //@ts-format-ignore-region }> = [ { @@ -108,18 +108,33 @@ const commands: Array<{ await saveServer(false) writeText('Saved to browser memory') } + }, + { + command: ['/pos'], + async invoke ([type]) { + let pos: string | undefined + if (type === 'block') { + pos = window.cursorBlockRel()?.position?.toString().slice(1, -1) + } else { + pos = bot.entity.position.toString().slice(1, -1) + } + if (!pos) return + await navigator.clipboard.writeText(pos) + writeText(`Copied position to clipboard: ${pos}`) + } } ] //@ts-format-ignore-endregion export const getBuiltinCommandsList = () => commands.flatMap(command => command.command) -export const tryHandleBuiltinCommand = (message) => { +export const tryHandleBuiltinCommand = (message: string) => { if (!localServer) return + const [userCommand, ...args] = message.split(' ') for (const command of commands) { - if (command.command.includes(message)) { - void command.invoke() // ignoring for now + if (command.command.includes(userCommand)) { + void command.invoke(args) // ignoring for now return true } } diff --git a/src/globals.js b/src/globals.js index f9a1053c1..005d422f1 100644 --- a/src/globals.js +++ b/src/globals.js @@ -1,5 +1,6 @@ import EventEmitter from 'events' +window.reportError = window.reportError ?? console.error window.bot = undefined window.THREE = undefined window.localServer = undefined