Skip to content

Commit

Permalink
feat: extender
Browse files Browse the repository at this point in the history
  • Loading branch information
imconnorngl committed Nov 30, 2024
1 parent 4ed76b5 commit 863e984
Show file tree
Hide file tree
Showing 20 changed files with 1,121 additions and 765 deletions.
103 changes: 53 additions & 50 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,63 @@ on: [push]
concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
quality:
name: Quality
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
quality:
name: Quality
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
scope: '@LunarClient'
always-auth: true
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
scope: "@LunarClient"
always-auth: true

- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: 8
run_install: true
- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: 8
run_install: true

- name: Build Packages
run: pnpm build
- name: Build Packages
run: pnpm build

- name: Check Types
run: pnpm types
release:
name: Release
runs-on: ubuntu-latest
needs: quality
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Check Types
run: pnpm types

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
scope: '@LunarClient'
always-auth: true
- name: Check Formatting
run: pnpm format:check
release:
name: Release
runs-on: ubuntu-latest
needs: quality
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: 8
run_install: true
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
scope: "@LunarClient"
always-auth: true

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN }}
- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: 8
run_install: true

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
"main": "dist/index.js",
"scripts": {
"build": "tsup src/index.ts --format esm --target es2022 --dts --clean",
"format:check": "prettier --check \"**/*.{ts,tsx}\" --cache",
"format:write": "prettier --write \"**/*.{ts,tsx}\" --cache",
"types": "tsc --noEmit",
"changeset": "changeset",
"version-packages": "changeset version",
"release": "pnpm build && changeset publish",
"prepack": "clean-package",
"postpack": "clean-package restore"
"changeset": "changeset",
"version-packages": "changeset version",
"release": "pnpm build && changeset publish",
"prepack": "clean-package",
"postpack": "clean-package restore"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
Expand All @@ -31,6 +33,7 @@
"discord-api-types": "^0.37.93",
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"clean-package": "^2.2.0"
"clean-package": "^2.2.0",
"prettier": "^3.1.0"
}
}
37 changes: 22 additions & 15 deletions src/builder/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import type { APICommandAutocompleteInteractionResponseCallbackData } from 'discord-api-types/v10'
import { Builder } from './utils'
import type { APICommandAutocompleteInteractionResponseCallbackData } from "discord-api-types/v10";
import { Builder } from "./utils";

export class Autocomplete extends Builder<APICommandAutocompleteInteractionResponseCallbackData> {
#search: string
#search: string;
constructor(search?: string | number) {
super({})
this.#search = search?.toString() || ''
}
choices = (...e: Required<APICommandAutocompleteInteractionResponseCallbackData>['choices']) => {
const choices = e.filter(e2 => {
if (e2.name.includes(this.#search)) return true
if (Object.values(e2.name_localizations || {}).some(e3 => e3?.includes(this.#search))) return true
if (e2.value.toString().includes(this.#search)) return true
return false
})
if (choices.length > 25) choices.length = 25
return this.a({ choices })
super({});
this.#search = search?.toString() || "";
}
choices = (
...e: Required<APICommandAutocompleteInteractionResponseCallbackData>["choices"]
) => {
const choices = e.filter((e2) => {
if (e2.name.includes(this.#search)) return true;
if (
Object.values(e2.name_localizations || {}).some((e3) =>
e3?.includes(this.#search)
)
)
return true;
if (e2.value.toString().includes(this.#search)) return true;
return false;
});
if (choices.length > 25) choices.length = 25;
return this.a({ choices });
};
}
Loading

0 comments on commit 863e984

Please sign in to comment.