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.
- Loading branch information
1 parent
6b44920
commit f616c5c
Showing
6 changed files
with
59 additions
and
10 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/tagscript-plugin-discord/src/lib/Parsers/Files.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,15 @@ | ||
import { BaseParser, Context, IParser, split } from 'tagscript'; | ||
|
||
/** | ||
* This parser allows sending files along with message using file url. | ||
*/ | ||
export class FilesParser extends BaseParser implements IParser { | ||
public constructor() { | ||
super(['files'], false, true); | ||
} | ||
|
||
public parse(ctx: Context) { | ||
ctx.response.actions.files = split(ctx.tag.payload!, true); | ||
return ''; | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
packages/tagscript-plugin-discord/src/lib/interfaces/index.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,15 @@ | ||
import { MessageEmbedOptions } from 'discord.js'; | ||
import 'tagscript'; | ||
|
||
declare module 'tagscript' { | ||
export interface IActions { | ||
cooldown?: { | ||
cooldown: number; | ||
message: string | null; | ||
}; | ||
embed?: MessageEmbedOptions; | ||
deleteMessage?: boolean; | ||
silentResponse?: boolean; | ||
files?: string[]; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/tagscript-plugin-discord/tests/Parsers/Files.test.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,11 @@ | ||
import { Interpreter } from 'tagscript'; | ||
import { FilesParser } from '../../src'; | ||
|
||
describe('Files', () => { | ||
test('GIVEN file url WHEN parse THEN return empty string and url in actions', async () => { | ||
const ts = new Interpreter(new FilesParser()); | ||
const text = '{files:https://example.com/file.txt,https://example.com/file2.txt}'; | ||
|
||
expect((await ts.run(text)).actions.files).toStrictEqual(['https://example.com/file.txt', 'https://example.com/file2.txt']); | ||
}); | ||
}); |
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,15 @@ | ||
import { MessageEmbedOptions } from 'discord.js'; | ||
import 'tagscript'; | ||
|
||
declare module 'tagscript' { | ||
export interface IActions { | ||
cooldown?: { | ||
cooldown: number; | ||
message: string | null; | ||
}; | ||
embed?: MessageEmbedOptions; | ||
deleteMessage?: boolean; | ||
silentResponse?: boolean; | ||
files?: string[]; | ||
} | ||
} |
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