From f7e27fae5a0629679415f0e8c84e3fdfde452411 Mon Sep 17 00:00:00 2001 From: Parbez Date: Fri, 6 May 2022 13:45:47 +0530 Subject: [PATCH] feat!: move all discord.js related parsers into a new package (#22) * feat!: add a new package * fix: remove delete test * fix: remove other formats * fix: remove all invalid exports * fix: separate files * fix: remove stop parser * fix: remove stop parser * test: add some missing tests * fix: tests * fix: tests * test: add more tests * fix(test): update precision * fix(test): add more tests * perf(date): don't set payload everytime * chore: cleaup * chore: fix docs links and readme * chore: add to dev deps --- .all-contributorsrc | 2 +- .eslintrc.json | 1 - .github/workflows/auto-deprecate.yml | 2 +- .github/workflows/continuous-delivery.yml | 2 +- .github/workflows/deprecate-on-merge.yml | 2 +- .npm-deprecaterc.yml | 1 + .vscode/settings.json | 2 +- README.md | 7 - package.json | 3 + .../.cliff-jumperrc.yml | 2 + packages/tagscript-plugin-discord/LICENSE | 21 ++ packages/tagscript-plugin-discord/README.md | 74 +++++ packages/tagscript-plugin-discord/cliff.toml | 60 ++++ .../tagscript-plugin-discord/jest.config.mjs | 14 + .../tagscript-plugin-discord/package.json | 65 +++++ .../tagscript-plugin-discord/src/index.ts | 1 + .../src/lib/Parsers/AllowDeny.ts | 5 +- .../src/lib/Parsers/Cooldown.ts | 4 +- .../src/lib/Parsers/Delete.ts | 4 +- .../src/lib/Parsers/Embed.ts | 6 +- .../src/lib/Parsers/Format.ts | 23 ++ .../src/lib/Parsers/Silent.ts | 4 +- .../src/lib/Parsers/index.ts | 6 + .../src/lib/Transformer/Base.ts | 39 +++ .../src/lib/Transformer/Guild.ts | 68 +++++ .../src/lib/Transformer/GuildMember.ts | 56 ++++ .../lib/Transformer/GuildTextBasedChannel.ts | 38 +++ .../src/lib/Transformer/Role.ts | 33 +++ .../src/lib/Transformer/User.ts | 32 +++ .../src/lib/Transformer/index.ts | 7 + .../tagscript-plugin-discord/src/lib/index.ts | 2 + .../src/tsconfig.json | 11 + .../tests/Parsers/AllowDeny.test.ts | 3 +- .../tests/Parsers/Cooldown.test.ts | 3 +- .../tests/Parsers/Delete.test.ts | 3 +- .../tests/Parsers/Embed.test.ts | 3 +- .../tests/Parsers/Format.test.ts | 24 ++ .../tests/Parsers/Silent.test.ts | 3 +- .../tests/Transformer/Guild.test.ts | 10 + .../tests/Transformer/GuildMember.test.ts | 12 + .../Transformer/GuildTextBasedChannel.test.ts | 11 + .../tests/Transformer/Role.test.ts | 11 + .../tests/Transformer/Structures.ts | 96 +++++++ .../tests/Transformer/User.test.ts | 16 ++ .../tests/tsconfig.json | 4 + .../tagscript-plugin-discord/tsup.config.ts | 3 + packages/tagscript/README.md | 17 +- packages/tagscript/package.json | 12 +- packages/tagscript/src/lib/Parsers/Format.ts | 26 +- packages/tagscript/src/lib/Parsers/index.ts | 5 - .../src/lib/Transformer/DiscordJs.ts | 259 ------------------ .../tagscript/src/lib/Transformer/index.ts | 1 - .../tagscript/tests/Parsers/Format.test.ts | 3 + packages/tagscript/tests/Utils/Util.test.ts | 39 ++- scripts/clean-full.mjs | 4 +- scripts/clean.mjs | 4 +- typedoc.json | 4 +- yarn.lock | 101 ++++++- 58 files changed, 918 insertions(+), 356 deletions(-) create mode 100644 packages/tagscript-plugin-discord/.cliff-jumperrc.yml create mode 100644 packages/tagscript-plugin-discord/LICENSE create mode 100644 packages/tagscript-plugin-discord/README.md create mode 100644 packages/tagscript-plugin-discord/cliff.toml create mode 100644 packages/tagscript-plugin-discord/jest.config.mjs create mode 100644 packages/tagscript-plugin-discord/package.json create mode 100644 packages/tagscript-plugin-discord/src/index.ts rename packages/{tagscript => tagscript-plugin-discord}/src/lib/Parsers/AllowDeny.ts (94%) rename packages/{tagscript => tagscript-plugin-discord}/src/lib/Parsers/Cooldown.ts (87%) rename packages/{tagscript => tagscript-plugin-discord}/src/lib/Parsers/Delete.ts (73%) rename packages/{tagscript => tagscript-plugin-discord}/src/lib/Parsers/Embed.ts (93%) create mode 100644 packages/tagscript-plugin-discord/src/lib/Parsers/Format.ts rename packages/{tagscript => tagscript-plugin-discord}/src/lib/Parsers/Silent.ts (74%) create mode 100644 packages/tagscript-plugin-discord/src/lib/Parsers/index.ts create mode 100644 packages/tagscript-plugin-discord/src/lib/Transformer/Base.ts create mode 100644 packages/tagscript-plugin-discord/src/lib/Transformer/Guild.ts create mode 100644 packages/tagscript-plugin-discord/src/lib/Transformer/GuildMember.ts create mode 100644 packages/tagscript-plugin-discord/src/lib/Transformer/GuildTextBasedChannel.ts create mode 100644 packages/tagscript-plugin-discord/src/lib/Transformer/Role.ts create mode 100644 packages/tagscript-plugin-discord/src/lib/Transformer/User.ts create mode 100644 packages/tagscript-plugin-discord/src/lib/Transformer/index.ts create mode 100644 packages/tagscript-plugin-discord/src/lib/index.ts create mode 100644 packages/tagscript-plugin-discord/src/tsconfig.json rename packages/{tagscript => tagscript-plugin-discord}/tests/Parsers/AllowDeny.test.ts (93%) rename packages/{tagscript => tagscript-plugin-discord}/tests/Parsers/Cooldown.test.ts (79%) rename packages/{tagscript => tagscript-plugin-discord}/tests/Parsers/Delete.test.ts (77%) rename packages/{tagscript => tagscript-plugin-discord}/tests/Parsers/Embed.test.ts (96%) create mode 100644 packages/tagscript-plugin-discord/tests/Parsers/Format.test.ts rename packages/{tagscript => tagscript-plugin-discord}/tests/Parsers/Silent.test.ts (77%) create mode 100644 packages/tagscript-plugin-discord/tests/Transformer/Guild.test.ts create mode 100644 packages/tagscript-plugin-discord/tests/Transformer/GuildMember.test.ts create mode 100644 packages/tagscript-plugin-discord/tests/Transformer/GuildTextBasedChannel.test.ts create mode 100644 packages/tagscript-plugin-discord/tests/Transformer/Role.test.ts create mode 100644 packages/tagscript-plugin-discord/tests/Transformer/Structures.ts create mode 100644 packages/tagscript-plugin-discord/tests/Transformer/User.test.ts create mode 100644 packages/tagscript-plugin-discord/tests/tsconfig.json create mode 100644 packages/tagscript-plugin-discord/tsup.config.ts delete mode 100644 packages/tagscript/src/lib/Transformer/DiscordJs.ts diff --git a/.all-contributorsrc b/.all-contributorsrc index c95f3149..c863496c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3,7 +3,7 @@ "projectOwner": "imranbarbhuiya", "repoType": "github", "repoHost": "https://github.com", - "files": ["packages/tagscript/README.md", "README.md"], + "files": ["packages/tagscript/README.md", "packages/tagscript-plugin-discord/README.md", "README.md"], "imageSize": 100, "commit": true, "commitConvention": "angular", diff --git a/.eslintrc.json b/.eslintrc.json index dc3e3dcb..f0f5fdb6 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,7 +5,6 @@ "parser": "@typescript-eslint/parser", "rules": { "@typescript-eslint/no-base-to-string": "off", - "@typescript-eslint/consistent-type-imports": "error", "@typescript-eslint/await-thenable": "error", "@typescript-eslint/no-unsafe-member-access": "error", "@typescript-eslint/no-unsafe-argument": "error", diff --git a/.github/workflows/auto-deprecate.yml b/.github/workflows/auto-deprecate.yml index 1440dabe..709de156 100644 --- a/.github/workflows/auto-deprecate.yml +++ b/.github/workflows/auto-deprecate.yml @@ -24,4 +24,4 @@ jobs: - name: Deprecate versions run: yarn npm-deprecate env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 3e80963d..70540e8f 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -54,4 +54,4 @@ jobs: popd done env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/deprecate-on-merge.yml b/.github/workflows/deprecate-on-merge.yml index 8c469769..10450df1 100644 --- a/.github/workflows/deprecate-on-merge.yml +++ b/.github/workflows/deprecate-on-merge.yml @@ -25,5 +25,5 @@ jobs: - name: Deprecate versions run: yarn npm-deprecate --name "*pr-${PR_NUMBER}*" -d -v env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} PR_NUMBER: ${{ github.event.number }} diff --git a/.npm-deprecaterc.yml b/.npm-deprecaterc.yml index f33e13ca..d317de62 100644 --- a/.npm-deprecaterc.yml +++ b/.npm-deprecaterc.yml @@ -2,3 +2,4 @@ name: '*next*' verbose: true package: - 'tagscript' + - 'tagscript-plugin-discord' diff --git a/.vscode/settings.json b/.vscode/settings.json index 4c75bb95..668594d9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,5 +6,5 @@ "editor.detectIndentation": false, "files.eol": "\n", "typescript.tsdk": "node_modules\\typescript\\lib", - "cSpell.words": ["tagscript"] + "cSpell.words": ["cooldown", "tagscript"] } diff --git a/README.md b/README.md index 2f5faa37..5d4238de 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,6 @@ TagScript is a drop in easy to use string interpreter that lets you provide user Read Full Documentation [here](https://tagscript.js.org/). -## TODO - -- Move all the discord related stuff to a separate repo. -- Make a VSCode extension - ---- - ## Features - Written In Typescript diff --git a/package.json b/package.json index 3cc2bdb6..731a18e0 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@favware/cliff-jumper": "^1.4.0", "@favware/npm-deprecate": "^1.0.4", "@favware/rollup-type-bundler": "^1.0.7", + "@knodes/typedoc-plugin-monorepo-readmes": "^0.22.5", "@sapphire/eslint-config": "^4.3.4", "@sapphire/prettier-config": "^1.4.3", "@types/jest": "^27.4.1", @@ -42,6 +43,8 @@ "tsup": "^5.12.6", "turbo": "^1.2.6", "typedoc": "^0.22.15", + "typedoc-monorepo-link-types": "^0.0.2", + "typedoc-plugin-djs-links": "^1.0.4", "typescript": "^4.6.4" }, "repository": { diff --git a/packages/tagscript-plugin-discord/.cliff-jumperrc.yml b/packages/tagscript-plugin-discord/.cliff-jumperrc.yml new file mode 100644 index 00000000..44328709 --- /dev/null +++ b/packages/tagscript-plugin-discord/.cliff-jumperrc.yml @@ -0,0 +1,2 @@ +name: tagscript-plugin-discord +packagePath: packages/tagscript-plugin-discord diff --git a/packages/tagscript-plugin-discord/LICENSE b/packages/tagscript-plugin-discord/LICENSE new file mode 100644 index 00000000..680c36ce --- /dev/null +++ b/packages/tagscript-plugin-discord/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Parbez + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/tagscript-plugin-discord/README.md b/packages/tagscript-plugin-discord/README.md new file mode 100644 index 00000000..51c509a5 --- /dev/null +++ b/packages/tagscript-plugin-discord/README.md @@ -0,0 +1,74 @@ +
+ +# tagscript-plugin-discord + +**A tagscript plugin to work with discord.js** + +[![npm](https://img.shields.io/npm/dw/tagscript)](https://www.npmjs.com/package/tagscript) +[![codecov](https://codecov.io/gh/imranbarbhuiya/tagscript/branch/main/graph/badge.svg)](https://codecov.io/gh/imranbarbhuiya/tagscript) +[![npm](https://img.shields.io/npm/v/tagscript?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/tagscript) + +
+ +## Description + +A Plugin for [TagScript](https://www.npmjs.com/package/tagscript) to work with discord.js related structures. + +## Features + +- Written In Typescript +- Offers CJS, ESM and UMD builds +- Full TypeScript & JavaScript support + +## Installation + +`tagscript-plugin-discord` depends on the following packages. Be sure to install these along with this package! + +- [tagscript](https://www.npmjs.com/package/tagscript) +- [discord.js](https://www.npmjs.com/package/discord.js) + +You can use the following command to install this package, or replace npm install with your package manager of choice. + +```bash +npm install tagscript-plugin-discord tagscript discord.js + +``` + +## Usage + +```ts +import { Interpreter } from 'tagscript'; +import { MemberTransformer } from 'tagscript-plugin-discord'; + +const ts = new Interpreter(); + +await ts.run(str, { member: new MemberTransformer(GuildMember) }); +``` + +## Buy me some doughnuts + +If you want to support me by donating, you can do so by using any of the following methods. Thank you very much in advance! + +Buy Me A Coffee +Buy Me a Coffee at ko-fi.com + +## Contributors ✨ + +Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): + + + + + + + + + +

Parbez

💻 🚧 🤔

WhiteSource Renovate

🚧
+ + + + + + +This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! diff --git a/packages/tagscript-plugin-discord/cliff.toml b/packages/tagscript-plugin-discord/cliff.toml new file mode 100644 index 00000000..ff3b5a7c --- /dev/null +++ b/packages/tagscript-plugin-discord/cliff.toml @@ -0,0 +1,60 @@ +[changelog] +header = """ +# Changelog +All notable changes to this project will be documented in this file.\n +""" +body = """ +{% if version %}\ + # [{{ version | trim_start_matches(pat="v") }}]\ + {% if previous %}\ + {% if previous.version %}\ + (https://github.com/imranbarbhuiya/tagscript/compare/{{ previous.version }}...{{ version }})\ + {% else %} + (https://github.com/imranbarbhuiya/tagscript/tree/{{ version }})\ + {% endif %}\ + {% endif %} \ + - ({{ timestamp | date(format="%Y-%m-%d") }}) +{% else %}\ + # [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ## {{ group | upper_first }} + {% for commit in commits %} + - {% if commit.breaking %}\ + [**breaking**] \ + {% endif %}\ + {% if commit.scope %}\ + **{{commit.scope}}:** \ + {% endif %}\ + {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/imranbarbhuiya/tagscript/commit/{{ commit.id }}))\ + {% endfor %} +{% endfor %}\n +""" +trim = true +footer = "" + +[git] +conventional_commits = true +filter_unconventional = true +commit_parsers = [ + { message = "^feat", group = "Features"}, + { message = "^fix", group = "Bug Fixes"}, + { message = "^docs", group = "Documentation"}, + { message = "^perf", group = "Performance"}, + { message = "^refactor", group = "Refactor"}, + { message = "^typings", group = "Typings"}, + { message = "^types", group = "Typings"}, + { message = ".*deprecated", body = ".*deprecated", group = "Deprecation"}, + { message = "^revert", skip = true}, + { message = "^style", group = "Styling"}, + { message = "^test", group = "Testing"}, + { message = "^chore", skip = true}, + { message = "^ci", skip = true}, + { message = "^build", skip = true}, + { body = ".*security", group = "Security"}, +] +filter_commits = true +tag_pattern = "tagscript@[0-9]*" +ignore_tags = "" +topo_order = false +sort_commits = "newest" \ No newline at end of file diff --git a/packages/tagscript-plugin-discord/jest.config.mjs b/packages/tagscript-plugin-discord/jest.config.mjs new file mode 100644 index 00000000..09a16cb4 --- /dev/null +++ b/packages/tagscript-plugin-discord/jest.config.mjs @@ -0,0 +1,14 @@ +/** @type {import('@jest/types').Config.InitialOptions} */ +const config = { + displayName: 'unit test', + preset: 'ts-jest', + testMatch: ['/tests/**/*.test.ts'], + collectCoverageFrom: ['/src/**/*.ts'], + globals: { + 'ts-jest': { + tsconfig: '/tests/tsconfig.json' + } + } +}; + +export default config; diff --git a/packages/tagscript-plugin-discord/package.json b/packages/tagscript-plugin-discord/package.json new file mode 100644 index 00000000..72ad4508 --- /dev/null +++ b/packages/tagscript-plugin-discord/package.json @@ -0,0 +1,65 @@ +{ + "name": "tagscript-plugin-discord", + "version": "0.0.0", + "description": "A plugin for tagscript to work with discord.js.", + "main": "dist/index.js", + "module": "dist/index.mjs", + "browser": "dist/index.global.js", + "unpkg": "dist/index.global.js", + "types": "dist/index.d.ts", + "exports": { + "import": "./dist/index.mjs", + "require": "./dist/index.js", + "types": "./dist/index.d.ts" + }, + "sideEffects": false, + "author": "@imranbarbhuiya", + "license": "MIT", + "scripts": { + "lint": "eslint src --ext ts --fix -c ../../.eslintrc", + "build": "tsup && tsc -b src", + "prepack": "rollup-type-bundler -e tagscript discord.js", + "bump": "cliff-jumper", + "check-update": "cliff-jumper --dry-run", + "test": "jest" + }, + "keywords": [ + "tagscript", + "string parser", + "safe string", + "typescript", + "template engine", + "template", + "template string", + "tagscript discord", + "discord.js", + "tag", + "bot tag" + ], + "devDependencies": { + "discord.js": "^13.6.0", + "tagscript": "workspace:^", + "tsup": "^5.12.6", + "typescript": "^4.6.4" + }, + "peerDependencies": { + "discord.js": "^13.6.0", + "tagscript": "workspace:^" + }, + "engines": { + "node": ">=v16.9.0" + }, + "files": [ + "dist", + "!dist/*.tsbuildinfo" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/imranbarbhuiya/tagscript.git", + "directory": "packages/tagscript-plugin-discord" + }, + "bugs": { + "url": "https://github.com/imranbarbhuiya/tagscript/issues" + }, + "homepage": "https://tagscript.js.org/" +} diff --git a/packages/tagscript-plugin-discord/src/index.ts b/packages/tagscript-plugin-discord/src/index.ts new file mode 100644 index 00000000..f41a696f --- /dev/null +++ b/packages/tagscript-plugin-discord/src/index.ts @@ -0,0 +1 @@ +export * from './lib'; diff --git a/packages/tagscript/src/lib/Parsers/AllowDeny.ts b/packages/tagscript-plugin-discord/src/lib/Parsers/AllowDeny.ts similarity index 94% rename from packages/tagscript/src/lib/Parsers/AllowDeny.ts rename to packages/tagscript-plugin-discord/src/lib/Parsers/AllowDeny.ts index 0c537124..bc910a41 100644 --- a/packages/tagscript/src/lib/Parsers/AllowDeny.ts +++ b/packages/tagscript-plugin-discord/src/lib/Parsers/AllowDeny.ts @@ -1,7 +1,4 @@ -import type { IParser } from '../interfaces'; -import type { Context } from '../Interpreter'; -import { BaseParser } from './Base'; - +import { BaseParser, type IParser, type Context } from 'tagscript'; /** * The require tag will attempt to convert the given parameter into a channel, user * or role, using name or Id. If the user running the tag is not in the targeted diff --git a/packages/tagscript/src/lib/Parsers/Cooldown.ts b/packages/tagscript-plugin-discord/src/lib/Parsers/Cooldown.ts similarity index 87% rename from packages/tagscript/src/lib/Parsers/Cooldown.ts rename to packages/tagscript-plugin-discord/src/lib/Parsers/Cooldown.ts index 6680fa08..c28e82fc 100644 --- a/packages/tagscript/src/lib/Parsers/Cooldown.ts +++ b/packages/tagscript-plugin-discord/src/lib/Parsers/Cooldown.ts @@ -1,6 +1,4 @@ -import type { IParser } from '../interfaces'; -import type { Context } from '../Interpreter'; -import { BaseParser } from './Base'; +import { BaseParser, type Context, type IParser } from 'tagscript'; /** * The cooldown tag implements cooldowns when running a tag. diff --git a/packages/tagscript/src/lib/Parsers/Delete.ts b/packages/tagscript-plugin-discord/src/lib/Parsers/Delete.ts similarity index 73% rename from packages/tagscript/src/lib/Parsers/Delete.ts rename to packages/tagscript-plugin-discord/src/lib/Parsers/Delete.ts index efe6b3fc..926af791 100644 --- a/packages/tagscript/src/lib/Parsers/Delete.ts +++ b/packages/tagscript-plugin-discord/src/lib/Parsers/Delete.ts @@ -1,6 +1,4 @@ -import type { IParser } from '../interfaces'; -import type { Context } from '../Interpreter'; -import { BaseParser } from './Base'; +import { BaseParser, type Context, type IParser } from 'tagscript'; /** * Delete the triggered message. diff --git a/packages/tagscript/src/lib/Parsers/Embed.ts b/packages/tagscript-plugin-discord/src/lib/Parsers/Embed.ts similarity index 93% rename from packages/tagscript/src/lib/Parsers/Embed.ts rename to packages/tagscript-plugin-discord/src/lib/Parsers/Embed.ts index b02f2100..8c1a0653 100644 --- a/packages/tagscript/src/lib/Parsers/Embed.ts +++ b/packages/tagscript-plugin-discord/src/lib/Parsers/Embed.ts @@ -1,8 +1,6 @@ -import type { IParser } from '../interfaces'; -import type { Context } from '../Interpreter'; -import { BaseParser } from './Base'; +import { BaseParser, split, type Context, type IParser } from 'tagscript'; + import type { Awaitable, MessageEmbedOptions } from 'discord.js'; -import { split } from '../Utils/Util'; /** * An embed tag will send an embed in the tag response. diff --git a/packages/tagscript-plugin-discord/src/lib/Parsers/Format.ts b/packages/tagscript-plugin-discord/src/lib/Parsers/Format.ts new file mode 100644 index 00000000..1d94bb75 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Parsers/Format.ts @@ -0,0 +1,23 @@ +import { BaseParser, type Context, type IParser } from 'tagscript'; + +export class DateFormatParser extends BaseParser implements IParser { + public constructor() { + super(['date', 'unix', 'currenttime']); + } + + public parse(ctx: Context) { + const { declaration } = ctx.tag; + if (['unix', 'currenttime'].includes(declaration!)) { + return Date.now().toString(); + } + const parameter = ctx.tag.parameter ?? 'f'; + if (!['f', 'F', 't', 'T', 'R'].includes(parameter)) return null; + let payload: string | number = ctx.tag.payload ?? Date.now().toString(); + if (!/^\d+$/.test(payload)) { + payload = new Date(payload).getTime().toString(); + } + if (payload.length > 10) payload = Math.floor(Number(payload) / 1000); + + return ``; + } +} diff --git a/packages/tagscript/src/lib/Parsers/Silent.ts b/packages/tagscript-plugin-discord/src/lib/Parsers/Silent.ts similarity index 74% rename from packages/tagscript/src/lib/Parsers/Silent.ts rename to packages/tagscript-plugin-discord/src/lib/Parsers/Silent.ts index 1f95a54d..c0a3187f 100644 --- a/packages/tagscript/src/lib/Parsers/Silent.ts +++ b/packages/tagscript-plugin-discord/src/lib/Parsers/Silent.ts @@ -1,6 +1,4 @@ -import type { IParser } from '../interfaces'; -import type { Context } from '../Interpreter'; -import { BaseParser } from './Base'; +import { BaseParser, type Context, type IParser } from 'tagscript'; /** * Silence the used command outputs. diff --git a/packages/tagscript-plugin-discord/src/lib/Parsers/index.ts b/packages/tagscript-plugin-discord/src/lib/Parsers/index.ts new file mode 100644 index 00000000..abe84076 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Parsers/index.ts @@ -0,0 +1,6 @@ +export * from './AllowDeny'; +export * from './Cooldown'; +export * from './Delete'; +export * from './Embed'; +export * from './Format'; +export * from './Silent'; diff --git a/packages/tagscript-plugin-discord/src/lib/Transformer/Base.ts b/packages/tagscript-plugin-discord/src/lib/Transformer/Base.ts new file mode 100644 index 00000000..d723e531 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Transformer/Base.ts @@ -0,0 +1,39 @@ +import type { Lexer, ITransformer } from 'tagscript'; +import type { GuildTextBasedChannel, Role, User, GuildMember, Guild } from 'discord.js'; + +export type outputResolvable = string | number | boolean | null | undefined; + +export interface SafeValues { + [key: string]: outputResolvable | ((base: T) => outputResolvable); +} + +/** + * Transformer for Discord.js objects. + * + * @abstract + */ +export abstract class BaseTransformer implements ITransformer { + protected base: T; + protected safeValues: SafeValues = {}; + + public constructor(base: T, safeValues: SafeValues = {}) { + this.base = base; + this.safeValues.id = this.base.id; + this.safeValues.mention = base.toString(); + this.safeValues.name = 'name' in base ? base.name : ''; + this.updateSafeValues(); + this.safeValues = { ...this.safeValues, ...safeValues }; + } + + public transform(tag: Lexer) { + if (!tag.parameter) return this.safeValues.mention as string; + let value = this.safeValues[tag.parameter]; + if (typeof value === 'function') value = value(this.base); + if (value === undefined) return null; + return `${value ?? ''}`; + } + + protected updateSafeValues() { + // + } +} diff --git a/packages/tagscript-plugin-discord/src/lib/Transformer/Guild.ts b/packages/tagscript-plugin-discord/src/lib/Transformer/Guild.ts new file mode 100644 index 00000000..d6d0f279 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Transformer/Guild.ts @@ -0,0 +1,68 @@ +import type { Guild } from 'discord.js'; +import { BaseTransformer } from './Base'; + +/** + * Transformer for Discord {@link Guild} + * + * @properties + * ``` + * id: Gives guild id. + * name: Gives guild name. + * description: Gives guild description. + * icon: Gives guild icon. + * splash: Gives guild splash. + * banner: Gives guild banner. + * features: Gives guild features. + * ownerId: Gives guild owner id. + * createdAt: Gives guild create date. + * createdTimestamp: Gives guild create date in ms. + * large: Gives true if the guild is large else false. + * memberCount: Gives guild member count. + * random: Gives random guild member. + * roles: Gives guild roles. + * roleIds: Gives guild roles ids. + * roleNames: Gives guild roles names. + * roleCount: Gives guild roles count. + * channels: Gives guild channels. + * channelIds: Gives guild channels ids. + * channelNames: Gives guild channels names. + * channelCount: Gives guild channels count. + * emojiCount: Gives guild emojis count. (These values depends on cache so it might be inaccurate) + * stickerCount: Gives guild stickers count. (These values depends on cache so it might be inaccurate) + * bots: Gives guild bots count. (These values depends on cache so it might be inaccurate) + * humans: Gives guild humans count. (These values depends on cache so it might be inaccurate) + * afkTimeout: Gives guild afk timeout. + * afkChannel: Gives guild afk channel. + * verificationLevel: Gives guild verification level. + * ``` + */ +export class GuildTransformer extends BaseTransformer { + protected override updateSafeValues() { + this.safeValues.description = this.base.description; + this.safeValues.icon = this.base.iconURL(); + this.safeValues.splash = this.base.splashURL(); + this.safeValues.banner = this.base.bannerURL(); + this.safeValues.features = this.base.features.join(' ') || '`None`'; + this.safeValues.ownerId = this.base.ownerId; + this.safeValues.createdAt = this.base.createdAt.toISOString(); + this.safeValues.createdTimestamp = this.base.createdTimestamp; + this.safeValues.large = this.base.large; + this.safeValues.memberCount = this.base.memberCount; + this.safeValues.random = this.base.members.cache.random()?.toString() ?? ''; + this.safeValues.roles = this.base.roles.cache.map((role) => role).join(' ') || '`None`'; + this.safeValues.roleIds = this.base.roles.cache.map((role) => role.id).join(', ') || '`None`'; + this.safeValues.roleNames = this.base.roles.cache.map((role) => role.name).join(', ') || '`None`'; + this.safeValues.roleCount = this.base.roles.cache.size; + this.safeValues.channels = this.base.channels.cache.map((channel) => channel).join(' ') || '`None`'; + this.safeValues.channelIds = this.base.channels.cache.map((channel) => channel.id).join(', ') || '`None`'; + this.safeValues.channelNames = this.base.channels.cache.map((channel) => channel.name).join(', ') || '`None`'; + this.safeValues.channelCount = this.base.channels.cache.size; + this.safeValues.emojiCount = this.base.emojis.cache.size; + this.safeValues.stickerCount = this.base.stickers.cache.size; + this.safeValues.bots = this.base.members.cache.filter((m) => m.user.bot).size; + this.safeValues.humans = this.base.members.cache.filter((m) => !m.user.bot).size; + this.safeValues.afkTimeout = this.base.afkTimeout; + this.safeValues.afkChannel = `${this.base.afkChannel}`; + this.safeValues.verificationLevel = this.base.verificationLevel; + } +} diff --git a/packages/tagscript-plugin-discord/src/lib/Transformer/GuildMember.ts b/packages/tagscript-plugin-discord/src/lib/Transformer/GuildMember.ts new file mode 100644 index 00000000..bc7f2033 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Transformer/GuildMember.ts @@ -0,0 +1,56 @@ +import type { GuildMember } from 'discord.js'; +import { BaseTransformer } from './Base'; + +/** + * Transformer for {@link GuildMember}. + * + * @properties + * ``` + * id: Gives member id. + * mention: Mentions the member. + * username: Gives username of the member. + * discriminator: Gives discriminator of the member + * tag: Gives username#discriminator + * avatar: Gives member's custom avatar if they have one. Else it'll be an empty string. + * displayAvatar: Gives member's avatar URL if they have one else gives member's default avatar. + * nickname: Gives member's nickname. + * displayName: Gives member's display name. (nickname if they have one else username) + * joinedAt: Gives member's join date. + * joinedTimestamp: Gives member's join date in ms + * createdAt: Gives member's account create date. + * createdTimestamp: Gives member's account created date in ms + * bot: Gives true if the member is a bot else false. + * color: Gives member's highest role color. + * position: Gives member's highest role position. + * roles: Gives member's roles. + * roleIds: Gives member's roles ids. + * roleNames: Gives member's roles names. + * topRole: Gives member's highest role name. + * timeoutUntil: Gives member's timeout until date. + * timeoutUntilTimestamp: Gives member's timeout until date in ms. + * ``` + */ +export class MemberTransformer extends BaseTransformer { + protected override updateSafeValues() { + this.safeValues.username = this.base.user.username; + this.safeValues.discriminator = this.base.user.discriminator; + this.safeValues.tag = this.base.user.tag; + this.safeValues.avatar = this.base.avatarURL(); + this.safeValues.displayAvatar = this.base.displayAvatarURL(); + this.safeValues.nickname = this.base.nickname; + this.safeValues.displayName = this.base.displayName; + this.safeValues.joinedAt = this.base.joinedAt?.toISOString() ?? ''; + this.safeValues.joinedTimestamp = this.base.joinedTimestamp; + this.safeValues.createdAt = this.base.user.createdAt.toISOString(); + this.safeValues.createdTimestamp = this.base.user.createdTimestamp; + this.safeValues.bot = this.base.user.bot; + this.safeValues.color = this.base.roles.color?.hexColor ?? ''; + this.safeValues.position = this.base.roles.highest.position; + this.safeValues.roles = this.base.roles.cache.map((role) => role).join(' ') || '`None`'; + this.safeValues.roleIds = this.base.roles.cache.map((role) => role.id).join(', ') || '`None`'; + this.safeValues.roleNames = this.base.roles.cache.map((role) => role.name).join(', ') || '`None`'; + this.safeValues.topRole = this.base.roles.highest.name; + this.safeValues.timeoutUntil = this.base.communicationDisabledUntil?.toISOString() ?? ''; + this.safeValues.timeoutUntilTimestamp = this.base.communicationDisabledUntilTimestamp; + } +} diff --git a/packages/tagscript-plugin-discord/src/lib/Transformer/GuildTextBasedChannel.ts b/packages/tagscript-plugin-discord/src/lib/Transformer/GuildTextBasedChannel.ts new file mode 100644 index 00000000..2d5a6431 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Transformer/GuildTextBasedChannel.ts @@ -0,0 +1,38 @@ +import type { GuildTextBasedChannel } from 'discord.js'; +import { BaseTransformer } from './Base'; + +/** + * Transformer for Discord {@link GuildTextBasedChannel} + * + * @properties + * ``` + * id: Gives channel id. + * mention: Mentions the channel. + * name: Gives channel name. + * topic: Gives channel topic. + * type: Gives channel type. + * position: Gives channel position. + * nsfw: Gives true if the channel is nsfw else false. + * parentId: Gives channel parent id. + * parentName: Gives channel parent name. + * parentType: Gives channel parent type. + * parentPosition: Gives channel parent position. + * createdAt: Gives channel create date. + * createdTimestamp: Gives channel create date in ms. + * slowmode: Gives channel slowmode. + */ +export class ChannelTransformer extends BaseTransformer { + protected override updateSafeValues() { + this.safeValues.topic = 'topic' in this.base ? this.base.topic : ''; + this.safeValues.type = this.base.type; + this.safeValues.position = 'position' in this.base ? this.base.position : 0; + this.safeValues.nsfw = 'nsfw' in this.base ? this.base.nsfw : this.base.parent?.nsfw ?? false; + this.safeValues.parentId = this.base.parentId; + this.safeValues.parentName = this.base.parent?.name ?? ''; + this.safeValues.parentType = this.base.parent?.type ?? ''; + this.safeValues.parentPosition = this.base.parent?.position ?? 0; + this.safeValues.createdAt = this.base.createdAt.toISOString(); + this.safeValues.createdTimestamp = this.base.createdTimestamp; + this.safeValues.slowmode = 'rateLimitPerUser' in this.base ? this.base.rateLimitPerUser : 0; + } +} diff --git a/packages/tagscript-plugin-discord/src/lib/Transformer/Role.ts b/packages/tagscript-plugin-discord/src/lib/Transformer/Role.ts new file mode 100644 index 00000000..d6dbf0e6 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Transformer/Role.ts @@ -0,0 +1,33 @@ +import type { Role } from 'discord.js'; +import { BaseTransformer } from './Base'; + +/** + * Transformer for Discord {@link Role} + * + * @properties + * ``` + * id: Gives role id. + * name: Gives role name. + * mention: Mentions the role. + * color: Gives role color. + * hoist: Gives true if the role is hoisted else false. + * mentionable: Gives true if the role is mentionable else false. + * position: Gives role position. + * permissions: Gives role permissions. + * createdAt: Gives role create date. + * createdTimestamp: Gives role create date in ms. + * memberCount: Gives role member count. + * ``` + */ +export class RoleTransformer extends BaseTransformer { + protected override updateSafeValues() { + this.safeValues.color = this.base.color.toString(); + this.safeValues.hoist = this.base.hoist; + this.safeValues.mentionable = this.base.mentionable; + this.safeValues.position = this.base.position; + this.safeValues.permissions = this.base.permissions.toArray().join(', '); + this.safeValues.createdAt = this.base.createdAt.toISOString(); + this.safeValues.createdTimestamp = this.base.createdTimestamp; + this.safeValues.memberCount = this.base.members.size; + } +} diff --git a/packages/tagscript-plugin-discord/src/lib/Transformer/User.ts b/packages/tagscript-plugin-discord/src/lib/Transformer/User.ts new file mode 100644 index 00000000..67fa24a3 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Transformer/User.ts @@ -0,0 +1,32 @@ +import type { User } from 'discord.js'; +import { BaseTransformer } from './Base'; + +/** + * Transformer for {@link User} + * + * @properties + * ``` + * id: Gives user id. + * mention: Mentions the user. + * username: Gives username of the user. + * discriminator: Gives discriminator of the user + * tag: Gives username#discriminator + * avatar: Gives user's custom avatar if they have one. Else it'll be an empty string. + * displayAvatar: Gives user's avatar URL if they have one else gives user's default avatar. + * createdAt: Gives user's account create date. + * createdTimestamp: Gives user's account created date in ms + * bot: Gives true if the user is a bot else false. + * ``` + */ +export class UserTransformer extends BaseTransformer { + protected override updateSafeValues() { + this.safeValues.username = this.base.username; + this.safeValues.discriminator = this.base.discriminator; + this.safeValues.tag = this.base.tag; + this.safeValues.avatar = this.base.avatarURL(); + this.safeValues.displayAvatar = this.base.displayAvatarURL(); + this.safeValues.createdAt = this.base.createdAt.toISOString(); + this.safeValues.createdTimestamp = this.base.createdTimestamp; + this.safeValues.bot = this.base.bot; + } +} diff --git a/packages/tagscript-plugin-discord/src/lib/Transformer/index.ts b/packages/tagscript-plugin-discord/src/lib/Transformer/index.ts new file mode 100644 index 00000000..dedea0f0 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/Transformer/index.ts @@ -0,0 +1,7 @@ +export * from './Base'; +export * from './Guild'; +export * from './GuildMember'; +export * from './GuildMember'; +export * from './GuildTextBasedChannel'; +export * from './Role'; +export * from './User'; diff --git a/packages/tagscript-plugin-discord/src/lib/index.ts b/packages/tagscript-plugin-discord/src/lib/index.ts new file mode 100644 index 00000000..17472149 --- /dev/null +++ b/packages/tagscript-plugin-discord/src/lib/index.ts @@ -0,0 +1,2 @@ +export * from './Transformer'; +export * from './Parsers'; diff --git a/packages/tagscript-plugin-discord/src/tsconfig.json b/packages/tagscript-plugin-discord/src/tsconfig.json new file mode 100644 index 00000000..1e91301c --- /dev/null +++ b/packages/tagscript-plugin-discord/src/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "./", + "outDir": "../dist", + "composite": true, + "tsBuildInfoFile": "../dist/.tsbuildinfo", + "emitDeclarationOnly": true + }, + "include": ["."] +} diff --git a/packages/tagscript/tests/Parsers/AllowDeny.test.ts b/packages/tagscript-plugin-discord/tests/Parsers/AllowDeny.test.ts similarity index 93% rename from packages/tagscript/tests/Parsers/AllowDeny.test.ts rename to packages/tagscript-plugin-discord/tests/Parsers/AllowDeny.test.ts index 0eb167b3..6132017c 100644 --- a/packages/tagscript/tests/Parsers/AllowDeny.test.ts +++ b/packages/tagscript-plugin-discord/tests/Parsers/AllowDeny.test.ts @@ -1,4 +1,5 @@ -import { RequiredParser, DenyParser, Interpreter } from '../../src'; +import { Interpreter } from 'tagscript'; +import { RequiredParser, DenyParser } from '../../src'; describe('RequiredParser', () => { const ts = new Interpreter(new RequiredParser()); diff --git a/packages/tagscript/tests/Parsers/Cooldown.test.ts b/packages/tagscript-plugin-discord/tests/Parsers/Cooldown.test.ts similarity index 79% rename from packages/tagscript/tests/Parsers/Cooldown.test.ts rename to packages/tagscript-plugin-discord/tests/Parsers/Cooldown.test.ts index a85bd4b4..54ece555 100644 --- a/packages/tagscript/tests/Parsers/Cooldown.test.ts +++ b/packages/tagscript-plugin-discord/tests/Parsers/Cooldown.test.ts @@ -1,4 +1,5 @@ -import { CooldownParser, Interpreter } from '../../src'; +import { Interpreter } from 'tagscript'; +import { CooldownParser } from '../../src'; describe('CooldownParser', () => { const ts = new Interpreter(new CooldownParser()); diff --git a/packages/tagscript/tests/Parsers/Delete.test.ts b/packages/tagscript-plugin-discord/tests/Parsers/Delete.test.ts similarity index 77% rename from packages/tagscript/tests/Parsers/Delete.test.ts rename to packages/tagscript-plugin-discord/tests/Parsers/Delete.test.ts index 3ad92f02..ebeea455 100644 --- a/packages/tagscript/tests/Parsers/Delete.test.ts +++ b/packages/tagscript-plugin-discord/tests/Parsers/Delete.test.ts @@ -1,4 +1,5 @@ -import { DeleteParser, Interpreter } from '../../src'; +import { Interpreter } from 'tagscript'; +import { DeleteParser } from '../../src'; describe('DeleteParser', () => { const ts = new Interpreter(new DeleteParser()); diff --git a/packages/tagscript/tests/Parsers/Embed.test.ts b/packages/tagscript-plugin-discord/tests/Parsers/Embed.test.ts similarity index 96% rename from packages/tagscript/tests/Parsers/Embed.test.ts rename to packages/tagscript-plugin-discord/tests/Parsers/Embed.test.ts index 01140499..0526b953 100644 --- a/packages/tagscript/tests/Parsers/Embed.test.ts +++ b/packages/tagscript-plugin-discord/tests/Parsers/Embed.test.ts @@ -1,4 +1,5 @@ -import { EmbedParser, Interpreter } from '../../src'; +import { Interpreter } from 'tagscript'; +import { EmbedParser } from '../../src'; const ts = new Interpreter(new EmbedParser()); describe('EmbedParser', () => { diff --git a/packages/tagscript-plugin-discord/tests/Parsers/Format.test.ts b/packages/tagscript-plugin-discord/tests/Parsers/Format.test.ts new file mode 100644 index 00000000..1a950734 --- /dev/null +++ b/packages/tagscript-plugin-discord/tests/Parsers/Format.test.ts @@ -0,0 +1,24 @@ +import { Interpreter } from 'tagscript'; +import { DateFormatParser } from '../../src'; + +const ts = new Interpreter(new DateFormatParser()); +describe('currentTime', () => { + test('GIVEN currentTime or unix THEN return current timestamp in ms', async () => { + expect(Number((await ts.run('{unix}')).body)).toBeCloseTo(Date.now(), -1); + expect(Number((await ts.run('{currenttime}')).body)).toBeCloseTo(Date.now(), -1); + }); +}); + +describe('DateFormat', () => { + test('GIVEN date THEN return formatted date', async () => { + expect((await ts.run('{date}')).body).toBe(``); + expect((await ts.run('{date:2020-01-01}')).body).toBe(''); + expect((await ts.run('{date(k):2020-01-01}')).body).toBe('{date(k):2020-01-01}'); + expect((await ts.run('{date(F):2020-01-01}')).body).toBe(''); + expect((await ts.run('{date(t):2020-01-01}')).body).toBe(''); + expect((await ts.run('{date(T):2020-01-01}')).body).toBe(''); + expect((await ts.run('{date(R):2020-01-01}')).body).toBe(''); + expect((await ts.run('{date(R):1577836800000}')).body).toBe(''); + expect((await ts.run('{date(R):1577836800}')).body).toBe(''); + }); +}); diff --git a/packages/tagscript/tests/Parsers/Silent.test.ts b/packages/tagscript-plugin-discord/tests/Parsers/Silent.test.ts similarity index 77% rename from packages/tagscript/tests/Parsers/Silent.test.ts rename to packages/tagscript-plugin-discord/tests/Parsers/Silent.test.ts index 24b56636..a28697f1 100644 --- a/packages/tagscript/tests/Parsers/Silent.test.ts +++ b/packages/tagscript-plugin-discord/tests/Parsers/Silent.test.ts @@ -1,4 +1,5 @@ -import { SilentParser, Interpreter } from '../../src'; +import { Interpreter } from 'tagscript'; +import { SilentParser } from '../../src'; describe('SilentParser', () => { const ts = new Interpreter(new SilentParser()); diff --git a/packages/tagscript-plugin-discord/tests/Transformer/Guild.test.ts b/packages/tagscript-plugin-discord/tests/Transformer/Guild.test.ts new file mode 100644 index 00000000..c1e78156 --- /dev/null +++ b/packages/tagscript-plugin-discord/tests/Transformer/Guild.test.ts @@ -0,0 +1,10 @@ +import { Interpreter, StrictVarsParser } from 'tagscript'; +import { GuildTransformer } from '../../src'; +import { guild } from './Structures'; + +const ts = new Interpreter(new StrictVarsParser()); +describe('GuildTransformer', () => { + test('GIVEN a a guild tag THEN return value from guild variable', async () => { + expect((await ts.run('{guild}', { guild: new GuildTransformer(guild) })).body).toBe('Team R.O.T.I'); + }); +}); diff --git a/packages/tagscript-plugin-discord/tests/Transformer/GuildMember.test.ts b/packages/tagscript-plugin-discord/tests/Transformer/GuildMember.test.ts new file mode 100644 index 00000000..f845e824 --- /dev/null +++ b/packages/tagscript-plugin-discord/tests/Transformer/GuildMember.test.ts @@ -0,0 +1,12 @@ +import { Interpreter, StrictVarsParser } from 'tagscript'; +import { MemberTransformer } from '../../src'; +import { member } from './Structures'; + +const ts = new Interpreter(new StrictVarsParser()); + +describe('MemberTransformer', () => { + test('GIVEN a member tag THEN return value from member variable', async () => { + expect((await ts.run('{member}', { member: new MemberTransformer(member) })).body).toBe('<@758880890159235083>'); + expect((await ts.run('{member(nickname)}', { member: new MemberTransformer(member) })).body).toBe(''); + }); +}); diff --git a/packages/tagscript-plugin-discord/tests/Transformer/GuildTextBasedChannel.test.ts b/packages/tagscript-plugin-discord/tests/Transformer/GuildTextBasedChannel.test.ts new file mode 100644 index 00000000..8c2ec085 --- /dev/null +++ b/packages/tagscript-plugin-discord/tests/Transformer/GuildTextBasedChannel.test.ts @@ -0,0 +1,11 @@ +import { Interpreter, StrictVarsParser } from 'tagscript'; +import { ChannelTransformer } from '../../src'; +import { channel } from './Structures'; + +const ts = new Interpreter(new StrictVarsParser()); + +describe('ChannelTransformer', () => { + test('GIVEN a channel tag THEN return value from channel variable', async () => { + expect((await ts.run('{channel}', { channel: new ChannelTransformer(channel) })).body).toBe('<#933395546138357800>'); + }); +}); diff --git a/packages/tagscript-plugin-discord/tests/Transformer/Role.test.ts b/packages/tagscript-plugin-discord/tests/Transformer/Role.test.ts new file mode 100644 index 00000000..532ad1ac --- /dev/null +++ b/packages/tagscript-plugin-discord/tests/Transformer/Role.test.ts @@ -0,0 +1,11 @@ +import { Interpreter, StrictVarsParser } from 'tagscript'; +import { RoleTransformer } from '../../src'; +import { role } from './Structures'; + +const ts = new Interpreter(new StrictVarsParser()); + +describe('RoleTransformer', () => { + test('GIVEN a role tag THEN return value from Role variable', async () => { + expect((await ts.run('{role}', { role: new RoleTransformer(role) })).body).toBe('<@&933378013154906142>'); + }); +}); diff --git a/packages/tagscript-plugin-discord/tests/Transformer/Structures.ts b/packages/tagscript-plugin-discord/tests/Transformer/Structures.ts new file mode 100644 index 00000000..9fcf1456 --- /dev/null +++ b/packages/tagscript-plugin-discord/tests/Transformer/Structures.ts @@ -0,0 +1,96 @@ +import { Client, Guild, GuildMember, Role, TextChannel, User } from 'discord.js'; +import { APIUser, APIRole, APIGuild, APIGuildMember, APIChannel } from 'discord-api-types/v9'; + +export const client = new Client({ intents: [] }); + +const userObject: APIUser = { + id: '758880890159235083', + username: 'P', + discriminator: '1572', + avatar: '17ac5f89d5f8b08b5bbd6cc43c930399', + bot: false, + system: false, + mfa_enabled: false +}; + +const roleObject: APIRole = { + unicode_emoji: null, + id: '933378013154906142', + name: '.', + color: 0, + hoist: false, + position: 16, + permissions: '8', + managed: false, + mentionable: false +}; + +const everyoneRoleObject: APIRole = { + icon: null, + unicode_emoji: null, + id: '933368398996447292', + name: '@everyone', + color: 0, + hoist: false, + position: 0, + permissions: '0', + managed: false, + mentionable: false +}; + +const guildObject = { + id: '933368398996447292', + name: 'Team R.O.T.I', + icon: '396ee43e3064f8ec805fede6f3bcdc6d', + splash: null, + discovery_splash: null, + owner_id: '938716130720235601', + afk_channel_id: null, + afk_timeout: 300, + verification_level: 0, + default_message_notifications: 0, + explicit_content_filter: 0, + roles: [roleObject, everyoneRoleObject], + emojis: [], + features: [], + mfa_level: 0, + system_channel_flags: 0, + vanity_url_code: null, + description: null, + banner: null, + premium_tier: 0, + preferred_locale: 'en-US', + nsfw_level: 0, + premium_progress_bar_enabled: false +} as unknown as APIGuild; + +const memberObject: APIGuildMember = { + roles: ['933378013154906142', '933368398996447292'], + joined_at: '2022-01-19T16:52:53.953Z', + deaf: false, + mute: false, + user: userObject +}; + +const channelObject: APIChannel = { + id: '933395546138357800', + type: 0 +}; + +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ + +// @ts-expect-error using protected constructor to test +export const user: User = new User(client, userObject); +// @ts-expect-error using protected constructor to test +export const guild: Guild = new Guild(client, guildObject); + +// @ts-expect-error using protected constructor to test +export const role: Role = new Role(client, roleObject, guild); + +// @ts-expect-error using protected constructor to test +export const member: GuildMember = new GuildMember(client, memberObject, guild); + +// @ts-expect-error using protected constructor to test +export const channel: TextChannel = new TextChannel(guild, channelObject, client); + +/* eslint-enable @typescript-eslint/no-unsafe-assignment */ diff --git a/packages/tagscript-plugin-discord/tests/Transformer/User.test.ts b/packages/tagscript-plugin-discord/tests/Transformer/User.test.ts new file mode 100644 index 00000000..f3cd58aa --- /dev/null +++ b/packages/tagscript-plugin-discord/tests/Transformer/User.test.ts @@ -0,0 +1,16 @@ +import { Interpreter, StrictVarsParser } from 'tagscript'; +import { UserTransformer } from '../../src'; +import { user } from './Structures'; + +const ts = new Interpreter(new StrictVarsParser()); + +describe('UserTransformer', () => { + test('GIVEN a user tag THEN return value from user variable', async () => { + expect((await ts.run('{user}', { user: new UserTransformer(user) })).body).toBe('<@758880890159235083>'); + expect((await ts.run('{user(username)}', { user: new UserTransformer(user) })).body).toBe('P'); + expect((await ts.run('{user(a)}', { user: new UserTransformer(user) })).body).toBe('{user(a)}'); + expect((await ts.run('{user(b)}', { user: new UserTransformer(user, { b: (m) => m.defaultAvatarURL }) })).body).toBe( + 'https://cdn.discordapp.com/embed/avatars/2.png' + ); + }); +}); diff --git a/packages/tagscript-plugin-discord/tests/tsconfig.json b/packages/tagscript-plugin-discord/tests/tsconfig.json new file mode 100644 index 00000000..01b87e86 --- /dev/null +++ b/packages/tagscript-plugin-discord/tests/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../../tsconfig.base.json", + "include": ["."] +} diff --git a/packages/tagscript-plugin-discord/tsup.config.ts b/packages/tagscript-plugin-discord/tsup.config.ts new file mode 100644 index 00000000..30a2b016 --- /dev/null +++ b/packages/tagscript-plugin-discord/tsup.config.ts @@ -0,0 +1,3 @@ +import { createTsupConfig } from '../../scripts/tsup.config'; + +export default createTsupConfig({ globalName: 'TagScriptDiscord' }); diff --git a/packages/tagscript/README.md b/packages/tagscript/README.md index ff3b78f9..51af316f 100644 --- a/packages/tagscript/README.md +++ b/packages/tagscript/README.md @@ -16,16 +16,6 @@ TagScript is a drop in easy to use string interpreter that lets you provide user Read Full Documentation [here](https://tagscript.js.org/). -> 🤖 TagScript is currently in beta. Its API is useable in production right now, but you might need to pull request improvements or fixes for some bugs. There isn't currently a 1.0 release schedule, we're still getting the architecture right. For the same reason it's recommended to pin your dependency to a specific version. - ---- - -Looking for help to - -- Make this repo a monorepo. -- Move all the discord related stuff to a separate repo. -- Make a VSCode extension - --- ## Features @@ -37,7 +27,7 @@ Looking for help to - Simple, expressive and safe template engine. - Supports your own parsers and transformers -## Install +## Installation ```bash # npm @@ -76,7 +66,6 @@ const result = await ts.run( I pick {if({5050:.}!=):heads|tails} ` ); -console.log(result); ``` ## Parsers @@ -95,11 +84,9 @@ Transformers are used to transform a value based on the tag at runtime. You can Your own transformer should implement [ITransformer](https://tagscript.js.org/interfaces/ITransformer.html) interface. ```ts -import { Interpreter, MemberTransformer, StringTransformer } from 'tagscript'; +import { Interpreter, StringTransformer } from 'tagscript'; const ts = new Interpreter(); -await ts.run(str, { member: new MemberTransformer(GuildMember) }); - await ts.run(str, { args: new StringTransformer(args) }); ``` diff --git a/packages/tagscript/package.json b/packages/tagscript/package.json index 09b3200b..e0e2bccb 100644 --- a/packages/tagscript/package.json +++ b/packages/tagscript/package.json @@ -17,7 +17,7 @@ "scripts": { "lint": "eslint src --ext ts --fix -c ../../.eslintrc", "build": "tsup && tsc -b src", - "prepack": "yarn build", + "prepack": "rollup-type-bundler", "bump": "cliff-jumper", "check-update": "cliff-jumper --dry-run", "test": "jest" @@ -29,19 +29,15 @@ "typescript", "template engine", "template", - "template string" + "template string", + "tag" ], - "publishConfig": { - "access": "public" - }, "devDependencies": { - "discord.js": "^13.6.0", "tsup": "^5.12.6", "typescript": "^4.6.4" }, "engines": { - "node": ">=v14.0.0", - "npm": ">=7.0.0" + "node": ">=v14.0.0" }, "files": [ "dist", diff --git a/packages/tagscript/src/lib/Parsers/Format.ts b/packages/tagscript/src/lib/Parsers/Format.ts index d8a76bee..02cbde9e 100644 --- a/packages/tagscript/src/lib/Parsers/Format.ts +++ b/packages/tagscript/src/lib/Parsers/Format.ts @@ -25,7 +25,7 @@ export class StringFormatParser extends BaseParser implements IParser { public parse(ctx: Context) { const { declaration, payload } = ctx.tag; - switch (declaration) { + switch (declaration as 'lower' | 'upper' | 'capitalize' | 'escape') { case 'lower': return payload!.toLowerCase(); case 'upper': @@ -34,34 +34,10 @@ export class StringFormatParser extends BaseParser implements IParser { return payload!.charAt(0).toUpperCase() + payload!.slice(1); case 'escape': return escapeContent(payload!); - default: - return payload!; } } } -// This is a discord specific formatter -export class DateFormatParser extends BaseParser implements IParser { - public constructor() { - super(['date', 'unix', 'currentTime'], false, true); - } - - public parse(ctx: Context) { - const { declaration } = ctx.tag; - if (['unix', 'currentTime'].includes(declaration!)) { - return Date.now().toString(); - } - const parameter = ctx.tag.parameter ?? 'f'; - let payload: string | number = ctx.tag.payload!; - if (!/^\d+$/.test(payload)) { - payload = new Date(payload).getTime().toString(); - } - if (payload.length > 10) payload = Math.floor(Number(payload) / 1000); - - return ``; - } -} - export class OrdinalFormatParser extends BaseParser implements IParser { public constructor() { super(['ordinal', 'ord'], false, true); diff --git a/packages/tagscript/src/lib/Parsers/index.ts b/packages/tagscript/src/lib/Parsers/index.ts index 90e71342..d8d31b95 100644 --- a/packages/tagscript/src/lib/Parsers/index.ts +++ b/packages/tagscript/src/lib/Parsers/index.ts @@ -1,11 +1,7 @@ -export * from './AllowDeny'; export * from './Base'; export * from './Break'; export * from './Control'; -export * from './Cooldown'; export * from './Define'; -export * from './Delete'; -export * from './Embed'; export * from './FiftyFifty'; export * from './Format'; export * from './Includes'; @@ -13,7 +9,6 @@ export * from './LooseVars'; export * from './Random'; export * from './Range'; export * from './Replace'; -export * from './Silent'; export * from './Slice'; export * from './Stop'; export * from './StrictVars'; diff --git a/packages/tagscript/src/lib/Transformer/DiscordJs.ts b/packages/tagscript/src/lib/Transformer/DiscordJs.ts deleted file mode 100644 index 4216eb4c..00000000 --- a/packages/tagscript/src/lib/Transformer/DiscordJs.ts +++ /dev/null @@ -1,259 +0,0 @@ -import type { ITransformer } from '../interfaces'; -import type { GuildTextBasedChannel, Role, User, GuildMember, Guild } from 'discord.js'; -import type { Lexer } from '../Interpreter'; - -export type outputResolvable = string | number | boolean | null | undefined; - -export interface SafeValues { - [key: string]: outputResolvable | ((base: T) => outputResolvable); -} - -/** - * Transformer for Discord.js objects. - * > These objects will be removed from this package and will be added in a new package. - * - * @abstract - */ -export abstract class DiscordJsBaseTransformer implements ITransformer { - protected base: T; - protected safeValues: SafeValues = {}; - - public constructor(base: T, safeValues: SafeValues = {}) { - this.base = base; - this.safeValues.id = this.base.id; - this.safeValues.mention = base.toString(); - this.safeValues.name = 'name' in base ? base.name : ''; - this.updateSafeValues(); - this.safeValues = { ...this.safeValues, ...safeValues }; - } - - public transform(tag: Lexer) { - if (!tag.parameter) return this.safeValues.mention as string; - let value = this.safeValues[tag.parameter]; - - if (typeof value === 'function') value = value(this.base); - if (value === undefined) return null; - return `${value ?? ''}`; - } - - protected updateSafeValues() { - // - } -} - -/** - * Transformer for {@link User} - * - * @properties - * ``` - * id: Gives user id. - * mention: Mentions the user. - * username: Gives username of the user. - * discriminator: Gives discriminator of the user - * tag: Gives username#discriminator - * avatar: Gives user's custom avatar if they have one. Else it'll be an empty string. - * displayAvatar: Gives user's avatar URL if they have one else gives user's default avatar. - * createdAt: Gives user's account create date. - * createdTimestamp: Gives user's account created date in ms - * bot: Gives true if the user is a bot else false. - * ``` - */ -export class UserTransformer extends DiscordJsBaseTransformer { - protected override updateSafeValues() { - this.safeValues.username = this.base.username; - this.safeValues.discriminator = this.base.discriminator; - this.safeValues.tag = this.base.tag; - this.safeValues.avatar = this.base.avatarURL(); - this.safeValues.displayAvatar = this.base.displayAvatarURL(); - this.safeValues.createdAt = this.base.createdAt.toISOString(); - this.safeValues.createdTimestamp = this.base.createdTimestamp; - this.safeValues.bot = this.base.bot; - } -} - -/** - * Transformer for {@link GuildMember}. - * - * @properties - * ``` - * id: Gives member id. - * mention: Mentions the member. - * username: Gives username of the member. - * discriminator: Gives discriminator of the member - * tag: Gives username#discriminator - * avatar: Gives member's custom avatar if they have one. Else it'll be an empty string. - * displayAvatar: Gives member's avatar URL if they have one else gives member's default avatar. - * nickname: Gives member's nickname. - * displayName: Gives member's display name. (nickname if they have one else username) - * joinedAt: Gives member's join date. - * joinedTimestamp: Gives member's join date in ms - * createdAt: Gives member's account create date. - * createdTimestamp: Gives member's account created date in ms - * bot: Gives true if the member is a bot else false. - * color: Gives member's highest role color. - * position: Gives member's highest role position. - * roles: Gives member's roles. - * roleIds: Gives member's roles ids. - * roleNames: Gives member's roles names. - * topRole: Gives member's highest role name. - * timeoutUntil: Gives member's timeout until date. - * timeoutUntilTimestamp: Gives member's timeout until date in ms. - * ``` - */ -export class MemberTransformer extends DiscordJsBaseTransformer { - protected override updateSafeValues() { - this.safeValues.username = this.base.user.username; - this.safeValues.discriminator = this.base.user.discriminator; - this.safeValues.tag = this.base.user.tag; - this.safeValues.avatar = this.base.avatarURL(); - this.safeValues.displayAvatar = this.base.displayAvatarURL(); - this.safeValues.nickname = this.base.nickname; - this.safeValues.displayName = this.base.displayName; - this.safeValues.joinedAt = this.base.joinedAt?.toISOString() ?? ''; - this.safeValues.joinedTimestamp = this.base.joinedTimestamp; - this.safeValues.createdAt = this.base.user.createdAt.toISOString(); - this.safeValues.createdTimestamp = this.base.user.createdTimestamp; - this.safeValues.bot = this.base.user.bot; - this.safeValues.color = this.base.roles.color?.hexColor ?? ''; - this.safeValues.position = this.base.roles.highest.position; - this.safeValues.roles = this.base.roles.cache.map((role) => role).join(' ') || '`None`'; - this.safeValues.roleIds = this.base.roles.cache.map((role) => role.id).join(', ') || '`None`'; - this.safeValues.roleNames = this.base.roles.cache.map((role) => role.name).join(', ') || '`None`'; - this.safeValues.topRole = this.base.roles.highest.name; - this.safeValues.timeoutUntil = this.base.communicationDisabledUntil?.toISOString() ?? ''; - this.safeValues.timeoutUntilTimestamp = this.base.communicationDisabledUntilTimestamp; - } -} - -/** - * Transformer for Discord {@link GuildTextBasedChannel} - * - * @properties - * ``` - * id: Gives channel id. - * mention: Mentions the channel. - * name: Gives channel name. - * topic: Gives channel topic. - * type: Gives channel type. - * position: Gives channel position. - * nsfw: Gives true if the channel is nsfw else false. - * parentId: Gives channel parent id. - * parentName: Gives channel parent name. - * parentType: Gives channel parent type. - * parentPosition: Gives channel parent position. - * createdAt: Gives channel create date. - * createdTimestamp: Gives channel create date in ms. - * slowmode: Gives channel slowmode. - */ -export class ChannelTransformer extends DiscordJsBaseTransformer { - protected override updateSafeValues() { - this.safeValues.topic = 'topic' in this.base ? this.base.topic : ''; - this.safeValues.type = this.base.type; - this.safeValues.position = 'position' in this.base ? this.base.position : 0; - this.safeValues.nsfw = 'nsfw' in this.base ? this.base.nsfw : this.base.parent?.nsfw ?? false; - this.safeValues.parentId = this.base.parentId; - this.safeValues.parentName = this.base.parent?.name ?? ''; - this.safeValues.parentType = this.base.parent?.type ?? ''; - this.safeValues.parentPosition = this.base.parent?.position ?? 0; - this.safeValues.createdAt = this.base.createdAt.toISOString(); - this.safeValues.createdTimestamp = this.base.createdTimestamp; - this.safeValues.slowmode = 'rateLimitPerUser' in this.base ? this.base.rateLimitPerUser : 0; - } -} - -/** - * Transformer for Discord {@link Guild} - * - * @properties - * ``` - * id: Gives guild id. - * name: Gives guild name. - * description: Gives guild description. - * icon: Gives guild icon. - * splash: Gives guild splash. - * banner: Gives guild banner. - * features: Gives guild features. - * ownerId: Gives guild owner id. - * createdAt: Gives guild create date. - * createdTimestamp: Gives guild create date in ms. - * large: Gives true if the guild is large else false. - * memberCount: Gives guild member count. - * random: Gives random guild member. - * roles: Gives guild roles. - * roleIds: Gives guild roles ids. - * roleNames: Gives guild roles names. - * roleCount: Gives guild roles count. - * channels: Gives guild channels. - * channelIds: Gives guild channels ids. - * channelNames: Gives guild channels names. - * channelCount: Gives guild channels count. - * emojiCount: Gives guild emojis count. (These values depends on cache so it might be inaccurate) - * stickerCount: Gives guild stickers count. (These values depends on cache so it might be inaccurate) - * bots: Gives guild bots count. (These values depends on cache so it might be inaccurate) - * humans: Gives guild humans count. (These values depends on cache so it might be inaccurate) - * afkTimeout: Gives guild afk timeout. - * afkChannel: Gives guild afk channel. - * verificationLevel: Gives guild verification level. - * ``` - */ -export class GuildTransformer extends DiscordJsBaseTransformer { - protected override updateSafeValues() { - this.safeValues.description = this.base.description; - this.safeValues.icon = this.base.iconURL(); - this.safeValues.splash = this.base.splashURL(); - this.safeValues.banner = this.base.bannerURL(); - this.safeValues.features = this.base.features.join(' ') || '`None`'; - this.safeValues.ownerId = this.base.ownerId; - this.safeValues.createdAt = this.base.createdAt.toISOString(); - this.safeValues.createdTimestamp = this.base.createdTimestamp; - this.safeValues.large = this.base.large; - this.safeValues.memberCount = this.base.memberCount; - this.safeValues.random = this.base.members.cache.random()?.toString() ?? ''; - this.safeValues.roles = this.base.roles.cache.map((role) => role).join(' ') || '`None`'; - this.safeValues.roleIds = this.base.roles.cache.map((role) => role.id).join(', ') || '`None`'; - this.safeValues.roleNames = this.base.roles.cache.map((role) => role.name).join(', ') || '`None`'; - this.safeValues.roleCount = this.base.roles.cache.size; - this.safeValues.channels = this.base.channels.cache.map((channel) => channel).join(' ') || '`None`'; - this.safeValues.channelIds = this.base.channels.cache.map((channel) => channel.id).join(', ') || '`None`'; - this.safeValues.channelNames = this.base.channels.cache.map((channel) => channel.name).join(', ') || '`None`'; - this.safeValues.channelCount = this.base.channels.cache.size; - this.safeValues.emojiCount = this.base.emojis.cache.size; - this.safeValues.stickerCount = this.base.stickers.cache.size; - this.safeValues.bots = this.base.members.cache.filter((m) => m.user.bot).size; - this.safeValues.humans = this.base.members.cache.filter((m) => !m.user.bot).size; - this.safeValues.afkTimeout = this.base.afkTimeout; - this.safeValues.afkChannel = `${this.base.afkChannel}`; - this.safeValues.verificationLevel = this.base.verificationLevel; - } -} - -/** - * Transformer for Discord {@link Role} - * - * @properties - * ``` - * id: Gives role id. - * name: Gives role name. - * mention: Mentions the role. - * color: Gives role color. - * hoist: Gives true if the role is hoisted else false. - * mentionable: Gives true if the role is mentionable else false. - * position: Gives role position. - * permissions: Gives role permissions. - * createdAt: Gives role create date. - * createdTimestamp: Gives role create date in ms. - * memberCount: Gives role member count. - * ``` - */ -export class RoleTransformer extends DiscordJsBaseTransformer { - protected override updateSafeValues() { - this.safeValues.color = this.base.color.toString(); - this.safeValues.hoist = this.base.hoist; - this.safeValues.mentionable = this.base.mentionable; - this.safeValues.position = this.base.position; - this.safeValues.permissions = this.base.permissions.toArray().join(', '); - this.safeValues.createdAt = this.base.createdAt.toISOString(); - this.safeValues.createdTimestamp = this.base.createdTimestamp; - this.safeValues.memberCount = this.base.members.size; - } -} diff --git a/packages/tagscript/src/lib/Transformer/index.ts b/packages/tagscript/src/lib/Transformer/index.ts index cc2dad10..89205b85 100644 --- a/packages/tagscript/src/lib/Transformer/index.ts +++ b/packages/tagscript/src/lib/Transformer/index.ts @@ -1,4 +1,3 @@ -export * from './DiscordJs'; export * from './Function'; export * from './Integer'; export * from './Object'; diff --git a/packages/tagscript/tests/Parsers/Format.test.ts b/packages/tagscript/tests/Parsers/Format.test.ts index c6de6f77..3e2fc2e9 100644 --- a/packages/tagscript/tests/Parsers/Format.test.ts +++ b/packages/tagscript/tests/Parsers/Format.test.ts @@ -14,6 +14,9 @@ describe('FormatParser', () => { const text4 = '{escape:Hello| Parbez!}'; expect(await ts.run(text4)).toStrictEqual(new Response().setValues('Hello\\| Parbez!', text4)); + + const text5 = '{anything:Hello| Parbez!}'; + expect(await ts.run(text5)).toStrictEqual(new Response().setValues('{anything:Hello| Parbez!}', text5)); }); }); diff --git a/packages/tagscript/tests/Utils/Util.test.ts b/packages/tagscript/tests/Utils/Util.test.ts index 281d7615..b2feda2f 100644 --- a/packages/tagscript/tests/Utils/Util.test.ts +++ b/packages/tagscript/tests/Utils/Util.test.ts @@ -1,4 +1,4 @@ -import { asyncFilter, escapeContent, implicitBool, parseIf } from '../../src'; +import { asyncFilter, escapeContent, implicitBool, parseIf, split } from '../../src'; describe('asyncFilter', () => { test('GIVEN async tasks in AsyncFilter THEN filter out all Promise', async () => { @@ -91,3 +91,40 @@ describe('implicitBool', () => { expect(result).toStrictEqual(null); }); }); + +describe('split', () => { + test('GIVEN string THEN return array of strings', () => { + const result = split('a,b,c', true); + expect(result).toStrictEqual(['a', 'b', 'c']); + }); + + test('GIVEN string THEN return array of strings', () => { + const result = split('a~b', true); + expect(result).toStrictEqual(['a', 'b']); + }); + + test('GIVEN string THEN return array of strings', () => { + const result = split('a,b,c'); + expect(result).toStrictEqual(['a,b,c']); + }); + + test('GIVEN string THEN return array of strings', () => { + const result = split('a,b,c', false); + expect(result).toStrictEqual(['a,b,c']); + }); + + test('GIVEN string THEN return array of strings', () => { + const result = split('a~c', false); + expect(result).toStrictEqual(['a~c']); + }); + + test('GIVEN string THEN return array of strings', () => { + const result = split('a|b|c', true); + expect(result).toStrictEqual(['a', 'b', 'c']); + }); + + test('GIVEN string THEN return array of strings', () => { + const result = split('a|b\\|c'); + expect(result).toStrictEqual(['a', 'b\\|c']); + }); +}); diff --git a/scripts/clean-full.mjs b/scripts/clean-full.mjs index 3f9e175c..d59a4eaf 100644 --- a/scripts/clean-full.mjs +++ b/scripts/clean-full.mjs @@ -10,9 +10,11 @@ const paths = [ // Nested node_modules folders new URL('tagscript/node_modules/', packagesDir), + new URL('tagscript-plugin-discord/node_modules/', packagesDir), // Dist folders - new URL('tagscript/dist/', packagesDir) + new URL('tagscript/dist/', packagesDir), + new URL('tagscript-plugin-discord/dist/', packagesDir) ]; await Promise.all(paths.map((path) => rm(path, options))); diff --git a/scripts/clean.mjs b/scripts/clean.mjs index 1a71fe2d..bd74fadc 100644 --- a/scripts/clean.mjs +++ b/scripts/clean.mjs @@ -7,9 +7,11 @@ const options = { recursive: true, force: true }; const paths = [ // Dist folders new URL('tagscript/dist/', packagesDir), + new URL('tagscript-plugin-discord/dist/', packagesDir), // Turbo folders - new URL('tagscript/.turbo/', packagesDir) + new URL('tagscript/.turbo/', packagesDir), + new URL('tagscript-plugin-discord/.turbo/', packagesDir) ]; await Promise.all(paths.map((path) => rm(path, options))); diff --git a/typedoc.json b/typedoc.json index 03eea898..6b8bf542 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,8 +1,8 @@ { "cleanOutputDir": true, "entryPointStrategy": "resolve", - "entryPoints": ["packages/tagscript/src/index.ts"], - "excludeExternals": false, + "entryPoints": ["packages/tagscript/src/index.ts", "packages/tagscript-plugin-discord/src/index.ts"], + "excludeExternals": true, "hideGenerator": true, "lightHighlightTheme": "github-light", "darkHighlightTheme": "github-dark", diff --git a/yarn.lock b/yarn.lock index 9bcf1ee5..6dc466dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1159,6 +1159,32 @@ __metadata: languageName: node linkType: hard +"@knodes/typedoc-plugin-monorepo-readmes@npm:^0.22.5": + version: 0.22.5 + resolution: "@knodes/typedoc-plugin-monorepo-readmes@npm:0.22.5" + dependencies: + "@knodes/typedoc-pluginutils": ~0.22.5 + find-up: ^4.1.0 + peerDependencies: + lodash: ^4.17.0 + typedoc: ^0.22.0 + checksum: 0eec6e5f22c7d31d68a6ccc9f597a4753a6e68f2adf73d214cb7697e12ac0afa5337aa35aef6e676adcc0cf1dec724c138eb0a975bcd6c18f762b742482fc713 + languageName: node + linkType: hard + +"@knodes/typedoc-pluginutils@npm:~0.22.5": + version: 0.22.5 + resolution: "@knodes/typedoc-pluginutils@npm:0.22.5" + dependencies: + pkg-up: ^3.1.0 + semver: ^7.3.5 + peerDependencies: + lodash: ^4.17.0 + typedoc: ^0.22.0 + checksum: 1126021c133be30f6aa36b5e7a1b9c2c1551768cdb51d8a34c1faed8bfddaaf2f30e5a3cad0e56df45aa3ae105c09f89b8e28f8a39d47a7d8414770b0f1999e7 + languageName: node + linkType: hard + "@nodelib/fs.scandir@npm:2.1.5": version: 2.1.5 resolution: "@nodelib/fs.scandir@npm:2.1.5" @@ -3687,6 +3713,15 @@ __metadata: languageName: node linkType: hard +"find-up@npm:^3.0.0": + version: 3.0.0 + resolution: "find-up@npm:3.0.0" + dependencies: + locate-path: ^3.0.0 + checksum: 38eba3fe7a66e4bc7f0f5a1366dc25508b7cfc349f852640e3678d26ad9a6d7e2c43eff0a472287de4a9753ef58f066a0ea892a256fa3636ad51b3fe1e17fae9 + languageName: node + linkType: hard + "find-up@npm:^4.0.0, find-up@npm:^4.1.0": version: 4.1.0 resolution: "find-up@npm:4.1.0" @@ -5138,6 +5173,16 @@ __metadata: languageName: node linkType: hard +"locate-path@npm:^3.0.0": + version: 3.0.0 + resolution: "locate-path@npm:3.0.0" + dependencies: + p-locate: ^3.0.0 + path-exists: ^3.0.0 + checksum: 53db3996672f21f8b0bf2a2c645ae2c13ffdae1eeecfcd399a583bce8516c0b88dcb4222ca6efbbbeb6949df7e46860895be2c02e8d3219abd373ace3bfb4e11 + languageName: node + linkType: hard + "locate-path@npm:^5.0.0": version: 5.0.0 resolution: "locate-path@npm:5.0.0" @@ -5808,7 +5853,7 @@ __metadata: languageName: node linkType: hard -"p-limit@npm:^2.2.0": +"p-limit@npm:^2.0.0, p-limit@npm:^2.2.0": version: 2.3.0 resolution: "p-limit@npm:2.3.0" dependencies: @@ -5835,6 +5880,15 @@ __metadata: languageName: node linkType: hard +"p-locate@npm:^3.0.0": + version: 3.0.0 + resolution: "p-locate@npm:3.0.0" + dependencies: + p-limit: ^2.0.0 + checksum: 83991734a9854a05fe9dbb29f707ea8a0599391f52daac32b86f08e21415e857ffa60f0e120bfe7ce0cc4faf9274a50239c7895fc0d0579d08411e513b83a4ae + languageName: node + linkType: hard + "p-locate@npm:^4.1.0": version: 4.1.0 resolution: "p-locate@npm:4.1.0" @@ -6011,6 +6065,15 @@ __metadata: languageName: node linkType: hard +"pkg-up@npm:^3.1.0": + version: 3.1.0 + resolution: "pkg-up@npm:3.1.0" + dependencies: + find-up: ^3.0.0 + checksum: 5bac346b7c7c903613c057ae3ab722f320716199d753f4a7d053d38f2b5955460f3e6ab73b4762c62fd3e947f58e04f1343e92089e7bb6091c90877406fcd8c8 + languageName: node + linkType: hard + "postcss-load-config@npm:^3.0.1": version: 3.1.3 resolution: "postcss-load-config@npm:3.1.3" @@ -6427,6 +6490,7 @@ __metadata: "@favware/cliff-jumper": ^1.4.0 "@favware/npm-deprecate": ^1.0.4 "@favware/rollup-type-bundler": ^1.0.7 + "@knodes/typedoc-plugin-monorepo-readmes": ^0.22.5 "@sapphire/eslint-config": ^4.3.4 "@sapphire/prettier-config": ^1.4.3 "@types/jest": ^27.4.1 @@ -6445,6 +6509,8 @@ __metadata: tsup: ^5.12.6 turbo: ^1.2.6 typedoc: ^0.22.15 + typedoc-monorepo-link-types: ^0.0.2 + typedoc-plugin-djs-links: ^1.0.4 typescript: ^4.6.4 languageName: unknown linkType: soft @@ -6949,11 +7015,24 @@ __metadata: languageName: node linkType: hard -"tagscript@workspace:packages/tagscript": +"tagscript-plugin-discord@workspace:packages/tagscript-plugin-discord": version: 0.0.0-use.local - resolution: "tagscript@workspace:packages/tagscript" + resolution: "tagscript-plugin-discord@workspace:packages/tagscript-plugin-discord" dependencies: discord.js: ^13.6.0 + tagscript: "workspace:^" + tsup: ^5.12.6 + typescript: ^4.6.4 + peerDependencies: + discord.js: ^13.6.0 + tagscript: "workspace:^" + languageName: unknown + linkType: soft + +"tagscript@workspace:^, tagscript@workspace:packages/tagscript": + version: 0.0.0-use.local + resolution: "tagscript@workspace:packages/tagscript" + dependencies: tsup: ^5.12.6 typescript: ^4.6.4 languageName: unknown @@ -7468,6 +7547,22 @@ __metadata: languageName: node linkType: hard +"typedoc-monorepo-link-types@npm:^0.0.2": + version: 0.0.2 + resolution: "typedoc-monorepo-link-types@npm:0.0.2" + peerDependencies: + typedoc: 0.22.x + checksum: 0159c0da7bea93b14c72a03c9fa2db4de056ff7173f1c75db66f947e01a92a7270825e8c400c3ae3c12562ceef04940e5714143008ab8a3c04b101b46eaae072 + languageName: node + linkType: hard + +"typedoc-plugin-djs-links@npm:^1.0.4": + version: 1.0.4 + resolution: "typedoc-plugin-djs-links@npm:1.0.4" + checksum: 9db409c50400f4b9f15d24dd7b7a32a5672f61bd2840a0533661f42c92fbad0a5496ad898e08acb2a25a9e36a7ebbc698d3a36e8eb77ad5f471628d13f496d8d + languageName: node + linkType: hard + "typedoc@npm:^0.22.15": version: 0.22.15 resolution: "typedoc@npm:0.22.15"