Skip to content

Commit

Permalink
feat!: move all discord.js related parsers into a new package (#22)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
imranbarbhuiya committed May 6, 2022
1 parent 8d5c6c0 commit f7e27fa
Show file tree
Hide file tree
Showing 58 changed files with 918 additions and 356 deletions.
2 changes: 1 addition & 1 deletion .all-contributorsrc
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion .eslintrc.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/auto-deprecate.yml
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/continuous-delivery.yml
Expand Up @@ -54,4 +54,4 @@ jobs:
popd
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/deprecate-on-merge.yml
Expand Up @@ -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 }}
1 change: 1 addition & 0 deletions .npm-deprecaterc.yml
Expand Up @@ -2,3 +2,4 @@ name: '*next*'
verbose: true
package:
- 'tagscript'
- 'tagscript-plugin-discord'
2 changes: 1 addition & 1 deletion .vscode/settings.json
Expand Up @@ -6,5 +6,5 @@
"editor.detectIndentation": false,
"files.eol": "\n",
"typescript.tsdk": "node_modules\\typescript\\lib",
"cSpell.words": ["tagscript"]
"cSpell.words": ["cooldown", "tagscript"]
}
7 changes: 0 additions & 7 deletions README.md
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions packages/tagscript-plugin-discord/.cliff-jumperrc.yml
@@ -0,0 +1,2 @@
name: tagscript-plugin-discord
packagePath: packages/tagscript-plugin-discord
21 changes: 21 additions & 0 deletions packages/tagscript-plugin-discord/LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Parbez <imranbarbhuiya.fsd@gmail.com>

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.
74 changes: 74 additions & 0 deletions packages/tagscript-plugin-discord/README.md
@@ -0,0 +1,74 @@
<div align="center">

# 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)

</div>

## 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!

<a href="https://www.buymeacoffee.com/parbez" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
<a href='https://ko-fi.com/Y8Y1CBIJH' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi4.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="https://github.com/imranbarbhuiya/TagScript/commits?author=imranbarbhuiya" title="Code">💻</a> <a href="#maintenance-imranbarbhuiya" title="Maintenance">🚧</a> <a href="#ideas-imranbarbhuiya" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://renovate.whitesourcesoftware.com"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">🚧</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
60 changes: 60 additions & 0 deletions 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"
14 changes: 14 additions & 0 deletions 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: ['<rootDir>/tests/**/*.test.ts'],
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tests/tsconfig.json'
}
}
};

export default config;
65 changes: 65 additions & 0 deletions 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/"
}
1 change: 1 addition & 0 deletions packages/tagscript-plugin-discord/src/index.ts
@@ -0,0 +1 @@
export * from './lib';
@@ -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
Expand Down
@@ -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.
Expand Down
@@ -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.
Expand Down
@@ -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.
Expand Down
23 changes: 23 additions & 0 deletions 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 `<t:${payload}:${parameter}>`;
}
}
@@ -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.
Expand Down
6 changes: 6 additions & 0 deletions 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';

0 comments on commit f7e27fa

Please sign in to comment.