-
-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
149 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
const { createHash } = require('crypto'); | ||
module.exports.md5 = str => createHash('md5').update(str).digest('hex'); | ||
module.exports.msToMins = ms => Number((ms / 1000 / 60).toFixed(2)); | ||
module.exports.iconURL = guildLike => guildLike.icon | ||
? guildLike.client.rest.cdn.icon(guildLike.id, guildLike.icon) | ||
: `https://api.dicebear.com/8.x/initials/png?seed=${encodeURIComponent(guildLike.name)}&size=96&backgroundType=gradientLinear&fontWeight=600`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { getPrivilegeLevel } = require('../../../../lib/users'); | ||
const { iconURL } = require('../../../../lib/misc'); | ||
|
||
module.exports.get = fastify => ({ | ||
handler: async (req, res) => { | ||
const { client } = req.routeOptions.config; | ||
const guild = client.guilds.cache.get(req.params.guild); | ||
res.send({ | ||
id: guild.id, | ||
logo: iconURL(guild), | ||
name: guild.name, | ||
privilegeLevel: await getPrivilegeLevel(await guild.members.fetch(req.user.id)), | ||
}); | ||
}, | ||
onRequest: [fastify.authenticate, fastify.isMember], | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports.get = fastify => ({ | ||
handler: async (req, res) => { | ||
const { client } = req.routeOptions.config; | ||
/** @type {import("@prisma/client").PrismaClient} */ | ||
const prisma = client.prisma; | ||
const guild = client.guilds.cache.get(req.params.guild); | ||
res.send( | ||
await prisma.ticket.findMany({ | ||
where: { | ||
createdById: req.user.id, | ||
guildId: guild.id, | ||
}, | ||
}), | ||
); | ||
}, | ||
onRequest: [fastify.authenticate, fastify.isMember], | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { getPrivilegeLevel } = require('../../../lib/users'); | ||
const { iconURL } = require('../../../lib/misc'); | ||
|
||
module.exports.get = fastify => ({ | ||
handler: async (req, res) => { | ||
const { client } = req.routeOptions.config; | ||
const guilds = await (await fetch('https://discordapp.com/api/users/@me/guilds', { headers: { 'Authorization': `Bearer ${req.user.accessToken}` } })).json(); | ||
res.send( | ||
await Promise.all( | ||
guilds | ||
.filter(partialGuild => client.guilds.cache.has(partialGuild.id)) | ||
.map(async partialGuild => { | ||
const guild = client.guilds.cache.get(partialGuild.id); | ||
return { | ||
id: guild.id, | ||
logo: iconURL(guild), | ||
name: guild.name, | ||
privilegeLevel: await getPrivilegeLevel(await guild.members.fetch(req.user.id)), | ||
}; | ||
}), | ||
), | ||
); | ||
}, | ||
onRequest: [fastify.authenticate], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters