Skip to content

Commit

Permalink
porting extendables to d.js-managers
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusgerdin committed Jun 28, 2020
1 parent 9e77e65 commit 2590774
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/extendables/GuildMember/fn_GuildMember#canMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = class extends Extendable {

async canMod(user) {
const member = await this.guild.members.fetch(user).catch(() => null);
return member.highestRole.position < this.highestRole.position;
return member ? member.highestRole.position < this.highestRole.position : false;
}

};
74 changes: 36 additions & 38 deletions src/extendables/KlasaGuild/fn_KlasaGuild#rtbyteInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = class extends Extendable {

if (clientMember.hasPermission('MANAGE_ROLES')) {
// Creating necessary roles on new guild
const adminRole = await this.roles.create({ data: { name: 'Admin' }, reason: `${this.client.user.username} initialization: Admin role` });
const modRole = await this.roles.create({ data: { name: 'Moderator' }, reason: `${this.client.user.username} initialization: Moderator role` });
const adminRole = await this.roles.create({ data: { name: 'Admin' }, reason: `${this.client.user.username} initialization: admin role` });
const modRole = await this.roles.create({ data: { name: 'Moderator' }, reason: `${this.client.user.username} initialization: moderator role` });

await this.settings.update('roles.administrator', adminRole, this);
await this.settings.update('roles.moderator', modRole, this);
Expand All @@ -28,13 +28,13 @@ module.exports = class extends Extendable {
}

if (clientMember.hasPermission('MANAGE_CHANNELS')) {
const adminRole = await this.roles.get(this.settings.get('roles.administrator'));
const modRole = await this.roles.get(this.settings.get('roles.moderator'));
const adminRole = await this.roles.cache.get(this.settings.get('roles.administrator'));
const modRole = await this.roles.cache.get(this.settings.get('roles.moderator'));

// Creating log channel
const logChannel = await this.channels.create('server-log', {
topic: `Activity log for ${this.client.user.username}`,
reason: `${this.client.user.username} initialization: Log channel`
topic: `Activity log for ${this.client.user.username}.`,
reason: `${this.client.user.username} initialization: log channel`
});
// Adding log channel into guild settings
await this.settings.update('channels.log', logChannel, this);
Expand All @@ -45,75 +45,73 @@ module.exports = class extends Extendable {
await logChannel.updateOverwrite(this.client.user, {
VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true
},
`${this.client.user.username} initialization: Adjusting log channel permissions for bot`);
}, `${this.client.user.username} initialization: adjusting log channel permissions for bot`);

await logChannel.updateOverwrite(this.id, {
VIEW_CHANNEL: false,
READ_MESSAGE_HISTORY: false
},
`${this.client.user.username} initialization: Adjusting log channel permissions for @everyone`);
}, `${this.client.user.username} initialization: adjusting log channel permissions for @everyone`);

await logChannel.updateOverwrite(adminRole, {
VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true
},
`${this.client.user.username} initialization: Adjusting log channel permissions for administrator role`);
}, `${this.client.user.username} initialization: adjusting log channel permissions for administrator role`);

await logChannel.updateOverwrite(modRole, {
VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true
},
`${this.client.user.username} initialization: Adjusting log channel permissions for moderator role`);
}, `${this.client.user.username} initialization: adjusting log channel permissions for moderator role`);
}

if (type === 'control') {
const globalLogChannel = await this.channels.create('global-log', {
topic: `Global activity log for ${this.client.user.username}`,
reason: `${this.client.user.username} initialization: Global log channel`
topic: `Global activity log for ${this.client.user.username}.`,
reason: `${this.client.user.username} initialization: global log channel`
});

// Check if role setup failed and adjust perms if not
if (!rolesSkipped) {
await globalLogChannel.updateOverwrite(this.client.user, {
VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true
},
`${this.client.user.username} initialization: Adjusting log channel permissions for bot`);
}, `${this.client.user.username} initialization: adjusting log channel permissions for bot`);

await globalLogChannel.updateOverwrite(this.id, {
VIEW_CHANNEL: false,
READ_MESSAGE_HISTORY: false
},
`${this.client.user.username} initialization: Adjusting log channel permissions for @everyone`);
}, `${this.client.user.username} initialization: adjusting log channel permissions for @everyone`);

await logChannel.updateOverwrite(adminRole, {
VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true
},
`${this.client.user.username} initialization: Adjusting log channel permissions for administrator role`);
}, `${this.client.user.username} initialization: adjusting log channel permissions for administrator role`);

await logChannel.updateOverwrite(modRole, {
VIEW_CHANNEL: true,
READ_MESSAGE_HISTORY: true
},
`${this.client.user.username} initialization: Adjusting log channel permissions for moderator role`);
}, `${this.client.user.username} initialization: adjusting log channel permissions for moderator role`);
}

// Setting control guild and global log channel in clientStorage
await this.client.settings.update('guilds.controlGuild', this.id, this);
await this.client.settings.update('channels.globalLog', globalLogChannel.id, this);

// Adding and initializing the emojis for the bot to use
const affirmEmoji = await this.emojis.create('./assets/img/emoji/affirm.png', 'affirm', { reason: `${this.client.user.username} initialization: Creating affirm emoji` });
const rejectEmoji = await this.emojis.create('./assets/img/emoji/reject.png', 'reject', { reason: `${this.client.user.username} initialization: Creating reject emoji` });
const arrowLeftEmoji = await this.emojis.create('./assets/img/emoji/arrowLeft.png', 'arrow_left', { reason: `${this.client.user.username} initialization: Creating arrowLeft emoji` });
const affirmEmoji = await this.emojis.create('./assets/img/emoji/affirm.png', 'affirm', { reason: `${this.client.user.username} initialization: creating affirm emoji` });
const rejectEmoji = await this.emojis.create('./assets/img/emoji/reject.png', 'reject', { reason: `${this.client.user.username} initialization: creating reject emoji` });
const arrowLeftEmoji = await this.emojis.create('./assets/img/emoji/arrowLeft.png', 'arrow_left', { reason: `${this.client.user.username} initialization: creating arrowLeft emoji` });
// eslint-disable-next-line max-len
const arrowToLeftEmoji = await this.emojis.create('./assets/img/emoji/arrowToLeft.png', 'arrow_to_left', { reason: `${this.client.user.username} initialization: Creating arrowToLeft emoji` });
const arrowRightEmoji = await this.emojis.create('./assets/img/emoji/arrowRight.png', 'arrow_right', { reason: `${this.client.user.username} initialization: Creating arrowRight emoji` });
const arrowToLeftEmoji = await this.emojis.create('./assets/img/emoji/arrowToLeft.png', 'arrow_to_left', { reason: `${this.client.user.username} initialization: creating arrowToLeft emoji` });
const arrowRightEmoji = await this.emojis.create('./assets/img/emoji/arrowRight.png', 'arrow_right', { reason: `${this.client.user.username} initialization: creating arrowRight emoji` });
// eslint-disable-next-line max-len
const arrowToRightEmoji = await this.emojis.create('./assets/img/emoji/arrowToRight.png', 'arrow_to_right', { reason: `${this.client.user.username} initialization: Creating arrowToRight emoji` });
const infoEmoji = await this.emojis.create('./assets/img/emoji/info.png', 'info', { reason: `${this.client.user.username} initialization: Creating info emoji` });
const listEmoji = await this.emojis.create('./assets/img/emoji/list.png', 'list', { reason: `${this.client.user.username} initialization: Creating list emoji` });
const onlineEmoji = await this.emojis.create('./assets/img/emoji/online.png', 'online', { reason: `${this.client.user.username} initialization: Creating online emoji` });
const idleEmoji = await this.emojis.create('./assets/img/emoji/idle.png', 'idle', { reason: `${this.client.user.username} initialization: Creating idle emoji` });
const dndEmoji = await this.emojis.create('./assets/img/emoji/dnd.png', 'dnd', { reason: `${this.client.user.username} initialization: Creating dnd emoji` });
const offlineEmoji = await this.emojis.create('./assets/img/emoji/offline.png', 'offline', { reason: `${this.client.user.username} initialization: Creating offline emoji` });
const botBadgeEmoji = await this.emojis.create('./assets/img/emoji/botBadge.png', 'bot_badge', { reason: `${this.client.user.username} initialization: Creating bot badge emoji` });
const arrowToRightEmoji = await this.emojis.create('./assets/img/emoji/arrowToRight.png', 'arrow_to_right', { reason: `${this.client.user.username} initialization: creating arrowToRight emoji` });
const infoEmoji = await this.emojis.create('./assets/img/emoji/info.png', 'info', { reason: `${this.client.user.username} initialization: creating info emoji` });
const listEmoji = await this.emojis.create('./assets/img/emoji/list.png', 'list', { reason: `${this.client.user.username} initialization: creating list emoji` });
const onlineEmoji = await this.emojis.create('./assets/img/emoji/online.png', 'online', { reason: `${this.client.user.username} initialization: creating online emoji` });
const idleEmoji = await this.emojis.create('./assets/img/emoji/idle.png', 'idle', { reason: `${this.client.user.username} initialization: creating idle emoji` });
const dndEmoji = await this.emojis.create('./assets/img/emoji/dnd.png', 'dnd', { reason: `${this.client.user.username} initialization: creating dnd emoji` });
const offlineEmoji = await this.emojis.create('./assets/img/emoji/offline.png', 'offline', { reason: `${this.client.user.username} initialization: creating offline emoji` });
const botBadgeEmoji = await this.emojis.create('./assets/img/emoji/botBadge.png', 'bot_badge', { reason: `${this.client.user.username} initialization: creating bot badge emoji` });
await this.client.settings.update('emoji.affirm', affirmEmoji.id, this);
await this.client.settings.update('emoji.reject', rejectEmoji.id, this);
await this.client.settings.update('emoji.arrowLeft', arrowLeftEmoji.id, this);
Expand All @@ -134,7 +132,7 @@ module.exports = class extends Extendable {
}

// Get owner member and log channel
const owner = await this.client.users.get(this.ownerID);
const owner = await this.client.users.cache.get(this.ownerID);
// Building server owner message embed
const embed = new MessageEmbed()
.setAuthor(this.language.get('INIT_TITLE'), this.client.user.displayAvatarURL())
Expand Down
2 changes: 1 addition & 1 deletion src/extendables/KlasaMessage/fn_KlasaMessage#affirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class extends Extendable {
}

async affirm(message = null, messageOptions = {}) {
const affirmEmoji = await this.client.emojis.get(this.client.settings.get('emoji.affirm'));
const affirmEmoji = await this.client.emojis.cache.get(this.client.settings.get('emoji.affirm'));
await this.react(affirmEmoji);
return message ? this.sendMessage(`${this.author}\n${affirmEmoji} ${message}`, messageOptions) : this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/extendables/KlasaMessage/fn_KlasaMessage#arrowLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class extends Extendable {
}

async arrowLeft(message = null, messageOptions = {}) {
const arrowLeftEmoji = await this.client.emojis.get(this.client.settings.get('emoji.arrowLeft'));
const arrowLeftEmoji = await this.client.emojis.cache.get(this.client.settings.get('emoji.arrowLeft'));
await this.react(arrowLeftEmoji);
return message ? this.sendMessage(`${this.author}\n${arrowLeftEmoji} ${message}`, messageOptions) : this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/extendables/KlasaMessage/fn_KlasaMessage#arrowRight.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class extends Extendable {
}

async arrowRight(message = null, messageOptions = {}) {
const arrowRightEmoji = await this.client.emojis.get(this.client.settings.get('emoji.arrowRight'));
const arrowRightEmoji = await this.client.emojis.cache.get(this.client.settings.get('emoji.arrowRight'));
await this.react(arrowRightEmoji);
return message ? this.sendMessage(`${this.author}\n${arrowRightEmoji} ${message}`, messageOptions) : this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class extends Extendable {
}

async arrowToLeft(message = null, messageOptions = {}) {
const arrowToLeftEmoji = await this.client.emojis.get(this.client.settings.get('emoji.arrowToLeft'));
const arrowToLeftEmoji = await this.client.emojis.cache.get(this.client.settings.get('emoji.arrowToLeft'));
await this.react(arrowToLeftEmoji);
return message ? this.sendMessage(`${this.author}\n${arrowToLeftEmoji} ${message}`, messageOptions) : this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class extends Extendable {
}

async arrowToRight(message = null, messageOptions = {}) {
const arrowToRightEmoji = await this.client.emojis.get(this.client.settings.get('emoji.arrowToRight'));
const arrowToRightEmoji = await this.client.emojis.cache.get(this.client.settings.get('emoji.arrowToRight'));
await this.react(arrowToRightEmoji);
return message ? this.sendMessage(`${this.author}\n${arrowToRightEmoji} ${message}`, messageOptions) : this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/extendables/KlasaMessage/fn_KlasaMessage#info.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class extends Extendable {
}

async info(message = null, messageOptions = {}) {
const infoEmoji = await this.client.emojis.get(this.client.settings.get('emoji.info'));
const infoEmoji = await this.client.emojis.cache.get(this.client.settings.get('emoji.info'));
await this.react(infoEmoji);
return message ? this.sendMessage(`${this.author}\n${infoEmoji} ${message}`, messageOptions) : this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/extendables/KlasaMessage/fn_KlasaMessage#list.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class extends Extendable {
}

async list(message = null, messageOptions = {}) {
const listEmoji = await this.client.emojis.get(this.client.settings.get('emoji.list'));
const listEmoji = await this.client.emojis.cache.get(this.client.settings.get('emoji.list'));
await this.react(listEmoji);
return message ? this.sendMessage(`${this.author}\n${listEmoji} ${message}`, messageOptions) : this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/extendables/KlasaMessage/fn_KlasaMessage#reject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class extends Extendable {
}

async reject(message = null, messageOptions = {}) {
const rejectEmoji = await this.client.emojis.get(this.client.settings.get('emoji.reject'));
const rejectEmoji = await this.client.emojis.cache.get(this.client.settings.get('emoji.reject'));
await this.react(rejectEmoji);
return message ? this.sendMessage(`${this.author}\n${rejectEmoji} ${message}`, messageOptions) : this;
}
Expand Down

0 comments on commit 2590774

Please sign in to comment.