-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_raid.js
More file actions
78 lines (60 loc) · 3.4 KB
/
remove_raid.js
File metadata and controls
78 lines (60 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************
* Author: Shawn Ray
* Date: 7/9/2020
* Github: https://github.com/Asmodasis
* Discord: https://discord.js.org/#/
* Filename: remove_raid.js
* Description: Module export function for assistance
*******************************************************************/
const fs = require('fs');
require('dotenv').config();
/*******************************************************************
* removeRaid
* fileName : the name of the file no extensions
* accessDate : the string for the raid date to access no spaces
* This function deletes a raid from the file (raid roster)
*******************************************************************/
module.exports = {
removeRaid: function (fileName, accessDate){
let contents = fs.readFileSync(fileName, 'utf8').split('\n')
if(accessDate == undefined)
throw 'Can not remove a raid without a proper raid attribute';
let raidArray = [];
let foundRow = 0; // how many cols are there in the file
let find = 0; // find locations
for(let elem = 0; elem < contents.length; elem++){ // split the file into an array for parsing
raidArray.push(contents[elem].replace('\n','').replace('\r','').split(','));
}
for(find = 0; find < contents.length;++find){
if(raidArray[find][0] == accessDate){ // date located
foundRow = find;
break;
}
}
if(find == contents.length) // full epoch, no attribute found
throw 'No attribute located, can\'t edit loot for a player without a proper raid attribute'; // no date located
let fileData = '';
for(let j = 0; j < raidArray.length; ++j){
if(foundRow == raidArray.length - 1){
if(!(j == foundRow)){
for(let i = 0; i < raidArray[0].length; ++i){
if(i == raidArray[0].length - 1) fileData += raidArray[j][i].toString();
else fileData += raidArray[j][i].toString()+',';
}
if(!((j == raidArray.length - 2))) fileData += '\n';
}
}else
if(!(j == foundRow)){
for(let i = 0; i < raidArray[0].length; ++i){
if(i == raidArray[0].length - 1) fileData += raidArray[j][i].toString();
else fileData += raidArray[j][i].toString()+',';
}
if(!((j == raidArray.length - 1))) fileData += '\n';
}
}
fs.writeFile(fileName, fileData, (err) => {
if(err) throw err;
})
throw ('The raid ' + accessDate + ' has been removed from the raid history.');
}
}