From 110cf40ebeace33c55c9bb7363503c7c8a19aaa9 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Sun, 24 Oct 2021 15:32:36 +0200 Subject: [PATCH] groups --- commands/ssps/cmd.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/commands/ssps/cmd.js b/commands/ssps/cmd.js index 83996c5..4797f5b 100644 --- a/commands/ssps/cmd.js +++ b/commands/ssps/cmd.js @@ -61,6 +61,7 @@ module.exports = class cmd extends commando.Command { connect [--discord ] - Connects discord and user profile teacher-connect - Connects discord and teacher profile set-teacher-room [email] [--force|-f] - Sets teacher's homeroom + groups [--user ] [--add |--remove ] - Manages groups `); case "connect": return this.connectCmd(argv, send, msg); @@ -68,11 +69,40 @@ module.exports = class cmd extends commando.Command { return this.teacherConnectCmd(argv, send, msg); case "set-teacher-room": return this.setTeacherRoomCmd(argv, send, msg); + case "groups": + return this.groupsCmd(argv, send, msg); default: return send(`Command ${argv._[0]} not found`); } } + async groupsCmd(argv, send, msg) { + if(argv.help) return send(` + Shows or update groups the user is part of. + User defaults to current user, but can be set by --user + + --add - Adds group (group must belong to current user's class). Use abbreviation + --remove - Removes group (can't be the special 'whole class' group). Use abbreviation. Can be list of comma separated values. + --user - Selects another user (owner only) + + Format: groups [--user ] [--add |--remove ] + `); + if(argv.add || argv.remove) return send("Not yet implemented"); + const person = await Person.findOne({ + where: { discord: argv.user || msg.author.id } + }); + if(!person) return send("Student nenalezen"); + const student = await Student.findOne({ + where: { personId: person.id } + }); + const groups = await student.getGroups(); + return send(` + Student je součástí těchto skupin: + + ${groups.map(t => `- ${t.abbrev} (${t.name})`).join("\n")} + `); + } + async setTeacherRoomCmd(argv, send, msg) { if(argv.help) return send(` Updates teacher room. @@ -171,7 +201,7 @@ module.exports = class cmd extends commando.Command { if(!student) return send("Student nenalezen. Momentálně je vyžadováno aby byl student registrovaný na profesní síti."); const userClass = ssps.getClass(msg.author); const classID = api.map[userClass]; - if(student.classId !== classID) return send(`Třída neodpovídá roli na SSPŠ serveru`); + if(student.classId && student.classId !== classID) return send(`Třída neodpovídá roli na SSPŠ serveru`); if(!student.personId) return send("Není vytvoření uživatelský profil - BUG"); const person = await Person.findOne({ where: { @@ -181,6 +211,8 @@ module.exports = class cmd extends commando.Command { if(person.mail !== email) return send("Student nenalezen."); person.discord = discord; await person.save(); + if(student.classId) await student.setClassID(student.classId, true); + await student.syncClass(); return send("Propojeno"); } }; \ No newline at end of file