Skip to content

Commit

Permalink
[WIP] Remove user bots
Browse files Browse the repository at this point in the history
  • Loading branch information
bdistin committed May 19, 2018
1 parent 56a9d1b commit 95a938c
Show file tree
Hide file tree
Showing 20 changed files with 10 additions and 788 deletions.
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);

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
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}`;
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
20 changes: 0 additions & 20 deletions src/structures/ClientApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,6 @@ class ClientApplication extends Base {
} });
}

/**
* Resets the app's secret.
* <warn>This is only available when using a user account.</warn>
* @returns {Promise<ClientApplication>}
*/
resetSecret() {
return this.client.api.oauth2.applications[this.id].reset.post()
.then(app => new ClientApplication(this.client, app));
}

/**
* Resets the app's bot token.
* <warn>This is only available when using a user account.</warn>
* @returns {Promise<ClientApplication>}
*/
resetToken() {
return this.client.api.oauth2.applications[this.id].bot.reset.post()
.then(app => new ClientApplication(this.client, Object.assign({}, this, { bot: app })));
}

/**
* When concatenated with a string, this automatically returns the application's name instead of the
* ClientApplication object.
Expand Down
Loading

0 comments on commit 95a938c

Please sign in to comment.