Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

WIP - Fix API and other things #1367

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
11 changes: 8 additions & 3 deletions src/commands/utility/guildinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ module.exports = class GuildInfo extends Command {
}, client)
}

run ({ t, author, channel, language }, guild = channel.guild) {
async run ({ t, author, channel, language }, guild = channel.guild) {
if (guild.members.cache.size !== guild.memberCount) {
guild.members.fetch({ withPresences: true })
Doges marked this conversation as resolved.
Show resolved Hide resolved
}
const embed = new SwitchbladeEmbed(author)
moment.locale(language)
channel.startTyping()
embed.setTitle(guild.name)
.setThumbnail(guild.iconURL({ dynamic: true }) ? guild.iconURL({ dynamic: true }) : `https://guild-default-icon.herokuapp.com/${guild.nameAcronym}`)
.addField(t('commands:guildinfo.id'), guild.id, true)
.addField(t('commands:guildinfo.owner'), guild.owner, true)
.addField(t('commands:guildinfo.region'), t(`regions:${guild.region}`), true)
.addField(t('commands:guildinfo.owner'), `<@${guild.ownerID}>`, true)
.addField(t('commands:guildinfo.channels', { count: MiscUtils.formatNumber(guild.channels.cache.size, language) }), [
t('commands:guildinfo.textChannels', { count: MiscUtils.formatNumber(guild.channels.cache.filter(g => g.type === 'text' || g.type === 'category').size, language) }),
t('commands:guildinfo.voiceChannels', { count: MiscUtils.formatNumber(guild.channels.cache.filter(g => g.type === 'voice').size, language) })
].join('\n'), true)
.addField(t('commands:guildinfo.createdAt'), `${moment(guild.createdTimestamp).format('LLL')}\n(${moment(guild.createdTimestamp).fromNow()})`, true)
.addField(t('commands:guildinfo.joinedAt'), `${moment(guild.joinedTimestamp).format('LLL')}\n(${moment(guild.joinedTimestamp).fromNow()})`, true)
.addField(t('commands:guildinfo.serverBoost', { count: MiscUtils.formatNumber(guild.premiumSubscriptionCount, language) }), [
t('commands:guildinfo.level', { count: MiscUtils.formatNumber(guild.premiumTier, language) })
].join('\n'), true)
.addField(t('commands:guildinfo.members', { count: MiscUtils.formatNumber(guild.members.cache.size, language) }), [
`${this.getEmoji('streaming')} ${t('commands:guildinfo.streaming', { count: MiscUtils.formatNumber(guild.members.cache.filter(m => m.game === 'streaming').size, language) })}`,
`${this.getEmoji('online')} ${t('commands:guildinfo.online', { count: MiscUtils.formatNumber(guild.members.cache.filter(m => m.presence.status === 'online').size, language) })}`,
Expand Down
4 changes: 2 additions & 2 deletions src/http/api/contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ module.exports = class Contributors extends Route {
}, client)
}

register (app) {
async register (app) {
const router = Router()

router.get('/', async (req, res) => {
const guild = this.client.guilds.cache.get(process.env.BOT_GUILD)
const guild = await this.client.guilds.fetch(process.env.BOT_GUILD)
const roles = guild.roles.cache
const members = await guild.members.fetch()

Expand Down
13 changes: 7 additions & 6 deletions src/http/api/guilds.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ module.exports = class Guilds extends Route {
}, client)
}

register (app) {
async register (app) {
const router = Router()

// Info
router.get('/:guildId/members', async (req, res) => {
const guild = this.client.guilds.cache.get(req.params.guildId)
const guild = await this.client.guilds.fetch(req.params.guildId)
const guildMembers = await guild.members.fetch()
if (guild) {
const { id, name, icon, members: { size } } = guild
const userMembers = guild.members.filter(m => !m.user.bot).size
const botMembers = size - userMembers
return res.status(200).json({ id, name, icon, totalMembers: size, userMembers, botMembers })
const { id, name, icon, memberCount } = guild
const userMembers = guildMembers.filter(m => !m.user.bot).size
const botMembers = memberCount - userMembers
return res.status(200).json({ id, name, icon, totalMembers: memberCount, userMembers, botMembers })
}
res.status(400).json({ error: 'Guild not found!' })
})
Expand Down
10 changes: 7 additions & 3 deletions src/http/api/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ module.exports = class Statistics extends Route {
}, client)
}

register (app) {
async register (app) {
const router = Router()
const shardGuildCounts = await this.client.shard.fetchClientValues('guilds.cache.size')
const totalGuildCount = shardGuildCounts.reduce((total, current) => total + current)
Doges marked this conversation as resolved.
Show resolved Hide resolved
const shardUserCounts = await this.client.shard.fetchClientValues('users.cache.size')
const totalUserCount = shardUserCounts.reduce((total, current) => total + current)
Doges marked this conversation as resolved.
Show resolved Hide resolved

router.get('/', (req, res) => {
res.status(200).json({
serverCount: this.client.guilds.size,
userCount: this.client.users.size,
serverCount: totalGuildCount,
userCount: totalUserCount,
uptime: process.uptime() * 1000,
commandCount: this.client.commands.length,
languageCount: Object.keys(i18next.store.data).length
Expand Down
1 change: 1 addition & 0 deletions src/listeners/MainListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ module.exports = class MainListener extends EventListener {
const cmd = fullCmd[0].toLowerCase().trim()
const command = this.commands.find(c => c.name.toLowerCase() === cmd || (c.aliases && c.aliases.includes(cmd)))
if (command) {
if (!message.channel.permissionsFor(this.user.id).has('SEND_MESSAGES')) return
Copy link
Member Author

Choose a reason for hiding this comment

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

I should add a message for no perms later but at least that's the thing whos gonna make the bot unbreakable when it has no perms

const userDocument = this.database && await this.database.users.findOne(message.author.id, 'blacklisted')
if (userDocument && userDocument.blacklisted) return

Expand Down
3 changes: 2 additions & 1 deletion src/locales/en-US/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@
"commandUsage": "[server id]",
"id": "ID",
"owner": "Owner",
"region": "Region",
"serverBoost": "Server Boost (**{{count}}**)",
"level": "Level: **{{count}}**",
"channels": "Channels **({{count}})**",
"textChannels": "Text: **{{count}}**",
"voiceChannels": "Voice: **{{count}}**",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/PermissionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module.exports = class PermissionUtils {
}

static specialRole (client, user) {
Doges marked this conversation as resolved.
Show resolved Hide resolved
const botGuild = client.guilds.cache.get(process.env.BOT_GUILD)
const member = botGuild && botGuild.members.cache.get(user.id)
const botGuild = client.guilds.fetch(process.env.BOT_GUILD)
const member = botGuild && botGuild.members.fetch(user.id)
Doges marked this conversation as resolved.
Show resolved Hide resolved
if (member) {
return member.roles.cache.filter(r => r.hoist).sort((a, b) => b.position - a.position).first()
}
Expand Down