-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.js
More file actions
115 lines (94 loc) · 3.29 KB
/
delete.js
File metadata and controls
115 lines (94 loc) · 3.29 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
THIS CODE WAS WRITTEN BY MODESTA THE GREAT
https://github.com/Modest4/russian-delete
_ _
| | | |
_ __ ___ ___ __| | ___ ___| |_ __ _
| '_ ` _ \ / _ \ / _` |/ _ \/ __| __/ _` |
| | | | | | (_) | (_| | __/\__ \ || (_| |
|_| |_| |_|\___/ \__,_|\___||___/\__\__,_|
_ _
/.) PRAY (.\
/)\| MODEST4 |/(\
//)/ \(\\
/'"^" "^"`\
*/
/*
Here are the differents levels available :
- pussy (potentially delete a random file in a specific folder) + Required path to folder
- russian-pussy (delete a random file or folder in a specific fodler) + Required path to folder
- cow-boy (potentially delete a random file somewhere)
- russian (delete a file)
- drunk-russian (delete a folder HELL YEA)
*/
const fs = require('fs-extra')
let Player = {
play : this.isFire() || return "You lucky bastard, not this time...",
levels : ["pussy", "russian-pussy", "cow-boy", "russian", "drunk-russian"],
level : this.levels[process.argv[2]],
dirPath : process.argv[3] || "./tmp",
isFire : () => {return Math.floor(Math.random() * 6) === 0},
delete : filePath => {
fs.remove(filePath, (err) => {
if (err) return console.log(err)
console.log(`${filePath} has been deleted`)
})
},
pickInFolder : (this.dirPath, (err, files) => {
if (err) return console.log(err)
let theFile = Math.floor(Math.random() * files.length)
console.log(`On va supprimer le fichier ${files[theFile]}`)
files.forEach((file, position) => {
let fullPath = dir + "/" + file
if(position === theFile) {
if (fs.lstatSync(fullPath).isFile()) { /* check if each of the content is a file */
deleteFile(fullPath, (err) => {
if (err) throw err
})
} else {
deleteFolder(fullPath)
}
}
})
})
}
if (Player.lvl === undefined) throw "What kind of game do you wanna play? Are you a pussy, a russian-pussy, a cow-boy, a russian or a drunk-russian ? How stupid are you dude?"
if (folderPath === undefined && lvl === levels[0] || folderPath === undefined && lvl === levels[1]) throw `You, ${lvl}, have to tell me in which folder I have to work`
let deleteFile = function(filePath) {
fs.remove(filePath, (err) => {
if (err) return err
})
console.log(`The file ${filePath} is now gone so far...`)
}
let deleteFolder = function(folderPath) {
fs.remove(folderPath, err => {
if (err) return console.log(err)
})
console.log(`The folder ${folderPath} is now gone so far...`)
}
fs.readdir(dir, (err, files) => {
if (err) throw err
let theFile = Math.floor(Math.random() * files.length)
console.log(`On va supprimer le fichier ${files[theFile]}`)
files.forEach((file, position) => {
let fullPath = dir + "/" + file
if(position === theFile) {
if (fs.lstatSync(fullPath).isFile()) { /* check if each of the content is a file */
deleteFile(fullPath, (err) => {
if (err) throw err
})
} else {
deleteFolder(fullPath)
}
}
})
})
/*
TODO
✓ Function for deleting files ✓
✓ Function for deleting folder ✓
✓ Function randomize isShot ? (1/6) ✓
✘ Move this into a module ✘
✘ Function to find a random folder from C ✘
❄ Create a module which recursively search a random place on the disk ❄
*/