This repository was archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
BREAKING!: feat @cordis/util #32
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
210845a
chore: init @cordis/util
70b6ac4
init makeRestUtils func
2302ecf
update pnpm-lock.yaml
3a21e28
bump version and remove wrong license
a4ce6bf
chore: init @cordis/util
75aea1c
init makeRestUtils func
8694649
update pnpm-lock.yaml
bbf16ef
bump version and remove wrong license
1f3285d
Merge branch 'feat/cordis/util' of https://github.com/cordis-lib/cord…
2353a7f
update pnpm-lock.yaml
48e7843
integrate requested changes
fc06ca7
Merge branch 'main' into feat/cordis/util
e3af4e9
move makeDiscordCdnUrl to @cordis/util
e257752
Merge branch 'main' into feat/cordis/util
df97176
Merge branch 'main' of https://github.com/cordis-lib/cordis into feat…
d5c3d80
tests: remove describe layer
2ef1018
feat: webhook api endpoints
c65176c
feat: audit log endpoints
2813d12
feat: invite routes
d285f7f
tests: fix the test
b3a1357
feat: guild emoji endpoints
fa0aa14
merge @cordis/snowflake with @cordis/util
0a7410f
Merge branch 'main' of https://github.com/cordis-lib/cordis into feat…
69a7119
feat: finish user methods and add template methods
8dfde79
fix https://github.com/cordis-lib/cordis/issues/46
587cc0c
feat: channel endpoints
1c6f063
feat: base embed structure
9b4b44f
tests: add base embed tests
ef43075
tests: ignore restutils in tests
5813f16
feat: guild endpoints
6ffa12e
feat: missing webhook endpoints
2b59a38
a bit of clean up
925bf09
Merge remote-tracking branch 'origin/main' into feat/cordis/util
7638f01
fix whatever muckery the last commit did to package.json
4024973
move version field in package.json
f0a28c6
refactor: destructure imports
dbf7032
fix: pnpm-lock file
9f14483
implement dd feedback
7c519e6
feat: embed
cd52757
chore: nitpicks
didinele 5fcbafb
fix(util/embed): handle timestamp properly
didinele 3723cc9
test(embed): update test to latest changes
didinele 5c6c350
tests: improve the embed tests
60d1aed
chore: nitpicks
didinele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
libs/snowflake/src/index.test.ts → libs/util/src/Snowflake.test.ts
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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,80 @@ | ||
| import { buildEmbed } from './embed'; | ||
|
|
||
| test('Dataless value checks', () => { | ||
| const embed1 = buildEmbed({}); | ||
| expect(embed1.author).toBe(undefined); | ||
| expect(embed1.color).toBe(undefined); | ||
| expect(embed1.description).toBe(undefined); | ||
| expect(embed1.footer).toBe(undefined); | ||
| expect(embed1.fields).toStrictEqual([]); | ||
| expect(embed1.image).toBe(undefined); | ||
| expect(embed1.provider).toBe(undefined); | ||
| expect(embed1.thumbnail).toBe(undefined); | ||
| expect(embed1.timestamp).toBe(undefined); | ||
| expect(embed1.title).toBe(undefined); | ||
| expect(embed1.author).toBe(undefined); | ||
| expect(embed1.url).toBe(undefined); | ||
| expect(embed1.video).toBe(undefined); | ||
| }); | ||
|
|
||
| test('Data value checks', () => { | ||
| const date = new Date('2021-03-08T14:40:27.875Z'); | ||
| const color = 16753920; | ||
|
|
||
| let embed2 = buildEmbed({ | ||
| title: 'testing title!', | ||
| description: 'testing description', | ||
| url: 'https://google.com', | ||
| color, | ||
| fields: [], | ||
| thumbnail: { | ||
| url: 'https://google.com' | ||
| }, | ||
| image: { | ||
| url: 'https://lh3.googleusercontent.com/proxy/K6J0xWzyfl729xgnZLj55qd5L0us_QN7m5MbcQgV09xP-HVw8Z_iJDwpXexcy87ZkHHrins6rMFwPahgPI-VI_il_gedMlBD7IIll_0e4AZNBg' | ||
| }, | ||
| author: { | ||
| name: 'Test Author' | ||
| }, | ||
| footer: { | ||
| text: 'Test Footer' | ||
| } | ||
| }).setTimestamp(date.getTime()); | ||
|
|
||
| expect(embed2.timestamp).toBe(date.toString()); | ||
| expect(embed2.color).toBe(color); | ||
| expect(embed2.fields).toStrictEqual([]); | ||
|
|
||
| embed2 = embed2 | ||
| .setAuthor('testing_author_3') | ||
| .setColor(16753920) | ||
| .setDescription('I am testing changing descriptions') | ||
| .setFooter('bing bong', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ') | ||
| .setImage('https://static.wikia.nocookie.net/youtubepoop/images/2/2a/Rick_Ashley.png/revision/latest/scale-to-width-down/340?cb=20130102175058') | ||
| .setThumbnail('https://static.wikia.nocookie.net/youtubepoop/images/2/2a/Rick_Ashley.png/revision/latest/scale-to-width-down/340?cb=20130102175058') | ||
| .setTitle('Never gonna give you up') | ||
| .setURL('http://yahoo.com') | ||
| .addFields({ name: 'never gonna', value: 'let you down', inline: true }, { name: 'never gonna run around and', value: 'desert you' }); | ||
|
|
||
| expect(embed2.toJSON()).toMatchObject({ | ||
| title: 'Never gonna give you up', | ||
| description: 'I am testing changing descriptions', | ||
| url: 'http://yahoo.com', | ||
| color: 16753920, | ||
| fields: [{ name: 'never gonna', value: 'let you down', inline: true }, { name: 'never gonna run around and', value: 'desert you' }], | ||
| thumbnail: { | ||
| url: 'https://static.wikia.nocookie.net/youtubepoop/images/2/2a/Rick_Ashley.png/revision/latest/scale-to-width-down/340?cb=20130102175058' | ||
| }, | ||
| image: { | ||
| url: 'https://static.wikia.nocookie.net/youtubepoop/images/2/2a/Rick_Ashley.png/revision/latest/scale-to-width-down/340?cb=20130102175058' | ||
| }, | ||
| author: { | ||
| name: 'testing_author_3' | ||
| }, | ||
| type: 'rich', | ||
| footer: { | ||
| text: 'bing bong', | ||
| icon_url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or 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,43 @@ | ||
| import { APIEmbed, APIEmbedField, EmbedType } from 'discord-api-types/v8'; | ||
|
|
||
| export const buildEmbed = (embedData: Partial<APIEmbed> = {}) => { | ||
| embedData.fields ??= []; | ||
| embedData.type = EmbedType.Rich; | ||
|
|
||
| return { | ||
| ...Object.freeze(embedData), | ||
| toJSON: () => embedData, | ||
|
|
||
| setAuthor(name: string, url?: string, icon_url?: string, proxy_icon_url?: string) { | ||
| return buildEmbed({ ...this, author: { name, url, icon_url, proxy_icon_url } }); | ||
| }, | ||
| setColor(color: number) { | ||
| return buildEmbed({ ...this, color }); | ||
| }, | ||
| setDescription(description: string) { | ||
| return buildEmbed({ ...this, description }); | ||
| }, | ||
| setFooter(text: string, icon_url?: string, proxy_icon_url?: string) { | ||
| return buildEmbed({ ...this, footer: { text, icon_url, proxy_icon_url } }); | ||
| }, | ||
| setImage(url: string, proxy_url?: string, height?: number, width?: number) { | ||
| return buildEmbed({ ...this, image: { url, proxy_url, height, width } }); | ||
| }, | ||
| setThumbnail(url: string, proxy_url?: string, height?: number, width?: number) { | ||
| return buildEmbed({ ...this, thumbnail: { url, proxy_url, height, width } }); | ||
| }, | ||
| setTitle(title: string) { | ||
| return buildEmbed({ ...this, title }); | ||
| }, | ||
| setURL(url: string) { | ||
| return buildEmbed({ ...this, url }); | ||
| }, | ||
| setTimestamp(timestamp: Date | number = new Date()) { | ||
| if (typeof timestamp === 'number') timestamp = new Date(timestamp); | ||
| return buildEmbed({ ...this, timestamp: timestamp.toString() }); | ||
| }, | ||
| addFields(...data: APIEmbedField[]) { | ||
| return buildEmbed({ ...this, fields: embedData.fields?.concat(data) ?? data }); | ||
| } | ||
| }; | ||
| }; |
File renamed without changes.
This file contains hidden or 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,4 @@ | ||
| export * from './embed'; | ||
| export * from './makeDiscordCdnUrl'; | ||
| export * from './restUtils'; | ||
| export * from './Snowflake'; |
This file contains hidden or 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,36 @@ | ||
| import { makeDiscordCdnUrl } from './'; | ||
| import { CordisUtilTypeError, CordisUtilRangeError } from './error'; | ||
|
|
||
| describe('invalid options handling', () => { | ||
| test('invalid format', () => { | ||
| const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; | ||
| // @ts-expect-error Intentionally invalid format | ||
| expect(() => makeDiscordCdnUrl(root, { format: 'asdf' })).toThrow(CordisUtilTypeError); | ||
| }); | ||
|
|
||
| test('invalid size', () => { | ||
| const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; | ||
| // @ts-expect-error Intentionally invalid size | ||
| expect(() => makeDiscordCdnUrl(root, { size: 1 })).toThrow(CordisUtilRangeError); | ||
| }); | ||
| }); | ||
|
|
||
| test('defaults using an image', () => { | ||
| const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; | ||
| expect(makeDiscordCdnUrl(root)).toBe(`${root}.webp`); | ||
| }); | ||
|
|
||
| test('defaults using a gif', () => { | ||
| const root = 'a_bbab2f9b0bcecf438b4810c67798bfca'; | ||
| expect(makeDiscordCdnUrl(root)).toBe(`${root}.gif`); | ||
| }); | ||
|
|
||
| test('non-dynamic with a gif', () => { | ||
| const root = 'a_bbab2f9b0bcecf438b4810c67798bfca'; | ||
| expect(makeDiscordCdnUrl(root, { dynamic: false })).toBe(`${root}.webp`); | ||
| }); | ||
|
|
||
| test('valid custom size', () => { | ||
| const root = 'e16be7c509d54bb53b1ee21fe8d8cdac'; | ||
| expect(makeDiscordCdnUrl(root, { size: 16 })).toBe(`${root}.webp?size=16`); | ||
| }); |
2 changes: 1 addition & 1 deletion
2
...common/src/functions/makeDiscordCdnUrl.ts → libs/util/src/makeDiscordCdnUrl.ts
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.