Skip to content

Commit

Permalink
feat(vanity): Only request vanity url when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Mar 31, 2020
1 parent 059d373 commit b5a7dff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/invites/cache/VanityUrlCache.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Cache } from '../../framework/cache/Cache';
import { GuildFeature } from '../../types';

export class VanityUrlCache extends Cache<string> {
public async init() {
// NO-OP
}

protected async _get(guildId: string): Promise<string> {
const guild = this.client.guilds.get(guildId);
if (!guild || !guild.features.includes(GuildFeature.VANITY_URL)) {
return null;
}

return (
this.client.guilds.get(guildId)?.vanityURL ||
this.client
.getGuildVanity(guildId)
guild.vanityURL ||
guild
.getVanity()
.then((r) => r.code as any)
.catch(() => null)
);
Expand Down
16 changes: 16 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ export enum GuildPermission {
READ_MESSAGE_HISTORY = 'readMessageHistory'
}

export enum GuildFeature {
INVITE_SPLASH = 'INVITE_SPLASH',
VIP_REGIONS = 'VIP_REGIONS',
VANITY_URL = 'VANITY_URL',
VERIFIED = 'VERIFIED',
PARTNERED = 'PARTNERED',
PUBLIC = 'PUBLIC',
COMMERCE = 'COMMERCE',
NEWS = 'NEWS',
DISCOVERABLE = 'DISCOVERABLE',
FEATURABLE = 'FEATURABLE',
ANIMATED_ICON = 'ANIMATED_ICON',
BANNER = 'BANNER',
PUBLIC_DISABLED = 'PUBLIC_DISABLED'
}

export enum PromptResult {
SUCCESS,
FAILURE,
Expand Down

0 comments on commit b5a7dff

Please sign in to comment.