mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-01-11 02:16:26 +02:00
feat(api): generate missing icons
This commit is contained in:
parent
c6a982e702
commit
46bd58daf6
@ -1,3 +1,6 @@
|
|||||||
const { createHash } = require('crypto');
|
const { createHash } = require('crypto');
|
||||||
module.exports.md5 = str => createHash('md5').update(str).digest('hex');
|
module.exports.md5 = str => createHash('md5').update(str).digest('hex');
|
||||||
module.exports.msToMins = ms => Number((ms / 1000 / 60).toFixed(2));
|
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`;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* eslint-disable no-underscore-dangle */
|
/* eslint-disable no-underscore-dangle */
|
||||||
|
const { iconURL } = require('../../../../../lib/misc');
|
||||||
const {
|
const {
|
||||||
getAvgResolutionTime,
|
getAvgResolutionTime,
|
||||||
getAvgResponseTime,
|
getAvgResponseTime,
|
||||||
@ -37,7 +38,7 @@ module.exports.get = fastify => ({
|
|||||||
cached = {
|
cached = {
|
||||||
createdAt: settings.createdAt,
|
createdAt: settings.createdAt,
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
logo: guild.iconURL(),
|
logo: iconURL(guild),
|
||||||
name: guild.name,
|
name: guild.name,
|
||||||
stats: {
|
stats: {
|
||||||
avgResolutionTime: ms(getAvgResolutionTime(closedTickets)),
|
avgResolutionTime: ms(getAvgResolutionTime(closedTickets)),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const { PermissionsBitField } = require('discord.js');
|
const { PermissionsBitField } = require('discord.js');
|
||||||
|
const { iconURL } = require('../../../../lib/misc');
|
||||||
|
|
||||||
module.exports.get = fastify => ({
|
module.exports.get = fastify => ({
|
||||||
handler: async (req, res) => {
|
handler: async (req, res) => {
|
||||||
@ -10,7 +11,14 @@ module.exports.get = fastify => ({
|
|||||||
.map(guild => ({
|
.map(guild => ({
|
||||||
added: client.guilds.cache.has(guild.id),
|
added: client.guilds.cache.has(guild.id),
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
logo: `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.webp`,
|
logo: iconURL(
|
||||||
|
client.guilds.cache.get(guild.id) ||
|
||||||
|
{
|
||||||
|
client,
|
||||||
|
icon: guild.icon,
|
||||||
|
id: guild.id,
|
||||||
|
},
|
||||||
|
),
|
||||||
name: guild.name,
|
name: guild.name,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
16
src/routes/api/guilds/[guild]/index.js
Normal file
16
src/routes/api/guilds/[guild]/index.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
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);
|
||||||
|
if (!guild) return res.status(404).send(new Error('Not Found'));
|
||||||
|
res.send({
|
||||||
|
id: guild.id,
|
||||||
|
logo: iconURL(guild),
|
||||||
|
name: guild.name,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onRequest: [fastify.authenticate],
|
||||||
|
});
|
||||||
|
|
18
src/routes/api/guilds/index.js
Normal file
18
src/routes/api/guilds/index.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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(
|
||||||
|
guilds
|
||||||
|
.filter(guild => client.guilds.cache.has(guild.id))
|
||||||
|
.map(guild => ({
|
||||||
|
id: guild.id,
|
||||||
|
logo: iconURL(client.guilds.cache.get(guild.id)),
|
||||||
|
name: guild.name,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onRequest: [fastify.authenticate],
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user