File tree Expand file tree Collapse file tree 4 files changed +79
-1
lines changed Expand file tree Collapse file tree 4 files changed +79
-1
lines changed Original file line number Diff line number Diff line change 24
24
"lint" : " eslint --ext .ts ./src" ,
25
25
"lint:fix" : " eslint --ext .ts ./src --fix" ,
26
26
"generate" : " prisma generate" ,
27
- "migrate" : " prisma migrate deploy"
27
+ "migrate" : " prisma migrate deploy" ,
28
+ "role-metadata" : " tsx scripts/roleMetadata"
28
29
},
29
30
"dependencies" : {
30
31
"@influxdata/influxdb-client" : " 1.33.2" ,
Original file line number Diff line number Diff line change
1
+ import 'dotenv/config' ;
2
+
3
+ ( async ( ) => {
4
+ if ( ! process . env . DISCORD_APP_ID || ! process . env . DISCORD_BOT_TOKEN ) {
5
+ console . error ( 'No token and/or app ID provided.' ) ;
6
+ process . exit ( 1 ) ;
7
+ }
8
+
9
+ const ROLE_METADATA_URL = `https://discord.com/api/v10/applications/${ process . env . DISCORD_APP_ID } /role-connections/metadata` ;
10
+
11
+ const response = await fetch (
12
+ ROLE_METADATA_URL ,
13
+ { headers : { 'Authorization' : `Bot ${ process . env . DISCORD_BOT_TOKEN } ` } }
14
+ ) ;
15
+
16
+ if ( response . status !== 200 ) {
17
+ console . error ( 'Failed to fetch role metadata' , await response . text ( ) ) ;
18
+ process . exit ( 1 ) ;
19
+ }
20
+
21
+ const json = await response . json ( ) ;
22
+ if ( json . length !== 0 ) {
23
+ console . log ( 'Role metadata already applied.' )
24
+ } else {
25
+ const putResponse = await fetch (
26
+ ROLE_METADATA_URL ,
27
+ {
28
+ method : 'PUT' ,
29
+ headers : {
30
+ 'Authorization' : `Bot ${ process . env . DISCORD_BOT_TOKEN } ` ,
31
+ 'Content-Type' : 'application/json'
32
+ } ,
33
+ body : JSON . stringify ( [
34
+ {
35
+ key : "connected" ,
36
+ type : 7 ,
37
+ name : "Connected" ,
38
+ description : "The user has connected a Trello account"
39
+ }
40
+ ] )
41
+ }
42
+ ) ;
43
+
44
+ if ( putResponse . status === 200 ) {
45
+ console . log ( 'Updated role metadata.' )
46
+ } else {
47
+ console . error ( 'Failed to update role metadata' , await response . text ( ) ) ;
48
+ process . exit ( 1 ) ;
49
+ }
50
+ }
51
+ } ) ( ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { ComponentContext } from 'slash-create';
3
3
import { getData } from '../util' ;
4
4
import { ActionFunction , ActionType } from '../util/actions' ;
5
5
import { prisma } from '../util/prisma' ;
6
+ import { VERSION } from '../util/constants' ;
6
7
7
8
export const action : ActionFunction = {
8
9
type : ActionType . USER_CLEAR_AUTH ,
@@ -20,6 +21,18 @@ export const action: ActionFunction = {
20
21
where : { memberID : userData . trelloID } ,
21
22
data : { active : false , memberID : null }
22
23
} ) ;
24
+ if ( userData . discordToken )
25
+ await fetch ( `https://discord.com/api/users/@me/applications/${ process . env . DISCORD_APP_ID } /role-connection` , {
26
+ method : 'PUT' ,
27
+ headers : {
28
+ Authorization : `Bearer ${ userData . discordToken } ` ,
29
+ 'User-Agent' : `Taco (https://github.com/trello-talk/TacoInteractions, v${ VERSION } )` ,
30
+ 'Content-Type' : 'application/json'
31
+ } ,
32
+ body : JSON . stringify ( {
33
+ metadata : { connected : false }
34
+ } )
35
+ } ) ;
23
36
24
37
return void ctx . editParent ( { content : t ( 'clearauth.done' ) , components : [ ] } ) ;
25
38
}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { ComponentContext } from 'slash-create';
3
3
import { getData } from '../util' ;
4
4
import { ActionFunction , ActionType } from '../util/actions' ;
5
5
import { prisma } from '../util/prisma' ;
6
+ import { VERSION } from '../util/constants' ;
6
7
7
8
export const action : ActionFunction = {
8
9
type : ActionType . USER_CLEAR_DATA ,
@@ -21,6 +22,18 @@ export const action: ActionFunction = {
21
22
where : { memberID : userData . trelloID } ,
22
23
data : { active : false , memberID : null }
23
24
} ) ;
25
+ if ( userData . discordToken )
26
+ await fetch ( `https://discord.com/api/users/@me/applications/${ process . env . DISCORD_APP_ID } /role-connection` , {
27
+ method : 'PUT' ,
28
+ headers : {
29
+ Authorization : `Bearer ${ userData . discordToken } ` ,
30
+ 'User-Agent' : `Taco (https://github.com/trello-talk/TacoInteractions, v${ VERSION } )` ,
31
+ 'Content-Type' : 'application/json'
32
+ } ,
33
+ body : JSON . stringify ( {
34
+ metadata : { connected : false }
35
+ } )
36
+ } ) ;
24
37
25
38
return void ctx . editParent ( { content : t ( 'cleardata.done' ) , components : [ ] } ) ;
26
39
}
You can’t perform that action at this time.
0 commit comments