Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Fixed a bug where if you were to record attendance twice in one day t…
Browse files Browse the repository at this point in the history
…hen you would record the same date multiple times. This however means that if you decide to record twice in one day it does not check if you have entered already that day.
  • Loading branch information
Gobluebro committed Jan 29, 2018
1 parent 05dcd8f commit d0612c4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
24 changes: 24 additions & 0 deletions commands/recordStart.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const fs = require('fs');

exports.run = (client, message, config) => {
if (config.isAutomated) {
return message.reply(
Expand All @@ -10,6 +12,28 @@ exports.run = (client, message, config) => {
} else {
config.attendanceArray = [];
config.isRecording = true;

var today = new Date();
var month = today.getMonth() + 1; //january is 0
var day = today.getDate(); //getday returns the day of the week.
var year = today.getFullYear(); //gets the 4 digit version
thisMonth = year + '-' + month;
thisDay = year + '/' + month + '/' + day;

fs.readFile('./logs/' + thisMonth + '.txt', 'utf-8', function(err, data) {
if (err) {
if (err.code === 'ENOENT') {
console.log('doesnt exist');
config.attendanceArray.unshift(thisDay);
}
} else {
console.log('exists');
var theFile = data.toString();
if (theFile.indexOf(thisDay) == -1) {
config.attendanceArray.unshift(thisDay);
}
}
});
//start the recording
return message.channel.send(
'Attendance recording has started. \n' +
Expand Down
2 changes: 0 additions & 2 deletions commands/recordStop.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ exports.run = (client, message, config) => {
var year = today.getFullYear(); //gets the 4 digit version
thisMonth = year + '-' + month;
thisDay = year + '/' + month + '/' + day;
//unshift brings the date to the front of the array
arrayAttendance.unshift(thisDay);

//w -open file for writing. the file is created (if it does not exist) or truncated (if it exists).
//wx - like w but fails if path exists.
Expand Down
1 change: 0 additions & 1 deletion commands/userRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ exports.run = (client, messsage, args) => {
//remove the user, remove the empty line, combine them together with the stuff before.
var removeUser = lastPartFile.replace(args[1], '');
var combine = firstPartFile + removeUser.replace(/(\r\n|\n|\r)/, '');
console.log(combine);
fs.writeFile('./logs/' + thisMonth + '.txt', combine, 'utf8', err => {
if (err) throw err;
return message.reply(
Expand Down

0 comments on commit d0612c4

Please sign in to comment.