mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 04:53:40 +08:00
share referral replies in the companion bot thread
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "990c033383dd223b6c93eb56e40576d6f83454dc2706bd9f239abdfa04799ce2", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "8611f529a0f5b51b7946c267ac89c8bb561d0161449af5dedd0df807200368d8", "schema_version": 1}
|
||||
|
||||
@@ -333,7 +333,11 @@ export function isReferral(i){
|
||||
return (i.type===2 && i.data?.type===3 && i.data.name===command) || (i.type===3 && /^refer:(leave|move|retry|ios|android):\d{17,20}$/.test(i.data?.custom_id||''));
|
||||
}
|
||||
export async function referralInteraction(i,env,ctx){
|
||||
const reply=text=>Response.json({type:4,data:privateCard(text)});
|
||||
const inReview=configured(env)&&i.guild_id===guild&&i.channel_id===env.COMPANION_REVIEW_THREAD_ID;
|
||||
const card=(text,controls=[])=>inReview
|
||||
? {...supportCard('',text,[],controls,0x5865f2),allowed_mentions:{parse:[]}}
|
||||
: privateCard(text,controls);
|
||||
const reply=text=>Response.json({type:4,data:card(text)});
|
||||
const manual=i.type===2;
|
||||
if(!configured(env)||i.guild_id!==guild||(!manual && i.channel_id!==env.COMPANION_REVIEW_THREAD_ID))return reply('Use the configured support review thread.');
|
||||
const settings=env.REPORTS.get(env.REPORTS.idFromName('companion-bot-setup'));
|
||||
@@ -350,8 +354,8 @@ export async function referralInteraction(i,env,ctx){
|
||||
const choices=result.choosePlatform?[['ios','iOS'],['android','Android']]:result.retryMove?[['retry','Retry creation']]:[];
|
||||
if(choices.length)controls=[{type:1,components:choices.map(([key,label])=>({type:2,style:2,label,custom_id:'refer:'+key+':'+source}))}];
|
||||
}finally{
|
||||
await fetch('https://discord.com/api/v10/webhooks/'+i.application_id+'/'+i.token+'/messages/@original',{method:'PATCH',headers:{'Content-Type':'application/json'},body:JSON.stringify({...privateCard(text,controls),content:null,embeds:[]})});
|
||||
await fetch('https://discord.com/api/v10/webhooks/'+i.application_id+'/'+i.token+'/messages/@original',{method:'PATCH',headers:{'Content-Type':'application/json'},body:JSON.stringify({...card(text,controls),content:null,embeds:[]})});
|
||||
}
|
||||
})());
|
||||
return Response.json({type:5,data:{flags:64}});
|
||||
return Response.json(inReview?{type:5}:{type:5,data:{flags:64}});
|
||||
}
|
||||
|
||||
@@ -211,3 +211,32 @@ test('lost acknowledgements recover the existing review card and Companion ticke
|
||||
assert.equal(rows.get(key).destination,dest);
|
||||
assert.equal(rows.get(key).platform,'android');
|
||||
});
|
||||
|
||||
test('review thread replies are shared from acknowledgement through final card; driving thread commands stay private',async t=>{
|
||||
const guild='1387432184121393333',review='1575000066366644244',source='1574085782967292086';
|
||||
const edits=[];
|
||||
t.mock.method(globalThis,'fetch',async(url,options)=>{
|
||||
assert.equal(options.method,'PATCH');
|
||||
edits.push(JSON.parse(options.body));
|
||||
return Response.json({});
|
||||
});
|
||||
const env={COMPANION_REVIEW_THREAD_ID:review,DRIVING_SAMPLE_THREAD_ID:source,
|
||||
REPORTS:{idFromName:name=>name,get:name=>({fetch:async()=>Response.json(name==='companion-bot-setup'?{id:'sage'}:{message:'Choose a platform',choosePlatform:true})})}};
|
||||
for(const inReview of [true,false]){
|
||||
const click={type:inReview?3:2,guild_id:guild,channel_id:inReview?review:source,member:{roles:['sage'],user:{id:source}},
|
||||
application_id:'app',token:'fixture',data:{custom_id:'refer:move:'+source}};
|
||||
let done;
|
||||
const ack=await (await referralInteraction(click,env,{waitUntil:job=>{done=job;}})).json();
|
||||
assert.equal(ack.type,5);
|
||||
assert.equal(Boolean(ack.data?.flags & 64),!inReview);
|
||||
await done;
|
||||
assert.equal(Boolean(edits.at(-1).flags & 64),!inReview);
|
||||
assert.deepEqual(edits.at(-1).allowed_mentions,{parse:[]});
|
||||
assert.equal(edits.at(-1).components[0].components[1].components.length,2);
|
||||
click.member.roles=[];
|
||||
const denied=await (await referralInteraction(click,env,{})).json();
|
||||
assert.equal(denied.type,4);
|
||||
assert.equal(Boolean(denied.data.flags & 64),!inReview);
|
||||
assert.match(JSON.stringify(denied.data),/requires StarPilot Sage/);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user