creation-recipients.ts
1 import * as pronote from "../../src"; 2 import { credentials } from "../_credentials"; 3 4 void async function main () { 5 const session = pronote.createSessionHandle(); 6 await pronote.loginCredentials(session, { 7 url: credentials.pronoteURL, 8 kind: pronote.AccountKind.STUDENT, 9 username: credentials.username, 10 password: credentials.password, 11 deviceUUID: credentials.deviceUUID 12 }); 13 14 if (!session.user.authorizations.canDiscuss) 15 throw new Error("This account can't discuss, review the permissions."); 16 17 type Kinds = ( 18 | typeof pronote.EntityKind.Teacher 19 | typeof pronote.EntityKind.Personal 20 | typeof pronote.EntityKind.Student 21 ); 22 23 const kinds: Kinds[] = []; 24 25 if (session.user.authorizations.canDiscussWithStaff) { 26 console.info("+ Personal"); 27 kinds.push(pronote.EntityKind.Personal); 28 } 29 30 if (session.user.authorizations.canDiscussWithTeachers) { 31 console.info("+ Teacher"); 32 kinds.push(pronote.EntityKind.Teacher); 33 } 34 35 if (session.user.authorizations.canDiscussWithStudents) { 36 console.info("+ Student"); 37 kinds.push(pronote.EntityKind.Student); 38 } 39 40 const recipients = await Promise.all(kinds.map((kind) => pronote.newDiscussionRecipients(session, kind))); 41 const people = recipients.flat(); 42 43 for (const person of people) { 44 console.info(); // New line. 45 let typeName = "unknown"; 46 47 if (person.kind === pronote.EntityKind.Personal) typeName = "staff"; 48 else if (person.kind === pronote.EntityKind.Teacher) typeName = "teacher"; 49 else if (person.kind === pronote.EntityKind.Student) typeName = "student"; 50 51 console.info(`(${typeName}): ${person.name}`); 52 53 if (person.function) console.info("=>", person.function.name); 54 if (person.subjects.length > 0) console.info("=>", person.subjects.map((subject) => subject.name).join(", ")); 55 } 56 }();