Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove user bots #2559

Merged
merged 15 commits into from
Jul 26, 2018
28 changes: 1 addition & 27 deletions src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const VoiceBroadcast = require('./voice/VoiceBroadcast');
const UserStore = require('../stores/UserStore');
const ChannelStore = require('../stores/ChannelStore');
const GuildStore = require('../stores/GuildStore');
const ClientPresenceStore = require('../stores/ClientPresenceStore');
const GuildEmojiStore = require('../stores/GuildEmojiStore');
const { Events, browser } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
Expand Down Expand Up @@ -96,17 +95,10 @@ class Client extends BaseClient {
*/
this.channels = new ChannelStore(this);

/**
* Presences that have been received for the client user's friends, mapped by user IDs
* <warn>This is only filled when using a user account.</warn>
* @type {ClientPresenceStore<Snowflake, Presence>}
*/
this.presences = new ClientPresenceStore(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this must remain for bots with friends and to handle the presence of the client


Object.defineProperty(this, 'token', { writable: true });
if (!browser && !this.token && 'CLIENT_TOKEN' in process.env) {
/**
* Authorization token for the logged in user/bot
* Authorization token for the logged in bot
* <warn>This should be kept private at all times.</warn>
* @type {?string}
*/
Expand Down Expand Up @@ -240,10 +232,6 @@ class Client extends BaseClient {

/**
* Logs the client in, establishing a websocket connection to Discord.
* <info>Both bot and regular user accounts are supported, but it is highly recommended to use a bot account whenever
* possible. User accounts are subject to harsher ratelimits and other restrictions that don't apply to bot accounts.
* Bot accounts also have access to many features that user accounts cannot utilise. User accounts that are found to
* be abusing/overusing the API will be banned, locking you out of Discord entirely.</info>
* @param {string} token Token of the account to log in with
* @returns {Promise<string>} Token of the account used
* @example
Expand All @@ -269,20 +257,6 @@ class Client extends BaseClient {
return this.manager.destroy();
}

/**
* Requests a sync of guild data with Discord.
* <info>This can be done automatically every 30 seconds by enabling {@link ClientOptions#sync}.</info>
* <warn>This is only available when using a user account.</warn>
* @param {Guild[]|Collection<Snowflake, Guild>} [guilds=this.guilds] An array or collection of guilds to sync
*/
syncGuilds(guilds = this.guilds) {
if (this.user.bot) return;
this.ws.send({
op: 12,
d: guilds instanceof Collection ? guilds.keyArray() : guilds.map(g => g.id),
});
}

/**
* Obtains an invite from Discord.
* @param {InviteResolvable} invite Invite code or URL
Expand Down
9 changes: 2 additions & 7 deletions src/client/ClientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,9 @@ class ClientManager {
destroy() {
this.client.ws.destroy();
if (!this.client.user) return Promise.resolve();
if (this.client.user.bot) {
return this.client.api.logout.post().then(() => {
this.client.token = null;
return Promise.resolve();
} else {
return this.client.api.logout.post().then(() => {
this.client.token = null;
});
}
});
}
}

Expand Down
1 change: 0 additions & 1 deletion src/client/actions/ActionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class ActionsManager {
this.register(require('./GuildRoleDelete'));
this.register(require('./GuildRoleUpdate'));
this.register(require('./UserUpdate'));
this.register(require('./UserNoteUpdate'));
this.register(require('./GuildSync'));
this.register(require('./GuildEmojiCreate'));
this.register(require('./GuildEmojiDelete'));
Expand Down
30 changes: 0 additions & 30 deletions src/client/actions/UserNoteUpdate.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/client/websocket/packets/WebSocketPacketManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class WebSocketPacketManager {
this.register(WSEvents.CHANNEL_PINS_UPDATE, require('./handlers/ChannelPinsUpdate'));
this.register(WSEvents.PRESENCE_UPDATE, require('./handlers/PresenceUpdate'));
this.register(WSEvents.USER_UPDATE, require('./handlers/UserUpdate'));
this.register(WSEvents.USER_NOTE_UPDATE, require('./handlers/UserNoteUpdate'));
this.register(WSEvents.USER_SETTINGS_UPDATE, require('./handlers/UserSettingsUpdate'));
this.register(WSEvents.USER_GUILD_SETTINGS_UPDATE, require('./handlers/UserGuildSettingsUpdate'));
this.register(WSEvents.VOICE_STATE_UPDATE, require('./handlers/VoiceStateUpdate'));
this.register(WSEvents.TYPING_START, require('./handlers/TypingStart'));
this.register(WSEvents.MESSAGE_CREATE, require('./handlers/MessageCreate'));
Expand All @@ -48,8 +45,6 @@ class WebSocketPacketManager {
this.register(WSEvents.MESSAGE_DELETE_BULK, require('./handlers/MessageDeleteBulk'));
this.register(WSEvents.VOICE_SERVER_UPDATE, require('./handlers/VoiceServerUpdate'));
this.register(WSEvents.GUILD_SYNC, require('./handlers/GuildSync'));
this.register(WSEvents.RELATIONSHIP_ADD, require('./handlers/RelationshipAdd'));
this.register(WSEvents.RELATIONSHIP_REMOVE, require('./handlers/RelationshipRemove'));
this.register(WSEvents.MESSAGE_REACTION_ADD, require('./handlers/MessageReactionAdd'));
this.register(WSEvents.MESSAGE_REACTION_REMOVE, require('./handlers/MessageReactionRemove'));
this.register(WSEvents.MESSAGE_REACTION_REMOVE_ALL, require('./handlers/MessageReactionRemoveAll'));
Expand Down
19 changes: 0 additions & 19 deletions src/client/websocket/packets/handlers/RelationshipAdd.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/client/websocket/packets/handlers/RelationshipRemove.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/client/websocket/packets/handlers/UserGuildSettingsUpdate.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/client/websocket/packets/handlers/UserNoteUpdate.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/client/websocket/packets/handlers/UserSettingsUpdate.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const Messages = {
TOKEN_INVALID: 'An invalid token was provided.',
TOKEN_MISSING: 'Request to use token, but token was unavailable to the client.',

FEATURE_USER_ONLY: 'Only user accounts are able to make use of this feature.',

WS_CONNECTION_TIMEOUT: 'The connection to the gateway timed out.',
WS_CONNECTION_EXISTS: 'There is already an existing WebSocket connection.',
WS_NOT_OPEN: (data = 'data') => `Websocket not open to send ${data}`,
Expand Down
3 changes: 0 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = {

// Stores
ChannelStore: require('./stores/ChannelStore'),
ClientPresenceStore: require('./stores/ClientPresenceStore'),
GuildChannelStore: require('./stores/GuildChannelStore'),
GuildEmojiStore: require('./stores/GuildEmojiStore'),
GuildEmojiRoleStore: require('./stores/GuildEmojiRoleStore'),
Expand Down Expand Up @@ -57,8 +56,6 @@ module.exports = {
return require('./structures/ClientUser');
},
ClientUserChannelOverride: require('./structures/ClientUserChannelOverride'),
ClientUserGuildSettings: require('./structures/ClientUserGuildSettings'),
ClientUserSettings: require('./structures/ClientUserSettings'),
Collector: require('./structures/interfaces/Collector'),
DMChannel: require('./structures/DMChannel'),
Emoji: require('./structures/Emoji'),
Expand Down
3 changes: 1 addition & 2 deletions src/rest/RESTManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class RESTManager {

getAuth() {
const token = this.client.token || this.client.accessToken;
const prefixed = !!this.client.application || (this.client.user && this.client.user.bot);
if (token && prefixed) return `${this.tokenPrefix} ${token}`;
if (token && this.client.application) return `${this.tokenPrefix} ${token}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this cause a big issue for bot accounts if this.client.application is undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was a derp. Good catch!

else if (token) return token;
throw new Error('TOKEN_MISSING');
}
Expand Down
80 changes: 0 additions & 80 deletions src/stores/ClientPresenceStore.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/stores/GuildStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GuildStore extends DataStore {

/**
* Creates a guild.
* <warn>This is only available to bots in less than 10 guilds and user accounts.</warn>
* <warn>This is only available to bots in less than 10 guilds.</warn>
* @param {string} name The name of the guild
* @param {Object} [options] Options for the creating
* @param {string} [options.region] The region for the server, defaults to the closest one available
Expand Down
7 changes: 0 additions & 7 deletions src/stores/MessageStore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const DataStore = require('./DataStore');
const Collection = require('../util/Collection');
const Message = require('../structures/Message');
const { Error } = require('../errors');

/**
* Stores messages for text-based channels.
Expand Down Expand Up @@ -68,12 +67,6 @@ class MessageStore extends DataStore {
}

async _fetchId(messageID) {
if (!this.client.user.bot) {
const messages = await this._fetchMany({ limit: 1, around: messageID });
const msg = messages.get(messageID);
if (!msg) throw new Error('MESSAGE_MISSING');
return msg;
}
const data = await this.client.api.channels[this.channel.id].messages[messageID].get();
return this.add(data);
}
Expand Down
Loading