Skip to content

Commit

Permalink
refactor: import timers, process, and Buffer from node: (#7157)
Browse files Browse the repository at this point in the history
Co-authored-by: muchnameless <12682826+muchnameless@users.noreply.github.com>
Co-authored-by: Almeida <almeidx@pm.me>
  • Loading branch information
3 people committed Dec 28, 2021
1 parent d0c3961 commit 3c62bd2
Show file tree
Hide file tree
Showing 46 changed files with 79 additions and 5 deletions.
26 changes: 25 additions & 1 deletion .eslintrc.json
Expand Up @@ -171,6 +171,30 @@
"prefer-template": "error",
"rest-spread-spacing": "error",
"template-curly-spacing": "error",
"yield-star-spacing": "error"
"yield-star-spacing": "error",

"no-restricted-globals": [
"error",
{
"name": "Buffer",
"message": "Import Buffer from `node:buffer` instead"
},
{
"name": "process",
"message": "Import process from `node:process` instead"
},
{
"name": "setTimeout",
"message": "Import setTimeout from `node:timers` instead"
},
{
"name": "setInterval",
"message": "Import setInterval from `node:timers` instead"
},
{
"name": "setImmediate",
"message": "Import setImmediate from `node:timers` instead"
}
]
}
}
1 change: 1 addition & 0 deletions src/WebSocket.js
@@ -1,6 +1,7 @@
'use strict';

let erlpack;
const { Buffer } = require('node:buffer');

try {
erlpack = require('erlpack');
Expand Down
2 changes: 2 additions & 0 deletions src/client/Client.js
@@ -1,5 +1,7 @@
'use strict';

const process = require('node:process');
const { setInterval } = require('node:timers');
const { Collection } = require('@discordjs/collection');
const BaseClient = require('./BaseClient');
const ActionsManager = require('./actions/ActionsManager');
Expand Down
1 change: 1 addition & 0 deletions src/client/actions/GuildDelete.js
@@ -1,5 +1,6 @@
'use strict';

const { setTimeout } = require('node:timers');
const Action = require('./Action');
const { deletedGuilds } = require('../../structures/Guild');
const { Events } = require('../../util/Constants');
Expand Down
1 change: 1 addition & 0 deletions src/client/actions/InteractionCreate.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Action = require('./Action');
const AutocompleteInteraction = require('../../structures/AutocompleteInteraction');
const ButtonInteraction = require('../../structures/ButtonInteraction');
Expand Down
1 change: 1 addition & 0 deletions src/client/actions/MessageCreate.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Action = require('./Action');
const { Events } = require('../../util/Constants');

Expand Down
1 change: 1 addition & 0 deletions src/client/websocket/WebSocketManager.js
@@ -1,6 +1,7 @@
'use strict';

const EventEmitter = require('node:events');
const { setImmediate } = require('node:timers');
const { setTimeout: sleep } = require('node:timers/promises');
const { Collection } = require('@discordjs/collection');
const { RPCErrorCodes } = require('discord-api-types/v9');
Expand Down
1 change: 1 addition & 0 deletions src/client/websocket/WebSocketShard.js
@@ -1,6 +1,7 @@
'use strict';

const EventEmitter = require('node:events');
const { setTimeout, setInterval } = require('node:timers');
const WebSocket = require('../../WebSocket');
const { Status, Events, ShardEvents, Opcodes, WSEvents } = require('../../util/Constants');
const Intents = require('../../util/Intents');
Expand Down
1 change: 1 addition & 0 deletions src/managers/ChannelManager.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const CachedManager = require('./CachedManager');
const { Channel } = require('../structures/Channel');
const { Events, ThreadChannelTypes } = require('../util/Constants');
Expand Down
1 change: 1 addition & 0 deletions src/managers/GuildChannelManager.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { Collection } = require('@discordjs/collection');
const CachedManager = require('./CachedManager');
const ThreadManager = require('./ThreadManager');
Expand Down
2 changes: 2 additions & 0 deletions src/managers/GuildManager.js
@@ -1,5 +1,7 @@
'use strict';

const process = require('node:process');
const { setTimeout } = require('node:timers');
const { Collection } = require('@discordjs/collection');
const CachedManager = require('./CachedManager');
const { Guild } = require('../structures/Guild');
Expand Down
2 changes: 2 additions & 0 deletions src/managers/GuildMemberManager.js
@@ -1,5 +1,7 @@
'use strict';

const { Buffer } = require('node:buffer');
const { setTimeout } = require('node:timers');
const { Collection } = require('@discordjs/collection');
const CachedManager = require('./CachedManager');
const { Error, TypeError, RangeError } = require('../errors');
Expand Down
1 change: 1 addition & 0 deletions src/managers/PermissionOverwriteManager.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { Collection } = require('@discordjs/collection');
const CachedManager = require('./CachedManager');
const { TypeError } = require('../errors');
Expand Down
1 change: 1 addition & 0 deletions src/managers/RoleManager.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { Collection } = require('@discordjs/collection');
const CachedManager = require('./CachedManager');
const { TypeError } = require('../errors');
Expand Down
1 change: 1 addition & 0 deletions src/rest/APIRequest.js
@@ -1,6 +1,7 @@
'use strict';

const https = require('node:https');
const { setTimeout } = require('node:timers');
const FormData = require('form-data');
const fetch = require('node-fetch');
const { UserAgent } = require('../util/Constants');
Expand Down
1 change: 1 addition & 0 deletions src/rest/RESTManager.js
@@ -1,5 +1,6 @@
'use strict';

const { setInterval } = require('node:timers');
const { Collection } = require('@discordjs/collection');
const APIRequest = require('./APIRequest');
const routeBuilder = require('./APIRouter');
Expand Down
1 change: 1 addition & 0 deletions src/rest/RequestHandler.js
@@ -1,5 +1,6 @@
'use strict';

const { setTimeout } = require('node:timers');
const { setTimeout: sleep } = require('node:timers/promises');
const { AsyncQueue } = require('@sapphire/async-queue');
const DiscordAPIError = require('./DiscordAPIError');
Expand Down
2 changes: 2 additions & 0 deletions src/sharding/Shard.js
Expand Up @@ -2,6 +2,8 @@

const EventEmitter = require('node:events');
const path = require('node:path');
const process = require('node:process');
const { setTimeout } = require('node:timers');
const { setTimeout: sleep } = require('node:timers/promises');
const { Error } = require('../errors');
const Util = require('../util/Util');
Expand Down
1 change: 1 addition & 0 deletions src/sharding/ShardClientUtil.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { Error } = require('../errors');
const { Events } = require('../util/Constants');
const Util = require('../util/Util');
Expand Down
1 change: 1 addition & 0 deletions src/sharding/ShardingManager.js
Expand Up @@ -3,6 +3,7 @@
const EventEmitter = require('node:events');
const fs = require('node:fs');
const path = require('node:path');
const process = require('node:process');
const { setTimeout: sleep } = require('node:timers/promises');
const { Collection } = require('@discordjs/collection');
const Shard = require('./Shard');
Expand Down
1 change: 1 addition & 0 deletions src/structures/Channel.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Base = require('./Base');
let CategoryChannel;
let DMChannel;
Expand Down
1 change: 1 addition & 0 deletions src/structures/Emoji.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Base = require('./Base');
const SnowflakeUtil = require('../util/SnowflakeUtil');

Expand Down
1 change: 1 addition & 0 deletions src/structures/Guild.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { Collection } = require('@discordjs/collection');
const AnonymousGuild = require('./AnonymousGuild');
const GuildAuditLogs = require('./GuildAuditLogs');
Expand Down
1 change: 1 addition & 0 deletions src/structures/GuildMember.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Base = require('./Base');
const VoiceState = require('./VoiceState');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
Expand Down
1 change: 1 addition & 0 deletions src/structures/GuildTemplate.js
@@ -1,5 +1,6 @@
'use strict';

const { setTimeout } = require('node:timers');
const Base = require('./Base');
const { Events } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
Expand Down
1 change: 1 addition & 0 deletions src/structures/Message.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { Collection } = require('@discordjs/collection');
const Base = require('./Base');
const BaseMessageComponent = require('./BaseMessageComponent');
Expand Down
1 change: 1 addition & 0 deletions src/structures/MessageEmbed.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { RangeError } = require('../errors');
const Util = require('../util/Util');

Expand Down
1 change: 1 addition & 0 deletions src/structures/MessagePayload.js
@@ -1,5 +1,6 @@
'use strict';

const { Buffer } = require('node:buffer');
const BaseMessageComponent = require('./BaseMessageComponent');
const MessageEmbed = require('./MessageEmbed');
const { RangeError } = require('../errors');
Expand Down
1 change: 1 addition & 0 deletions src/structures/Role.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Base = require('./Base');
const { Error } = require('../errors');
const Permissions = require('../util/Permissions');
Expand Down
1 change: 1 addition & 0 deletions src/structures/StageInstance.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Base = require('./Base');
const { PrivacyLevels } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');
Expand Down
1 change: 1 addition & 0 deletions src/structures/Sticker.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Base = require('./Base');
const { StickerFormatTypes, StickerTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil');
Expand Down
1 change: 1 addition & 0 deletions src/structures/VoiceChannel.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const BaseGuildVoiceChannel = require('./BaseGuildVoiceChannel');
const Permissions = require('../util/Permissions');

Expand Down
1 change: 1 addition & 0 deletions src/structures/Webhook.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const MessagePayload = require('./MessagePayload');
const { Error } = require('../errors');
const { WebhookTypes } = require('../util/Constants');
Expand Down
1 change: 1 addition & 0 deletions src/structures/interfaces/Collector.js
@@ -1,6 +1,7 @@
'use strict';

const EventEmitter = require('node:events');
const { setTimeout } = require('node:timers');
const { Collection } = require('@discordjs/collection');
const { TypeError } = require('../../errors');
const Util = require('../../util/Util');
Expand Down
1 change: 1 addition & 0 deletions src/util/Constants.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const Package = (exports.Package = require('../../package.json'));
const { Error, RangeError, TypeError } = require('../errors');

Expand Down
1 change: 1 addition & 0 deletions src/util/DataResolver.js
@@ -1,5 +1,6 @@
'use strict';

const { Buffer } = require('node:buffer');
const fs = require('node:fs');
const path = require('node:path');
const stream = require('node:stream');
Expand Down
1 change: 1 addition & 0 deletions src/util/LimitedCollection.js
@@ -1,5 +1,6 @@
'use strict';

const { setInterval } = require('node:timers');
const { Collection } = require('@discordjs/collection');
const { _cleanupSymbol } = require('./Constants.js');
const Sweepers = require('./Sweepers.js');
Expand Down
2 changes: 2 additions & 0 deletions src/util/Options.js
@@ -1,5 +1,7 @@
'use strict';

const process = require('node:process');

/**
* Rate limit data
* @typedef {Object} RateLimitData
Expand Down
1 change: 1 addition & 0 deletions src/util/Sweepers.js
@@ -1,5 +1,6 @@
'use strict';

const { setInterval } = require('node:timers');
const { Events, ThreadChannelTypes, SweeperKeys } = require('./Constants');
const { TypeError } = require('../errors/DJSError.js');

Expand Down
1 change: 1 addition & 0 deletions src/util/Util.js
@@ -1,6 +1,7 @@
'use strict';

const { parse } = require('node:path');
const process = require('node:process');
const { Collection } = require('@discordjs/collection');
const fetch = require('node-fetch');
const { Colors, Endpoints } = require('./Constants');
Expand Down
5 changes: 3 additions & 2 deletions test/sendtest.js
Expand Up @@ -2,6 +2,8 @@

const fs = require('node:fs');
const path = require('node:path');
const process = require('node:process');
const { setTimeout: sleep } = require('node:timers/promises');
const util = require('node:util');
const fetch = require('node-fetch');
const { owner, token } = require('./auth.js');
Expand All @@ -12,7 +14,6 @@ const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_
const buffer = l => fetch(l).then(res => res.buffer());
const read = util.promisify(fs.readFile);
const readStream = fs.createReadStream;
const wait = util.promisify(setTimeout);

const linkA = 'https://lolisafe.moe/iiDMtAXA.png';
const linkB = 'https://lolisafe.moe/9hSpedPh.png';
Expand Down Expand Up @@ -97,7 +98,7 @@ client.on('messageCreate', async message => {
for (const [i, test] of tests.entries()) {
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``);
await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``));
await wait(1_000);
await sleep(1_000);
}
/* eslint-enable no-await-in-loop */
} else if (match) {
Expand Down
2 changes: 2 additions & 0 deletions test/shard.js
@@ -1,5 +1,7 @@
'use strict';

const process = require('node:process');
const { setTimeout } = require('node:timers');
const { token } = require('./auth.json');
const { Client, Intents } = require('../src');

Expand Down
1 change: 1 addition & 0 deletions test/sharder.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { token } = require('./auth');
const Discord = require('../src');

Expand Down
1 change: 1 addition & 0 deletions test/tester1000.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { token, prefix, owner } = require('./auth.js');
const { Client, Intents } = require('../src');

Expand Down
1 change: 1 addition & 0 deletions test/tester2000.js
@@ -1,5 +1,6 @@
'use strict';

const process = require('node:process');
const { token, prefix, owner } = require('./auth.js');
const { Client, Options, Intents, Formatters } = require('../src');

Expand Down
4 changes: 2 additions & 2 deletions test/webhooktest.js
Expand Up @@ -2,6 +2,7 @@

const fs = require('node:fs');
const path = require('node:path');
const { setTimeout: sleep } = require('node:timers/promises');
const util = require('node:util');
const fetch = require('node-fetch');
const { owner, token, webhookChannel, webhookToken } = require('./auth.js');
Expand All @@ -12,7 +13,6 @@ const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_
const buffer = l => fetch(l).then(res => res.buffer());
const read = util.promisify(fs.readFile);
const readStream = fs.createReadStream;
const wait = util.promisify(setTimeout);

const linkA = 'https://lolisafe.moe/iiDMtAXA.png';
const linkB = 'https://lolisafe.moe/9hSpedPh.png';
Expand Down Expand Up @@ -107,7 +107,7 @@ client.on('messageCreate', async message => {
for (const [i, test] of tests.entries()) {
await message.channel.send(`**#${i}-Hook: ${type}**\n\`\`\`js\n${test.toString()}\`\`\``);
await test(message, hook).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``));
await wait(1_000);
await sleep(1_000);
}
}
/* eslint-enable no-await-in-loop */
Expand Down

0 comments on commit 3c62bd2

Please sign in to comment.