delete file on bot command or when bot leaves the room

This commit is contained in:
Sharon Kennedy 2020-05-20 12:07:09 -04:00
parent f7da8fb2ac
commit 2c0e2f08c8

View File

@ -230,6 +230,9 @@ class OcrccBot {
case "transcript please": case "transcript please":
this.sendTranscript(senderId, roomId); this.sendTranscript(senderId, roomId);
break; break;
case "delete transcript":
this.deleteTranscript(senderId, roomId);
break;
case "hi": case "hi":
const responses = [ const responses = [
"Hi!", "Hi!",
@ -313,6 +316,38 @@ class OcrccBot {
} }
} }
deleteTranscript(senderId, roomId) {
const transcriptFile = this.localStorage.getItem(`${roomId}-transcript`)
if (!transcriptFile) {
return this.sendTextMessage(
roomId,
"There is no transcript for this chat.",
senderId
);
}
fs.unlink(transcriptFile, (err) => {
if (err) {
logger.log('error', "UNABLE TO DELETE TRANSCRIPT FILE => " + transcriptFile)
logger.log('error', err)
return this.sendTextMessage(
roomId,
`There was an error deleting the transcript: ${err}`,
senderId
);
}
this.localStorage.removeItem(`${roomId}-transcript`)
logger.log('info', "DELETED TRANSCRIPT FILE => " + transcriptFile)
this.sendTextMessage(
roomId,
`The transcript file has been deleted.`,
senderId
);
});
}
async deleteOldDevices() { async deleteOldDevices() {
const currentDeviceId = this.client.getDeviceId(); const currentDeviceId = this.client.getDeviceId();
const deviceData = await this.client.getDevices() const deviceData = await this.client.getDevices()
@ -429,11 +464,12 @@ class OcrccBot {
const memberCount = room.getJoinedMemberCount() const memberCount = room.getJoinedMemberCount()
if (memberCount === 1) { // just the bot if (memberCount === 1) { // just the bot left
logger.log("info", `LEAVING EMPTY ROOM ==> ${member.roomId}`); logger.log("info", `LEAVING EMPTY ROOM ==> ${member.roomId}`);
this.client.leave(member.roomId) this.deleteTranscript(member.userId, member.roomId);
this.localStorage.removeItem(`${member.roomId}-facilitator`) this.localStorage.removeItem(`${member.roomId}-facilitator`)
this.localStorage.removeItem(`${member.roomId}-transcript`) this.localStorage.removeItem(`${member.roomId}-transcript`)
this.client.leave(member.roomId)
} }
} }
}); });