File tree 5 files changed +48
-2
lines changed
5 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 1
1
const { createHash } = require ( 'crypto' ) ;
2
2
module . exports . md5 = str => createHash ( 'md5' ) . update ( str ) . digest ( 'hex' ) ;
3
3
module . exports . msToMins = ms => Number ( ( ms / 1000 / 60 ) . toFixed ( 2 ) ) ;
4
+ module . exports . iconURL = guildLike => guildLike . icon
5
+ ? guildLike . client . rest . cdn . icon ( guildLike . id , guildLike . icon )
6
+ : `https://api.dicebear.com/8.x/initials/png?seed=${ encodeURIComponent ( guildLike . name ) } &size=96&backgroundType=gradientLinear&fontWeight=600` ;
Original file line number Diff line number Diff line change 1
1
/* eslint-disable no-underscore-dangle */
2
+ const { iconURL } = require ( '../../../../../lib/misc' ) ;
2
3
const {
3
4
getAvgResolutionTime,
4
5
getAvgResponseTime,
@@ -37,7 +38,7 @@ module.exports.get = fastify => ({
37
38
cached = {
38
39
createdAt : settings . createdAt ,
39
40
id : guild . id ,
40
- logo : guild . iconURL ( ) ,
41
+ logo : iconURL ( guild ) ,
41
42
name : guild . name ,
42
43
stats : {
43
44
avgResolutionTime : ms ( getAvgResolutionTime ( closedTickets ) ) ,
Original file line number Diff line number Diff line change 1
1
const { PermissionsBitField } = require ( 'discord.js' ) ;
2
+ const { iconURL } = require ( '../../../../lib/misc' ) ;
2
3
3
4
module . exports . get = fastify => ( {
4
5
handler : async ( req , res ) => {
@@ -10,7 +11,14 @@ module.exports.get = fastify => ({
10
11
. map ( guild => ( {
11
12
added : client . guilds . cache . has ( guild . id ) ,
12
13
id : guild . id ,
13
- logo : `https://cdn.discordapp.com/icons/${ guild . id } /${ guild . icon } .webp` ,
14
+ logo : iconURL (
15
+ client . guilds . cache . get ( guild . id ) ||
16
+ {
17
+ client,
18
+ icon : guild . icon ,
19
+ id : guild . id ,
20
+ } ,
21
+ ) ,
14
22
name : guild . name ,
15
23
} ) ) ,
16
24
) ;
Original file line number Diff line number Diff line change
1
+ const { iconURL } = require ( '../../../../lib/misc' ) ;
2
+
3
+ module . exports . get = fastify => ( {
4
+ handler : async ( req , res ) => {
5
+ const { client } = req . routeOptions . config ;
6
+ const guild = client . guilds . cache . get ( req . params . guild ) ;
7
+ if ( ! guild ) return res . status ( 404 ) . send ( new Error ( 'Not Found' ) ) ;
8
+ res . send ( {
9
+ id : guild . id ,
10
+ logo : iconURL ( guild ) ,
11
+ name : guild . name ,
12
+ } ) ;
13
+ } ,
14
+ onRequest : [ fastify . authenticate ] ,
15
+ } ) ;
16
+
Original file line number Diff line number Diff line change
1
+ const { iconURL } = require ( '../../../lib/misc' ) ;
2
+
3
+ module . exports . get = fastify => ( {
4
+ handler : async ( req , res ) => {
5
+ const { client } = req . routeOptions . config ;
6
+ const guilds = await ( await fetch ( 'https://discordapp.com/api/users/@me/guilds' , { headers : { 'Authorization' : `Bearer ${ req . user . accessToken } ` } } ) ) . json ( ) ;
7
+ res . send (
8
+ guilds
9
+ . filter ( guild => client . guilds . cache . has ( guild . id ) )
10
+ . map ( guild => ( {
11
+ id : guild . id ,
12
+ logo : iconURL ( client . guilds . cache . get ( guild . id ) ) ,
13
+ name : guild . name ,
14
+ } ) ) ,
15
+ ) ;
16
+ } ,
17
+ onRequest : [ fastify . authenticate ] ,
18
+ } ) ;
You can’t perform that action at this time.
0 commit comments