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
37 changes: 6 additions & 31 deletions src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,15 @@ 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>
* Presences that have been received for the client user, mapped by user IDs
* @type {ClientPresenceStore<Snowflake, Presence>}
*/
this.presences = new ClientPresenceStore(this);

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 +239,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 @@ -262,27 +257,13 @@ class Client extends BaseClient {

/**
* Logs out, terminates the connection to Discord, and destroys the client.
* @returns {Promise}
* @returns {void}
*/
destroy() {
super.destroy();
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 Expand Up @@ -369,22 +350,16 @@ class Client extends BaseClient {
}

/**
* Obtains the OAuth Application of the bot from Discord.
* @param {Snowflake} [id='@me'] ID of application to fetch
* Obtains the OAuth Application of this bot from Discord.
* @returns {Promise<ClientApplication>}
* @example
* client.fetchApplication('id')
* .then(application => console.log(`Obtained application with name: ${application.name}`)
* .catch(console.error);
*/
fetchApplication(id = '@me') {
return this.api.oauth2.applications(id).get()
fetchApplication() {
return this.api.oauth2.applications('@me').get()
.then(app => new ClientApplication(this, app));
}

/**
* Generates a link that can be used to invite the bot to a guild.
* <warn>This is only available when using a bot account.</warn>
* @param {PermissionResolvable} [permissions] Permissions to request
* @returns {Promise<string>}
* @example
Expand Down
10 changes: 1 addition & 9 deletions src/client/ClientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,7 @@ class ClientManager {

destroy() {
this.client.ws.destroy();
if (!this.client.user) return Promise.resolve();
if (this.client.user.bot) {
this.client.token = null;
return Promise.resolve();
} else {
return this.client.api.logout.post().then(() => {
this.client.token = null;
});
}
if (this.client.user) this.client.token = null;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/client/actions/ActionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +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'));
this.register(require('./GuildEmojiUpdate'));
Expand Down
29 changes: 0 additions & 29 deletions src/client/actions/GuildSync.js

This file was deleted.

30 changes: 0 additions & 30 deletions src/client/actions/UserNoteUpdate.js

This file was deleted.

6 changes: 0 additions & 6 deletions src/client/websocket/packets/WebSocketPacketManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@ 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'));
this.register(WSEvents.MESSAGE_DELETE, require('./handlers/MessageDelete'));
this.register(WSEvents.MESSAGE_UPDATE, require('./handlers/MessageUpdate'));
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
11 changes: 0 additions & 11 deletions src/client/websocket/packets/handlers/GuildSync.js

This file was deleted.

23 changes: 0 additions & 23 deletions src/client/websocket/packets/handlers/Ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class ReadyHandler extends AbstractHandler {

client.ws.heartbeat();

data.user.user_settings = data.user_settings;
data.user.user_guild_settings = data.user_guild_settings;

if (!ClientUser) ClientUser = require('../../../../structures/ClientUser');
const clientUser = new ClientUser(client, data.user);
client.user = clientUser;
Expand All @@ -20,27 +17,8 @@ class ReadyHandler extends AbstractHandler {

for (const guild of data.guilds) client.guilds.add(guild);
for (const privateDM of data.private_channels) client.channels.add(privateDM);

for (const relation of data.relationships) {
const user = client.users.add(relation.user);
if (relation.type === 1) {
client.user.friends.set(user.id, user);
} else if (relation.type === 2) {
client.user.blocked.set(user.id, user);
}
}

for (const presence of data.presences || []) client.presences.add(presence);

if (data.notes) {
for (const user in data.notes) {
let note = data.notes[user];
if (!note.length) note = null;

client.user.notes.set(user, note);
}
}

if (!client.users.has('1')) {
client.users.add({
id: '1',
Expand All @@ -61,7 +39,6 @@ class ReadyHandler extends AbstractHandler {
client.setMaxListeners(data.guilds.length + 10);

client.once('ready', () => {
client.syncGuilds();
client.setMaxListeners(10);
client.clearTimeout(t);
});
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 @@ -56,9 +56,6 @@ module.exports = {
// This is a getter so that it properly extends any custom User class
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
2 changes: 1 addition & 1 deletion src/rest/RESTManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +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);
const prefixed = !!this.client.application || this.client.user;
if (token && prefixed) return `${this.tokenPrefix} ${token}`;
else if (token) return token;
throw new Error('TOKEN_MISSING');
Expand Down
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 fewer 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
Loading