generated from imranbarbhuiya/package-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
8d5c6c0
commit f7e27fa
Showing
58 changed files
with
918 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ name: '*next*' | |
verbose: true | ||
package: | ||
- 'tagscript' | ||
- 'tagscript-plugin-discord' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name: tagscript-plugin-discord | ||
packagePath: packages/tagscript-plugin-discord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib'; |
5 changes: 1 addition & 4 deletions
5
...es/tagscript/src/lib/Parsers/AllowDeny.ts → ...ugin-discord/src/lib/Parsers/AllowDeny.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
...ges/tagscript/src/lib/Parsers/Cooldown.ts → ...lugin-discord/src/lib/Parsers/Cooldown.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
packages/tagscript/src/lib/Parsers/Delete.ts → ...-plugin-discord/src/lib/Parsers/Delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
packages/tagscript/src/lib/Parsers/Embed.ts → ...t-plugin-discord/src/lib/Parsers/Embed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/tagscript-plugin-discord/src/lib/Parsers/Format.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}>`; | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
packages/tagscript/src/lib/Parsers/Silent.ts → ...-plugin-discord/src/lib/Parsers/Silent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from './AllowDeny'; | ||
export * from './Cooldown'; | ||
export * from './Delete'; | ||
export * from './Embed'; | ||
export * from './Format'; | ||
export * from './Silent'; |
Oops, something went wrong.