Skip to content

Commit

Permalink
fix(DataResolver): fix circular dependency error with GuildTemplate (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cherryblossom000 authored May 22, 2021
1 parent 14c6802 commit b376f31
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/util/DataResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const path = require('path');
const stream = require('stream');
const fetch = require('node-fetch');
const { Error: DiscordError, TypeError } = require('../errors');
const GuildTemplate = require('../structures/GuildTemplate');
const Invite = require('../structures/Invite');

/**
Expand Down Expand Up @@ -56,6 +55,7 @@ class DataResolver {
* @returns {string}
*/
static resolveGuildTemplateCode(data) {
const GuildTemplate = require('../structures/GuildTemplate');
return this.resolveCode(data, GuildTemplate.GUILD_TEMPLATES_PATTERN);
}

Expand Down
3 changes: 2 additions & 1 deletion test/escapeMarkdown.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

/* eslint-disable max-len, no-undef */
/* eslint-env jest */
/* eslint-disable max-len */

const Util = require('../src/util/Util');
const testString = "`_Behold!_`\n||___~~***```js\n`use strict`;\nrequire('discord.js');```***~~___||";
Expand Down
11 changes: 11 additions & 0 deletions test/resolveGuildTemplateCode.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

/* eslint-env jest */

const { DataResolver } = require('../src');

describe('resolveGuildTemplateCode', () => {
test('basic', () => {
expect(DataResolver.resolveGuildTemplateCode('https://discord.new/abc')).toBe('abc');
});
});
27 changes: 27 additions & 0 deletions test/templateCreateGuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const { token } = require('./auth');
const { Client } = require('../src');

const client = new Client({ intents: ['GUILDS', 'GUILD_MESSAGES'] });
client
.on('ready', () => console.log('ready'))
.on('message', async message => {
try {
const templates = await message.guild.fetchTemplates();
if (!templates.size) {
console.log('no templates');
} else {
const guild = await templates.first().createGuild('guild name');
console.log(`created guild with ID ${guild.id}`);
await guild.delete();
console.log('deleted guild');
}
} catch (error) {
console.error(error);
} finally {
client.destroy();
}
})
.login(token)
.catch(console.error);

0 comments on commit b376f31

Please sign in to comment.