Skip to content

Commit

Permalink
fix(djs12): caches
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobiah committed Mar 30, 2020
1 parent 76c4054 commit b40f47f
Show file tree
Hide file tree
Showing 52 changed files with 113 additions and 113 deletions.
12 changes: 6 additions & 6 deletions src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ const getChannels = (channelsParam, message) => {
let channels = [];
// handle it for strings
if (channelsParam !== 'all' && channelsParam !== 'current' && channelsParam !== '*') {
channels.push(message.guild.channels.get(channelsParam.trim().replace(/(<|>|#)/ig, '')));
channels.push(message.guild.channels.cache.get(channelsParam.trim().replace(/(<|>|#)/ig, '')));
} else if (channelsParam === 'all' || channelsParam === '*') {
channels = channels.concat(message.guild.channels.array().filter(channel => channel.type === 'text'));
channels = channels.concat(message.guild.channels.cache.filter(channel => channel.type === 'text').array());
} else if (channelsParam === 'current') {
channels.push(message.channel);
}
Expand All @@ -803,8 +803,8 @@ const getTarget = (targetParam, roleMentions, userMentions, message) => {
target = userMention;
target.type = 'User';
} else {
const userTarget = message.guild.members.get(targetParam);
const roleTarget = message.guild.roles.get(targetParam);
const userTarget = message.guild.members.cache.get(targetParam);
const roleTarget = message.guild.roles.cache.get(targetParam);
if (targetParam === '*') {
target = message.guild.roles.everyone;
target.type = 'Role';
Expand All @@ -831,8 +831,8 @@ const resolveRoles = ({ mentions = undefined, content = '', guild = undefined })
if (matches && matches.length) {
matches.slice(0, 1);
matches = matches.map((match) => {
if (guild.roles.has(match)) {
return guild.roles.get(match);
if (guild.roles.cache.has(match)) {
return guild.roles.cache.get(match);
}
return undefined;
}).filter(match => typeof match !== 'undefined');
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Builds/AddBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ class AddBuild extends Command {
}
let unfoundOwners = [];
const builds = await this.settings.addNewBuilds(buildsConfig.builds.map((build) => {
if ((typeof build.owner !== 'undefined' && this.bot.client.users.get(build.owner)) || typeof build.owner === 'undefined') {
if ((typeof build.owner !== 'undefined' && this.bot.client.cache.users.get(build.owner)) || typeof build.owner === 'undefined') {
return {
title: build.title,
body: `${buildsConfig.common.prefix || ''}${build.body}${buildsConfig.common.postfix || ''}`,
image: build.image,
ownerId: build.owner || message.author.id,
owner: this.bot.client.users.get(build.owner) || build.owner || message.author,
owner: this.bot.client.cache.users.get(build.owner) || build.owner || message.author,
isPublic: build.is_public || false,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/DefaultRoles/AddDefaultRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AddDefaultRole extends Command {

async run(message) {
const roleId = message.strippedContent.match(this.regex)[1];
if (roleId && message.guild.roles.has(roleId.trim())) {
if (roleId && message.guild.roles.cache.has(roleId.trim())) {
const roles = JSON.parse(await this.settings.getGuildSetting(message.guild, 'defaultRoles') || '[]');
if (!roles.includes(roleId)) {
roles.push(roleId);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/DefaultRoles/DeleteDefaultRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeleteDefaultRole extends Command {

async run(message) {
const roleId = message.strippedContent.match(this.regex)[1];
if (roleId && message.guild.roles.has(roleId.trim())) {
if (roleId && message.guild.roles.cache.has(roleId.trim())) {
const roles = JSON.parse(await this.settings.getGuildSetting(message.guild, 'defaultRoles') || '[]');
if (roles.includes(roleId)) {
roles.splice(roles.indexOf(roleId, 1));
Expand Down
4 changes: 2 additions & 2 deletions src/commands/DynamicChannels/AddTemplateChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class AddTemplateChannel extends Command {
async run(message) {
const newTemplateChannelId = message.strippedContent.match(this.regex)[1];
const isRelay = relayRegex.test(message.strippedContent);
if (newTemplateChannelId && this.bot.client.channels.has(newTemplateChannelId.trim())) {
const newTemplateChannel = this.bot.client.channels.get(newTemplateChannelId.trim());
if (newTemplateChannelId && this.bot.client.channels.cache.has(newTemplateChannelId.trim())) {
const newTemplateChannel = this.bot.client.channels.cache.get(newTemplateChannelId.trim());
await this.settings.addTemplate(newTemplateChannel, isRelay);
this.messageManager.reply(message, `${newTemplateChannel} added as a template.`, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/DynamicChannels/DeleteTemplateChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class DeleteTemplateChannel extends Command {
*/
async run(message) {
const templateId = message.strippedContent.match(this.regex)[1];
if (templateId && this.bot.client.channels.has(templateId.trim())) {
const template = this.bot.client.channels.get(templateId.trim());
if (templateId && this.bot.client.channels.cache.has(templateId.trim())) {
const template = this.bot.client.channels.cache.get(templateId.trim());
await this.settings.deleteTemplate(template);
this.messageManager.reply(message, `${template} removed as a template.`, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/DynamicChannels/ListTemplateChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class AddTemplateChannel extends Command {
const templateIds = await this.settings.getTemplates([message.guild]);
const templates = [];
templateIds.forEach((templateId) => {
if (message.guild.channels.has(templateId)) {
templates.push(message.guild.channels.get(templateId));
if (message.guild.channels.cache.has(templateId)) {
templates.push(message.guild.channels.cache.get(templateId));
}
});
const embed = new BaseEmbed(this.bot);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/DynamicChannels/SetTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class SetTemplate extends Command {
if (!templateChannelId || !nameTemplate) {
return this.sendToggleUsage(message, ctx, []);
}
if (templateChannelId && this.bot.client.channels.has(templateChannelId.trim())) {
const template = this.bot.client.channels.get(templateChannelId.trim());
if (templateChannelId && this.bot.client.channels.cache.has(templateChannelId.trim())) {
const template = this.bot.client.channels.cache.get(templateChannelId.trim());
if (await this.settings.isTemplate(template)) {
await this.settings.setDynTemplate(template.id, nameTemplate);
this.messageManager.reply(message, `\`${nameTemplate}\` set as ${template}'s name template'.`, true, true);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Giveaways/StartGiveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class StartGiveaway extends Command {
[time, winnerCount, channel, ...prizeTokens] = message.strippedContent.replace(this.call, '').trim().split(/ +/g);
if (channelCap.test(channel)) {
[, channel] = (channel.match(channelCap) || []);
if (channel && message.guild.channels.has(channel)) {
channel = message.guild.channels.get(channel);
if (channel && message.guild.channels.cache.has(channel)) {
channel = message.guild.channels.cache.get(channel);
}
} else {
prizeTokens.unshift(channel);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/LFG/SetLFGChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SetLFGChannel extends Command {
const chm = matchable.match(new RegExp(captures.channel, 'i'));
const channel = (chm || [])[1];

if (channel && this.bot.client.channels.has(channel.trim())) {
if (channel && this.bot.client.channels.cache.has(channel.trim())) {
await this.settings.setGuildSetting(message.guild, `lfgChannel${platform !== 'pc' ? `.${platform}` : ''}`, channel);
this.messageManager.notifySettingsChange(message, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Logging/BanLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SetBanLog extends Command {
*/
async run(message) {
const logChannel = message.strippedContent.match(this.regex)[1];
if (logChannel && this.bot.client.channels.has(logChannel.trim())) {
if (logChannel && this.bot.client.channels.cache.has(logChannel.trim())) {
await this.settings.setGuildSetting(message.guild, 'banLog', logChannel);
this.messageManager.notifySettingsChange(message, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Logging/MemberRemoveLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SetMemRemoveLog extends Command {
*/
async run(message) {
const logChannel = message.strippedContent.match(this.regex)[1];
if (logChannel && this.bot.client.channels.has(logChannel.trim())) {
if (logChannel && this.bot.client.channels.cache.has(logChannel.trim())) {
await this.settings.setGuildSetting(message.guild, 'memberRemoveLog', logChannel);
this.messageManager.notifySettingsChange(message, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Logging/SetMessageDeleteLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SetMessageDeleteLog extends Command {
*/
async run(message) {
const logChannel = message.strippedContent.match(this.regex)[1];
if (logChannel && this.bot.client.channels.has(logChannel.trim())) {
if (logChannel && this.bot.client.channels.cache.has(logChannel.trim())) {
await this.settings.setGuildSetting(message.guild, 'msgDeleteLog', logChannel);
this.messageManager.notifySettingsChange(message, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Logging/SetModRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SetModRole extends Command {
*/
async run(message) {
const roleId = message.strippedContent.match(this.regex)[1];
if (roleId && message.guild.roles.has(roleId.trim())) {
if (roleId && message.guild.roles.cache.has(roleId.trim())) {
await this.settings.setGuildSetting(message.guild, 'modRole', roleId);
this.messageManager.notifySettingsChange(message, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Logging/SetVulgarLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SetVulgarLog extends Command {
*/
async run(message) {
const vulgarLogChannel = message.strippedContent.match(this.regex)[1];
if (vulgarLogChannel && this.bot.client.channels.has(vulgarLogChannel.trim())) {
if (vulgarLogChannel && this.bot.client.channels.cache.has(vulgarLogChannel.trim())) {
await this.settings.setGuildSetting(message.guild, 'vulgarLog', vulgarLogChannel);
this.messageManager.notifySettingsChange(message, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Logging/UnbanLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SetUnBanLog extends Command {
*/
async run(message) {
const logChannel = message.strippedContent.match(this.regex)[1];
if (logChannel && this.bot.client.channels.has(logChannel.trim())) {
if (logChannel && this.bot.client.channels.cache.has(logChannel.trim())) {
await this.settings.setGuildSetting(message.guild, 'unbanLog', logChannel);
this.messageManager.notifySettingsChange(message, true, true);
return this.messageManager.statuses.SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Owner/LeaveServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class LeaveServer extends Command {
*/
async run(message) {
const serverid = message.strippedContent.match(this.regex)[1];
if (this.bot.client.guilds.has(serverid)) {
const guild = await this.bot.client.guilds.get(serverid).leave();
if (this.bot.client.guilds.cache.has(serverid)) {
const guild = await this.bot.client.guilds.cache.get(serverid).leave();
this.messageManager.reply(message, `Left ${guild.name}`, true, true);
return this.messageManager.statuses.SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Owner/Servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Servers extends Command {
async run(message) {
const fileContents = [];
fileContents.push('"Guild Name","Guild Owner","Guild Id","Member Count","# Human","# Bot"');
this.bot.client.guilds.array().forEach((guild) => {
this.bot.client.guilds.cache.array().forEach((guild) => {
fileContents.push(`"${guild.name}","${guild.owner.user.username}#${guild.owner.user.discriminator}","${guild.id}","${guild.members.size}","${guild.members.filter(user => !user.user.bot).size}","${guild.members.filter(user => user.user.bot).size}"`);
});

Expand Down
2 changes: 1 addition & 1 deletion src/commands/Promocodes/AddManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AddManager extends Command {
this.messageManager.reply(message, 'You either manage none or too many pools. Please specify the pool ID.');
return this.messageManager.statuses.FAILURE;
}
if (this.bot.client.users.has(user.trim())) {
if (this.bot.client.users.cache.has(user.trim())) {
await this.settings.addPoolManager(pool, user.trim());
return this.messageManager.statuses.SUCCESS;
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Promocodes/GrantPromocode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GrantPromocode extends Command {
this.messageManager.reply(message, 'You can either not manage provided pool, or provided pool doesn\'t exist.');
return this.messageManager.statuses.FAILURE;
}
if (!user || !this.bot.client.users.has(user)) {
if (!user || !this.bot.client.users.cache.has(user)) {
this.messageManager.reply(message, 'A user to grant to must be specified');
return this.messageManager.statuses.FAILURE;
}
Expand All @@ -46,7 +46,7 @@ class GrantPromocode extends Command {

await this.settings.grantCode(code, user, message.author.id, platform);
this.messageManager.reply(message, `Code granted to <@${user}> from ${pool} on ${platform}`);
this.messageManager.sendDirectMessageToUser(this.bot.client.users.get(user), `You've been granted a code for ${pool} on ${platform}.
this.messageManager.sendDirectMessageToUser(this.bot.client.users.cache.get(user), `You've been granted a code for ${pool} on ${platform}.
\nUse \`${ctx.prefix}glyphs list claimed\` in this direct message to see your new code.
\n**If you are receiving this in error, or the code is for the wrong platform,** contact ${message.member} immediately with the code so it can be revoked and a new code granted.`);
return this.messageManager.statuses.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Promocodes/RemoveManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RemoveManager extends Command {
this.messageManager.reply(message, 'You either manage none or too many pools. Please specify the pool ID.');
return this.messageManager.statuses.FAILURE;
}
if (this.bot.client.users.has(user.trim())) {
if (this.bot.client.users.cache.has(user.trim())) {
await this.settings.removePoolManager(pool, user.trim());
return this.messageManager.statuses.SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Promocodes/SetPoolGuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SetPoolGuild extends Command {
this.messageManager.reply(message, 'You either manage none or too many pools. Please specify the pool ID.');
return this.messageManager.statuses.FAILURE;
}
if (guildId && this.bot.client.guilds.has(guildId)) {
if (guildId && this.bot.client.guilds.cache.has(guildId)) {
await this.settings.setPoolGuild(pool, guildId.trim());
return this.messageManager.statuses.SUCCESS;
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/Roles/JoinRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Command = require('../../models/Command.js');
*/
const getRoleForString = (string, message) => {
const trimmedString = string.trim();
const roleFromId = message.guild.roles.get(trimmedString);
const roleFromId = message.guild.roles.cache.get(trimmedString);
let roleFromName;
if (typeof roleFromId === 'undefined') {
roleFromName = message.guild.roles
Expand Down Expand Up @@ -66,11 +66,11 @@ class JoinRole extends Command {
const filteredRoles = roles.filter(storedRole => role.id === storedRole.id);

const botIsHigher = message.guild.me
.roles.highest.comparePositionTo(message.guild.roles.get(role.id));
.roles.highest.comparePositionTo(message.guild.roles.cache.get(role.id));

const botHasPerm = message.channel.permissionsFor(this.bot.client.user.id).has('MANAGE_ROLES');

const userHasRole = message.member.roles.get(role.id);
const userHasRole = message.member.roles.cache.get(role.id);

const userHasMinimumRole = (filteredRoles[0] && filteredRoles[0].requiredRole
? message.member.roles.has(filteredRoles[0].requiredRole)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Roles/LeaveRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const Command = require('../../models/Command.js');
*/
function getRoleForString(string, message) {
const trimmedString = string.trim();
const roleFromId = message.guild.roles.get(trimmedString);
const roleFromId = message.guild.roles.cache.get(trimmedString);
let roleFromName;
if (typeof roleFromId === 'undefined') {
roleFromName = message.guild.roles
roleFromName = message.guild.roles.cache
.find(item => item.name.toLowerCase() === trimmedString.toLowerCase());
}
return roleFromId || roleFromName || null;
Expand Down
8 changes: 4 additions & 4 deletions src/commands/Roles/RemoveRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const Command = require('../../models/Command.js');
*/
function getRoleForString(string, message) {
const trimmedString = string.trim();
const roleFromId = message.guild.roles.get(trimmedString);
const roleFromId = message.guild.roles.cache.get(trimmedString);
let roleFromName;
if (typeof roleFromId === 'undefined') {
roleFromName = message.guild.roles
roleFromName = message.guild.roles.cache
.find(item => item.name.toLowerCase() === trimmedString.toLowerCase());
}
return roleFromId || roleFromName || null;
Expand Down Expand Up @@ -61,7 +61,7 @@ class RemoveRole extends Command {
.filter(storedRole => filteredRoles[0].id !== storedRole.id)
.map(unSelectedRole => unSelectedRole.getSimple()), filteredRoles[0]);
if (deleteRole) {
message.guild.roles.get(filteredRoles[0].id).delete('Deleting role from role remove');
message.guild.roles.cache.get(filteredRoles[0].id).delete('Deleting role from role remove');
}
return this.messageManager.statuses.SUCCESS;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ class RemoveRole extends Command {
},
{
name: '**Roles:**',
value: message.guild.roles.map(r => r.name).join('; '),
value: message.guild.roles.cache.map(r => r.name).join('; '),
inline: true,
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Roles/RoleIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Roles extends Command {
* @returns {string} success status
*/
async run(message) {
const roles = message.guild.roles.array().sort((a, b) => {
const roles = message.guild.roles.cache.array().sort((a, b) => {
if (a.name < b.name) {
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Roles/Roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Roles extends Command {
async run(message) {
const roles = (await this.settings.getRolesForGuild(message.guild))
.filter(role => (role && role.requiredRoleId
? message.member.roles.has(role.requiredRoleId)
? message.member.roles.cache.has(role.requiredRoleId)
: true));
const prefix = await this.settings.getGuildSetting(message.guild, 'prefix');
if (roles.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Roles/TrackRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TrackRole extends Command {
.replace('>', '');

if (!roleId) return this.messageManager.statuses.FAILURE;
const role = guild.roles.get(roleId);
const role = guild.roles.cache.get(roleId);
if (!role) return this.messageManager.statuses.FAILURE;

await this.settings.trackRole(guild, channel, role);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Roles/UntrackRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class UntrackRole extends Command {
.replace('>', '');

if (!roleId) return this.messageManager.statuses.FAILURE;
const role = guild.roles.get(roleId);
const role = guild.roles.cache.get(roleId);
if (!role) return this.messageManager.statuses.FAILURE;

await this.settings.untrackRole(guild, role);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/Rooms/Create.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ class Create extends Command {
shown = ctx.defaultShown;
}

const modRole = message.guild.roles.get(await this.settings.getGuildSetting(message.guild, 'modRole'));
const useModRole = modRole && modRole.id ? message.guild.roles.has(modRole.id) : false;
const modRole = message.guild.roles.cache.get(await this.settings.getGuildSetting(message.guild, 'modRole'));
const useModRole = modRole && modRole.id ? message.guild.cache.roles.has(modRole.id) : false;

if (ctx.tempCategory || (message.guild && message.guild.channels.has(ctx.tempCategory))) {
if (ctx.tempCategory || (message.guild && message.guild.channels.cache.has(ctx.tempCategory))) {
useText = false;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ If this is in error, please log a bug report with \`${ctx.prefix}bug\`.`;
});
let category;
if (!ctx.tempCategory
|| !(message.guild && message.guild.channels.has(ctx.tempCategory.id))) {
|| !(message.guild && message.guild.channels.cache.has(ctx.tempCategory.id))) {
category = await message.guild.channels.create(name, {
name,
type: 'category',
Expand Down
Loading

0 comments on commit b40f47f

Please sign in to comment.