How to use fs.unlink method in Appium

Best JavaScript code snippet using appium

index.js

Source:index.js Github

copy

Full Screen

1const Discord = require("discord.js");2const client = new Discord.Client({autoReconnect: true, max_message_cache: 0});3const config = require("./config.json");4const fs = require("fs-extra");5const decache = require("decache");6const path = require("path");7const prefix = config.prefix;89client.on("ready", (message) => {10 const onReady = require("./onReady.js");11 onReady(message, client, fs)12});1314client.on("message", (message, channel) => {15 if (message.content.startsWith(prefix + "purge")) {16 if (message.channel.type === "dm") return;17 if(!message.guild.member(message.author).hasPermission("MANAGE_GUILD")) return message.reply("**:x: Vous n'avez pas la permission `manage-guild` dans ce serveur**").catch(console.error);1819 const user = message.mentions.users.first();20 const amount = !!parseInt(message.content.split(' ')[1]) ? parseInt(message.content.split(' ')[1]) : parseInt(message.content.split(' ')[2]) 21 if (!amount) return message.reply('**:x: Veuillez spécifier une limite de message**'); 22 if (!amount && !user) return message.reply('**:x: Veuillez spécifier une limite de message**');23 if (!user){24 if(isNaN(message.content.split(' ')[1]) || parseInt(message.content.split(' ')[1]) < 2 || parseInt(message.content.split(' ')[1]) > 100){25 message.channel.send('**:x: Veuillez spécifier une limite de message comprise entre 2 et 100**')26 }27 }28 29 if(message.content.split(' ')[2]){30 if(isNaN(message.content.split(' ')[2]) || parseInt(message.content.split(' ')[2]) < 2 || parseInt(message.content.split(' ')[2]) > 100){31 message.channel.send('**:x: Veuillez spécifier une limite de message comprise entre 2 et 100**')32 }33 }34 35 message.channel.fetchMessages({ limit: amount, })36 .then((messages) => {37 if (user) {38 const filterBy = user ? user.id : Client.user.id;39 messages = messages.filter(m => m.author.id === filterBy).array().slice(0, amount);40 }41 message.channel.bulkDelete(messages).catch(error => console.log(error.stack));42 message.channel.send(":wastebasket: | `" + amount + "` messages supprimés").then(msg => msg.delete(3000).catch(err => console.log(err)));4344 })4546 }47});4849client.on("guildMemberAdd", (member) => {50 var newMemberId = member.id;51 member.user.send(`**Bienvenue \`${member.user.username}\`**52Vous voici arriver sur **${member.guild.name}** !\n53Avant de pouvoir intégrer cette communauté, il va falloir s'en donner les moyens !\n54A tout instant dans le labyrinthe, vous pouvez utiliser la commande: **\`!choix\`**\nElle vous indiquera vos différentes possibilités en fonctions de l'emplacement où vous vous trouvez.\n55De même, la commande **\`!faire demi-tour\`** (ou **\`!faire demi tour\`**) vous permet de revenir à l'emplacement que vous occupiez précédemment de celui où vous vous trouvez.56Enfin, si vous souhaitez reprendre au choix des portes principales, la commande **\`!restart\`** vous sera d'une grande utilité...\n(elle pourrait bien s'avérer plus que nécessaire... :smirk: )\n57Si vous êtes de la partie, et lorsque vous y serez prêt,\nje vous invite à taper sur **>>> ${enterChan} <<<**\nla commande: **\`!start\`**\n58**La partie n'attend que vous \`${member.user.username}\`!**`)59});6061// START / RESTART & HELP USERS COMMANDS62client.on("message", (message, channel) => {6364 if ((message.author.bot)||(isReady == false)||(message == null)||(message == undefined)) return;6566 var cmd = message.content.slice(1);6768 if (message.content.startsWith(prefix) && (message.channel.id != "513786692964974594")) message.delete(500)6970 //71 if (message.channel.id == "513786692964974594") { // Bot DMs7273 if ((cmd == "restart") && !fs.existsSync(winUsersRep + message.author.id + '.js')) {74 message.channel.send(`vous souhaitez (re)commencer votre quête ?\n\nVous avez **30 secondes** pour retourner sur :\n\n**>>> ${enterChan} <<<**\n\nTapez-y la commande: **\`!restart\`**`)75 enterChan.overwritePermissions(message.author, { SEND_MESSAGES: true })76 setTimeout(function() {77 enterChan.overwritePermissions(message.author, { SEND_MESSAGES: false })78 }, 30 * 1000)7980 } else if ((cmd == "restart") && fs.existsSync(winUsersRep + message.author.id + '.js')) {81 message.channel.send(`**${message.author.username}** vous avez tapé la commande restart alors que vous êtes arrivé au bout du labyrinthe.82Vous avez **30 secondes** pour retourner sur :\n\n**>>> ${enterChan} <<<**\n\nTapez-y la commande: **\`!restart\`**`)83 enterChan.overwritePermissions(message.author, { SEND_MESSAGES: true })84 setTimeout(function() {85 enterChan.overwritePermissions(message.author, { SEND_MESSAGES: false })86 }, 30 * 1000)8788 }8990 }9192 if (message.channel.id == "513786692964974594") return;93 var member = message.guild.member(message.author);94 var msgChan = message.channel;95 var fileName = member.id + '.js';9697 // USERS START CMD 98 if ((message.channel == enterChan) && (cmd == 'start')) { // START USERS CMD99 const startCmd = require("./startCmd.js")100 startCmd(message, client, member, fs)101102 // RESTART CMD103 } else if (cmd == "restart") { // RESTART USERS CMD104 const restartCmd = require("./restartCmd.js")105 if (!fs.existsSync(winUsersRep + member.id + '.js')) {106 restartCmd(message, client, member, fs)107 } else {108 member.user.send(`**${member.user.username}** vous avez tapé la commande restart alors que vous êtes arrivé au bout du labyrinthe.109Afin de confirmer que ce choix n'a pas été effectué par inadvertance je vous invite à valider votre demande en tapant:\n**\`je veux recommencer le labyrinthe\`**`)110 }111112 } else if (cmd == "choix") { // DONNE LES DIFFERENTS CHOIX POSSIBLES EN FONCTION DU SALON OU L'UTILISATEUR SE TROUVE113 const choixCmd = require("./choixCmd.js")114 choixCmd(message, member)115116 } else if ((cmd == "faire demi-tour") || (cmd == "faire demi tour")) { // COME BACK USERS CMD117 const comebackCmd = require('./comebackCmd.js')118 comebackCmd(message, prefix, client, member, msgChan, cmd, fileName, fs)119 }120 121122 if ((msgChan == exitChan) && (cmd == enterChoice)) {123 if (member.roles.has(winRole.id)) member.remove(winRole.id).then(rmRole => {124 member.addRole(role_3I.id)125 fs.createFileSync(rep_3I + fileName)126 })127 }128129 if (msgChan == chanDoor1) {130131 if (!fs.existsSync(rep_1A + fileName) && !fs.existsSync(rep_1B + fileName)) { // Premier choix dans le labyrinthe132 if (cmd == choice_1A) {133 member.addRole(role_1A.id).then(addRole => {134 fs.createFileSync(rep_1A + fileName)135 setTimeout(function() {136 chan_1A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))137 if (member.roles.has(door1Role.id)) member.removeRole(door1Role.id)138 }, 1 * 1500)139 })140 } else if (cmd == choice_1B) {141 member.addRole(role_1B.id).then(addRole => {142 fs.createFileSync(rep_1B + fileName)143 setTimeout(function() {144 if (member.roles.has(door1Role.id)) member.removeRole(door1Role.id)145 }, 1 * 1500)146 })147 }148149 } else if (fs.existsSync(rep_1A + fileName)) { // l'utilisateur vient du salon 1A150 if (cmd == choice_1A) {151 member.addRole(role_1A.id).then(addRole => {152 fs.createFileSync(door1UsersRep + fileName)153 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);154 setTimeout(function() {155 chan_1A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))156 if (member.roles.has(door1Role.id)) member.removeRole(door1Role.id)157 }, 1 * 1500)158 })159 } else if (cmd == choice_1B) {160 member.addRole(role_1B.id).then(addRole => {161 fs.createFileSync(rep_1B + fileName)162 if (fs.existsSync(rep_1A + fileName)) fs.unlinkSync(rep_1A + fileName);163 setTimeout(function() {164 if (member.roles.has(door1Role.id)) member.removeRole(door1Role.id)165 }, 1 * 1500)166 })167 }168169 } else if (fs.existsSync(rep_1B + fileName)) { // l'utilisateur vient du salon 1B170 if (cmd == choice_1A) {171 member.addRole(role_1A.id).then(addRole => {172 fs.createFileSync(rep_1A + fileName)173 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);174 setTimeout(function() {175 chan_1A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))176 if (member.roles.has(door1Role.id)) member.removeRole(door1Role.id)177 }, 1 * 1500)178 })179 } else if (cmd == choice_1B) {180 member.addRole(role_1B.id).then(addRole => {181 fs.createFileSync(rep_1B + fileName)182 if (fs.existsSync(rep_1A + fileName)) fs.unlinkSync(rep_1A + fileName);183 setTimeout(function() {184 if (member.roles.has(door1Role.id)) member.removeRole(door1Role.id)185 }, 1 * 1500)186 })187 }188189 }190 191 } else if (msgChan == chanDoor2) {192193 if (!fs.existsSync(rep_2A + fileName) && !fs.existsSync(rep_2B + fileName)) { // Premier choix dans le labyrinthe194 if (cmd == choice_2A) {195 member.addRole(role_2A.id).then(addRole => {196 fs.createFileSync(rep_2A + fileName)197 setTimeout(function() {198 if (member.roles.has(door2Role.id)) member.removeRole(door2Role.id)199 }, 1 * 1500)200 })201 } else if (cmd == choice_2B) {202 member.addRole(role_2B.id).then(addRole => {203 fs.createFileSync(rep_2B + fileName)204 setTimeout(function() {205 if (member.roles.has(door2Role.id)) member.removeRole(door2Role.id)206 }, 1 * 1500)207 })208 }209 210211 } else if (fs.existsSync(rep_2A + fileName)) {212 if (cmd == choice_2A) {213 member.addRole(role_2A.id).then(addRole => {214 fs.createFileSync(door2UsersRep + fileName)215 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);216 setTimeout(function() {217 if (member.roles.has(door2Role.id)) member.removeRole(door2Role.id)218 }, 1 * 1500)219 })220 } else if (cmd == choice_2B) {221 member.addRole(role_2B.id).then(addRole => {222 fs.createFileSync(rep_2B + fileName)223 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);224 setTimeout(function() {225 if (member.roles.has(door2Role.id)) member.removeRole(door2Role.id)226 }, 1 * 1500)227 })228 }229230 } else if (fs.existsSync(rep_2B + fileName)) {231 if (cmd == choice_2A) {232 member.addRole(role_2A.id).then(addRole => {233 fs.createFileSync(rep_2A + fileName)234 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);235 setTimeout(function() {236 if (member.roles.has(door2Role.id)) member.removeRole(door2Role.id)237 }, 1 * 1500)238 })239 } else if (cmd == choice_2B) {240 member.addRole(role_2B.id).then(addRole => {241 fs.createFileSync(rep_2B + fileName)242 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);243 setTimeout(function() {244 if (member.roles.has(door2Role.id)) member.removeRole(door2Role.id)245 }, 1 * 1500)246 })247 }248249 }250 251 } else if (msgChan == chanDoor3) {252253 if (!fs.existsSync(rep_3A + fileName) && !fs.existsSync(rep_3B + fileName)) { // Premier choix dans le labyrinthe254 if (cmd == choice_3A) {255 member.addRole(role_3A.id).then(addRole => {256 fs.createFileSync(rep_3A + fileName)257 setTimeout(function() {258 chan_3A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))259 if (member.roles.has(door3Role.id)) member.removeRole(door3Role.id)260 }, 1 * 1500)261 })262 } else if (cmd == choice_3B) {263 member.addRole(role_3B.id).then(addRole => {264 fs.createFileSync(rep_3B + fileName)265 setTimeout(function() {266 if (member.roles.has(door3Role.id)) member.removeRole(door3Role.id)267 }, 1 * 1500)268 })269 }270 if (member.roles.has(door1Role.id)) member.removeRole(door1Role.id)271272 } else if (fs.existsSync(rep_3A + fileName)) { // l'utilisateur vient du salon 3A273 if (cmd == choice_3A) {274 member.addRole(role_3A.id).then(addRole => {275 fs.createFileSync(door3UsersRep + fileName)276 if (fs.existsSync(rep_3B + fileName)) fs.unlinkSync(rep_3B + fileName);277 setTimeout(function() {278 chan_3A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))279 if (member.roles.has(door3Role.id)) member.removeRole(door3Role.id)280 }, 1 * 1500)281 })282 } else if (cmd == choice_3B) {283 member.addRole(role_3B.id).then(addRole => {284 fs.createFileSync(rep_3B + fileName)285 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);286 setTimeout(function() {287 if (member.roles.has(door3Role.id)) member.removeRole(door3Role.id)288 }, 1 * 1500)289 })290 }291292 } else if (fs.existsSync(rep_3B + fileName)) { // l'utilisateur vient du salon 3B293 if (cmd == choice_3A) {294 member.addRole(role_3A.id).then(addRole => {295 fs.createFileSync(rep_3A + fileName)296 if (fs.existsSync(rep_3B + fileName)) fs.unlinkSync(rep_3B + fileName);297 setTimeout(function() {298 chan_3A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))299 if (member.roles.has(door3Role.id)) member.removeRole(door3Role.id)300 }, 1 * 1500)301 })302 } else if (cmd == choice_3B) {303 member.addRole(role_3B.id).then(addRole => {304 fs.createFileSync(rep_3B + fileName)305 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);306 setTimeout(function() {307 if (member.roles.has(door3Role.id)) member.removeRole(door3Role.id)308 }, 1 * 1500)309 })310 }311312 }313 314 } else if (msgChan == chanDoor4) {315316 if (!fs.existsSync(rep_4A + fileName) && !fs.existsSync(rep_4B + fileName)) { // Premier choix dans le labyrinthe317 if (cmd == choice_4A) {318 member.addRole(role_4A.id).then(addRole => {319 fs.createFileSync(rep_4A + fileName)320 setTimeout(function() {321 chan_4A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))322 if (member.roles.has(door4Role.id)) member.removeRole(door4Role.id)323 }, 1 * 1500)324 })325 } else if (cmd == choice_4B) {326 member.addRole(role_4B.id).then(addRole => {327 fs.createFileSync(rep_4B + fileName)328 setTimeout(function() {329 if (member.roles.has(door4Role.id)) member.removeRole(door4Role.id)330 }, 1 * 1500)331 })332 }333334 } else if (fs.existsSync(rep_4A + fileName)) { // l'utilisateur vient du salon 4A335 if (cmd == choice_4A) {336 member.addRole(role_4A.id).then(addRole => {337 fs.createFileSync(rep_4A + fileName)338 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);339 setTimeout(function() {340 chan_4A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))341 if (member.roles.has(door4Role.id)) member.removeRole(door4Role.id)342 }, 1 * 1500)343 })344 } else if (cmd == choice_4B) {345 member.addRole(role_4B.id).then(addRole => {346 fs.createFileSync(rep_4B + fileName)347 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);348 setTimeout(function() {349 if (member.roles.has(door4Role.id)) member.removeRole(door4Role.id)350 }, 1 * 1500)351 })352 }353354 } else if (fs.existsSync(rep_4B + fileName)) { // l'utilisateur vient du salon 4B355 if (cmd == choice_4A) {356 member.addRole(role_4A.id).then(addRole => {357 fs.createFileSync(rep_4A + fileName)358 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);359 setTimeout(function() {360 chan_4A.send(`cul de sac... faire demi tour`).then(ans => ans.delete(5000))361 if (member.roles.has(door4Role.id)) member.removeRole(door4Role.id)362 }, 1 * 1500)363 })364 } else if (cmd == choice_4B) {365 member.addRole(role_4B.id).then(addRole => {366 fs.createFileSync(rep_4B + fileName)367 if (fs.existsSync(rep_4A + fileName)) fs.unlinkSync(rep_4A + fileName);368 setTimeout(function() {369 if (member.roles.has(door4Role.id)) member.removeRole(door4Role.id)370 }, 1 * 1500)371 })372 }373374 }375 376 }377 378});379380381382// LABYRINTHE PART 1383client.on("message", (message) => {384 if ((message.author.bot)||(isReady == false)||(message == null)||(message == undefined)) return;385 if (message.channel.id == "513786692964974594") return;386 var member = message.guild.member(message.author);387 var cmd = message.content.slice(1);388 var fileName = member.id + '.js';389 var congratMsg = `**${member}**, félicitations ! Vous venez de découvrir la porte d'entrée du discord !\nPour entrer... **\`!entrer\`**\nLes membres présents ont été prévenus de votre arrivée soudaine, vous êtes à présent convié(e) à vous faire votre petite place parmis nous ! ^^\n390En vous souhaitant la bienvenue par avance, je vous souhaite une bonne installation au nom de la communauté !`;391392 if ((message.channel == chan_1B) && ((cmd == choice_1C)||(cmd == choice_1D)||(cmd == choice_1A)||(cmd == choice_1))) { // CHAN_1B393394 if (cmd == choice_1C) { // PIEGE ICI395 member.addRole(role_1C.id).then(addRole => {396 fs.createFileSync(rep_1C + fileName)397 if (fs.existsSync(door1UsersRep + fileName)) fs.unlinkSync(door1UsersRep + fileName);398 if (fs.existsSync(rep_1A + fileName)) fs.unlinkSync(rep_1A + fileName);399 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);400 })401 } else if (cmd == choice_1D) {402 member.addRole(role_1D.id).then(addRole => {403 fs.createFileSync(rep_1D + fileName)404 if (fs.existsSync(door1UsersRep + fileName)) fs.unlinkSync(door1UsersRep + fileName);405 if (fs.existsSync(rep_1A + fileName)) fs.unlinkSync(rep_1A + fileName);406 })407 } else if (cmd == choice_1A) {408 member.addRole(role_1A.id).then(addRole => {409 fs.createFileSync(rep_1A + fileName)410 if (fs.existsSync(door1UsersRep + fileName)) fs.unlinkSync(door1UsersRep + fileName);411 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);412 })413 } else if (cmd == choice_1) {414 member.addRole(door1Role.id).then(addRole => {415 fs.createFileSync(door1UsersRep + fileName)416 if (fs.existsSync(rep_1A + fileName)) fs.unlinkSync(rep_1A + fileName);417 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);418 })419420 }421 if (member.roles.has(role_1B.id)) member.removeRole(role_1B.id);422423 }424425 if ((message.channel == chan_1D) && ((cmd == choice_1E)||(cmd == choice_1F)||(cmd == choice_1B)||(cmd == choice_1C))) { // CHAN_1D426 427 if (cmd == choice_1E) {428 member.addRole(role_1E.id).then(addRole => {429 fs.createFileSync(rep_1E + fileName)430 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);431 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);432 })433 } else if (cmd == choice_1F) {434 member.addRole(role_1F.id).then(addRole => {435 fs.createFileSync(rep_1F + fileName)436 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);437 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);438 })439 } else if (cmd == choice_1B) {440 member.addRole(role_1B.id).then(addRole => {441 fs.createFileSync(rep_1B + fileName)442 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);443 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);444 })445 } else if (cmd == choice_1C) {446 member.addRole(role_1C.id).then(addRole => {447 fs.createFileSync(rep_1C + fileName)448 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);449 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);450 })451 }452 if (member.roles.has(role_1D.id)) member.removeRole(role_1D.id);453454 }455456 if ((message.channel == chan_1F) && ((cmd == choice_2A)||(cmd == choice_2C)||(cmd == choice_1D)||(cmd == choice_1E))) { // CHAN_1F457 458 if (cmd == choice_2A) member.addRole(role_2A.id).then(addRole => {459 fs.createFileSync(rep_2A + fileName)460 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);461 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);462 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);463 })464 if (cmd == choice_2C) member.addRole(role_2C.id).then(addRole => {465 fs.createFileSync(rep_2C + fileName)466 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);467 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);468 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);469 })470 if (cmd == choice_1D) member.addRole(role_2A.id).then(addRole => {471 fs.createFileSync(rep_1D + fileName)472 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);473 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);474 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);475 })476 if (cmd == choice_1E) member.addRole(role_2C.id).then(addRole => {477 fs.createFileSync(rep_1E + fileName)478 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);479 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);480 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);481 })482 if (member.roles.has(role_1F.id)) member.removeRole(role_1F.id);483484 }485486});487488// LABYRINTHE PART 2489client.on("message", (message) => {490491 if ((message.author.bot)||(isReady == false)||(message == null)||(message == undefined)) return;492 if (message.channel.id == "513786692964974594") return;493 var member = message.guild.member(message.author);494 var cmd = message.content.slice(1);495 var fileName = member.id + '.js';496497 if ((message.channel == chan_2A) && ((cmd == choice_1F)||(cmd == choice_2C)||(cmd == choice_2B)||(cmd == choice_2))) { // CHAN_2A498499 if (cmd == choice_1F) member.addRole(role_1F).then(addRole => {500 fs.createFileSync(rep_1F + fileName)501 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);502 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);503 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);504 })505 if (cmd == choice_2C) member.addRole(role_2C).then(addRole => {506 fs.createFileSync(rep_2C + fileName)507 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);508 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);509 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);510 })511 if (cmd == choice_2B) member.addRole(role_2B).then(addRole => {512 fs.createFileSync(rep_2B + fileName)513 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);514 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);515 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);516 })517 if (cmd == choice_2) member.addRole(role_2C).then(addRole => {518 fs.createFileSync(rep_2C + fileName)519 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);520 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);521 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);522 })523 if (member.roles.has(role_2A.id)) member.removeRole(role_2A.id);524 }525526 if ((message.channel == chan_2B) && ((cmd == choice_2C)||(cmd == choice_2D)||(cmd == choice_2A)||(cmd == choice_2))) { // CHAN_2B527 if (cmd == choice_2C) member.addRole(role_2C).then(addRole => {528 fs.createFileSync(rep_2C + fileName)529 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);530 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);531 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);532 })533 if (cmd == choice_2D) member.addRole(role_2D).then(addRole => {534 fs.createFileSync(rep_2D + fileName)535 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);536 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);537 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);538 })539 if (cmd == choice_2A) member.addRole(role_2A).then(addRole => {540 fs.createFileSync(rep_2A + fileName)541 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);542 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);543 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);544 })545 if (cmd == choice_2) member.addRole(door2Role).then(addRole => {546 fs.createFileSync(door2UsersRep + fileName)547 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);548 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);549 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);550 })551 if (member.roles.has(role_2B.id)) member.removeRole(role_2B.id);552 }553554 if ((message.channel == chan_2C) && ((cmd == choice_1F)||(cmd == choice_2A)||(cmd == choice_2B)||(cmd == choice_2D))) { // CHAN_2C555 if (cmd == choice_1F) member.addRole(role_1F).then(addRole => {556 fs.createFileSync(rep_1F + fileName)557 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);558 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);559 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);560 })561 if (cmd == choice_2A) member.addRole(role_2A).then(addRole => {562 fs.createFileSync(rep_2A + fileName)563 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);564 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);565 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);566 })567 if (cmd == choice_2B) member.addRole(role_2B).then(addRole => {568 fs.createFileSync(rep_2B + fileName)569 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);570 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);571 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);572 })573 if (cmd == choice_2D) member.addRole(role_2D).then(addRole => {574 fs.createFileSync(rep_2D + fileName)575 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);576 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);577 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);578 })579 if (member.roles.has(role_2C.id)) member.removeRole(role_2C.id);580 }581582 if ((message.channel == chan_2D) && ((cmd == choice_2E)||(cmd == choice_2F)||(cmd == choice_2B)||(cmd == choice_2C))) { // CHAN_2D583 if (cmd == choice_2E) member.addRole(role_2E).then(addRole => {584 fs.createFileSync(rep_2E + fileName)585 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);586 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);587 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);588 })589 if (cmd == choice_2F) member.addRole(role_2F).then(addRole => {590 fs.createFileSync(rep_2F + fileName)591 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);592 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);593 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);594 })595 if (cmd == choice_2B) member.addRole(role_2B).then(addRole => {596 fs.createFileSync(rep_2B + fileName)597 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);598 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);599 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);600 })601 if (cmd == choice_2C) member.addRole(role_2C).then(addRole => {602 fs.createFileSync(rep_2C + fileName)603 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);604 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);605 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);606 })607 if (member.roles.has(role_2D.id)) member.removeRole(role_2D.id);608 }609610 if ((message.channel == chan_2E) && ((cmd == choice_2I)||(cmd == choice_3H)||(cmd == choice_2D)||(cmd == choice_2F))) {// CHAN_2E611 if (cmd == choice_2I) member.addRole(role_2I).then(addRole => {612 fs.createFileSync(rep_2I + fileName)613 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);614 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);615 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);616 })617 if (cmd == choice_3H) member.addRole(role_3H).then(addRole => {618 fs.createFileSync(rep_3H + fileName)619 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);620 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);621 })622 if (cmd == choice_2D) member.addRole(role_2D).then(addRole => {623 fs.createFileSync(rep_2D + fileName)624 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);625 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);626 })627 if (cmd == choice_2F) member.addRole(role_2F).then(addRole => {628 fs.createFileSync(rep_2F + fileName)629 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);630 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);631 })632 if (member.roles.has(role_2E.id)) member.removeRole(role_2E.id);633 }634635 if ((message.channel == chan_2F) && ((cmd == choice_2G)||(cmd == choice_2H)||(cmd == choice_2E)||(cmd == choice_2D))) { // CHAN_2F636 if (cmd == choice_2G) member.addRole(role_2G).then(addRole => {637 fs.createFileSync(rep_2G + fileName)638 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);639 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);640 if (fs.existsSync(rep_2H + fileName)) fs.unlinkSync(rep_2H + fileName);641 })642 if (cmd == choice_2H) member.addRole(role_2H).then(addRole => {643 fs.createFileSync(rep_2H + fileName)644 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);645 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);646 })647 if (cmd == choice_2E) member.addRole(role_2E).then(addRole => {648 fs.createFileSync(rep_2E + fileName)649 if (fs.existsSync(rep_2H + fileName)) fs.unlinkSync(rep_2H + fileName);650 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);651 })652 if (cmd == choice_2D) member.addRole(role_2D).then(addRole => {653 fs.createFileSync(rep_2D + fileName)654 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);655 if (fs.existsSync(rep_2H + fileName)) fs.unlinkSync(rep_2H + fileName);656 })657 if (member.roles.has(role_2F.id)) member.removeRole(role_2F.id);658 }659660});661662// LABYRINTHE PART 3663client.on("message", (message) => {664665 if ((message.author.bot)||(isReady == false)||(message == null)||(message == undefined)) return;666 if (message.channel.id == "513786692964974594") return;667 var member = message.guild.member(message.author);668 var cmd = message.content.slice(1); 669 var fileName = member.id + '.js';670671 if ((message.channel == chan_3B) && ((cmd == choice_3C)||(cmd == choice_3D)||(cmd == choice_3A)||(cmd == choice_3))) { // CHAN_3B672673 if (cmd == choice_3C) member.addRole(role_3C).then(addRole => {674 fs.createFileSync(rep_3C + fileName)675 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);676 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);677 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);678 })679 if (cmd == choice_3D) member.addRole(role_3D).then(addRole => {680 fs.createFileSync(rep_3D + fileName)681 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);682 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);683 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);684 })685 if (cmd == choice_3A) member.addRole(role_3A).then(addRole => {686 fs.createFileSync(rep_3A + fileName)687 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);688 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);689 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);690 })691 if (cmd == choice_3) member.addRole(door3Role).then(addRole => {692 fs.createFileSync(door3UsersRepou + fileName)693 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);694 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);695 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);696 })697 if (member.roles.has(role_3B.id)) member.removeRole(role_3B.id);698699 } else if ((message.channel == chan_3D) && ((cmd == choice_3E)||(cmd == choice_3F)||(cmd == choice_3C)||(cmd == choice_3B))) { // CHAN_3D700701 if (cmd == choice_3E) member.addRole(role_3E).then(addRole => {702 fs.createFileSync(rep_3E + fileName)703 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);704 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);705 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);706 })707 if (cmd == choice_3F) member.addRole(role_3F).then(addRole => {708 fs.createFileSync(rep_3F + fileName)709 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);710 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);711 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);712 })713 if (cmd == choice_3C) member.addRole(role_3C).then(addRole => {714 fs.createFileSync(rep_3C + fileName)715 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);716 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);717 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);718 })719 if (cmd == choice_3B) member.addRole(door3Role).then(addRole => {720 fs.createFileSync(rep_3B + fileName)721 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);722 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);723 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);724 })725 if (member.roles.has(role_3D.id)) member.removeRole(role_3D.id);726727 } else if ((message.channel == chan_3F) && ((cmd == choice_3G)||(cmd == choice_3H)||(cmd == choice_3E)||(cmd == choice_3D))) { // CHAN_3D728729 if (cmd == choice_3G) member.addRole(role_3G).then(addRole => {730 fs.createFileSync(rep_3G + fileName)731 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);732 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);733 })734 if (cmd == choice_3H) member.addRole(role_3H).then(addRole => {735 fs.createFileSync(rep_3H + fileName)736 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);737 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);738 })739 if (cmd == choice_3E) member.addRole(role_3E).then(addRole => {740 fs.createFileSync(rep_3E + fileName)741 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);742 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);743 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);744 })745 if (cmd == choice_3D) member.addRole(rep_3D).then(addRole => {746 fs.createFileSync(rep_3D + fileName)747 if (fs.existsSync(rep_3B + fileName)) fs.unlinkSync(rep_3B + fileName);748 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);749 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);750 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);751 })752 if (member.roles.has(role_3F.id)) member.removeRole(role_3F.id);753754 } else if ((message.channel == chan_3G) && ((cmd == choice_3I)||(cmd == choice_3J)||(cmd == choice_3H)||(cmd == choice_3F))) { // CHAN_3G755756 if (cmd == choice_3I) member.addRole(role_3I).then(addRole => { // VICTOIRE !!!757 fs.createFileSync(rep_3I + fileName)758 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);759 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);760 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);761 setTimeout(function() {762 chan_3I.send(congratMsg)763 }, 1 * 1500)764 })765 if (cmd == choice_3J) member.addRole(role_3J).then(addRole => {766 fs.createFileSync(rep_3J + fileName)767 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);768 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);769 if (fs.existsSync(rep_3I + fileName)) fs.unlinkSync(rep_3I + fileName);770 })771 if (cmd == choice_3H) member.addRole(role_3H).then(addRole => {772 fs.createFileSync(rep_3H + fileName)773 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);774 if (fs.existsSync(rep_3I + fileName)) fs.unlinkSync(rep_3I + fileName);775 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);776 })777 if (cmd == choice_3F) member.addRole(rep_3F).then(addRole => {778 fs.createFileSync(rep_3F + fileName)779 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);780 if (fs.existsSync(rep_3I + fileName)) fs.unlinkSync(rep_3I + fileName);781 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);782 })783 if (member.roles.has(role_3G.id)) member.removeRole(role_3G.id);784785 } else if ((message.channel == chan_3H) && ((cmd == choice_2E)||(cmd == choice_2I)||(cmd == choice_3G)||(cmd == choice_3F))) { // CHAN_3H786787 if (cmd == choice_2E) member.addRole(role_2E).then(addRole => {788 fs.createFileSync(rep_2E + fileName)789 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);790 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_3F + fileName);791 })792 if (cmd == choice_2I) member.addRole(role_2I).then(addRole => {793 fs.createFileSync(rep_2I + fileName)794 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);795 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);796 if (fs.existsSync(rep_3E + fileName)) fs.unlinkSync(rep_2E + fileName);797 })798 if (cmd == choice_3G) member.addRole(role_3G).then(addRole => {799 fs.createFileSync(rep_3G + fileName)800 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);801 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);802 })803 if (cmd == choice_3F) member.addRole(rep_3F).then(addRole => {804 fs.createFileSync(rep_3F + fileName)805 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);806 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);807 })808 if (member.roles.has(role_3H.id)) member.removeRole(role_3H.id);809810 } else if ((message.channel == chan_3I) && (cmd == enterChoice)) {811 fs.createFileSync(winUsersRep + fileName)812 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);813 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);814 if (fs.existsSync(startedUsersRep + fileName)) fs.unlinkSync(startedUsersRep + fileName);815 member.addRole(winRole.id).then(addRole => {816 labyMainRolesList.forEach(role => {817 if (member.roles.has(role.id)) member.removeRole(role.id) && console.log(` Il a perdu le rôle ${role.name}`)818 })819 labyRolesList.forEach(role => {820 if (member.roles.has(role.id)) member.removeRole(role.id) && console.log(` Il a perdu le rôle ${role.name}`)821 })822 })823 824 } else if ((message.channel == chan_3J) && ((cmd == choice_3K)||(cmd == choice_3L)||(cmd == choice_3G)||(cmd == choice_3I))) { // CHAN_3H825826 if (cmd == choice_3K) member.addRole(role_3K).then(addRole => {827 fs.createFileSync(rep_3K + fileName)828 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);829 if (fs.existsSync(rep_3I + fileName)) fs.unlinkSync(rep_3I + fileName);830 })831 if (cmd == choice_3L) member.addRole(role_3L).then(addRole => {832 fs.createFileSync(rep_3L + fileName)833 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);834 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);835 if (fs.existsSync(rep_3E + fileName)) fs.unlinkSync(rep_2E + fileName);836 })837 if (cmd == choice_3G) member.addRole(role_3G).then(addRole => {838 fs.createFileSync(rep_3G + fileName)839 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);840 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);841 })842 if (cmd == choice_3I) member.addRole(rep_3I).then(addRole => { // VICTOIRE !!!843 fs.createFileSync(rep_3I + fileName)844 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);845 setTimeout(function() {846 chan_3I.send(congratMsg)847 }, 1 * 1500)848 })849 if (member.roles.has(role_3J.id)) member.removeRole(role_3J.id);850851 }852853});854855// LABYRINTHE PART 4856client.on("message", (message) => {857858 if ((message.author.bot)||(isReady == false)||(message == null)||(message == undefined)) return;859 if (message.channel.id == "513786692964974594") return;860 var member = message.guild.member(message.author);861 var cmd = message.content.slice(1);862 var fileName = member.id + '.js';863864 if ((message.channel == chan_4B) && ((cmd == choice_4C)||(cmd == choice_4D)||(cmd == choice_4A)||(cmd == choice_4))) { // CHAN_4B865866 if (cmd == choice_4C) member.addRole(role_4C).then(addRole => {867 fs.createFileSync(rep_4C + fileName)868 if (fs.existsSync(door4UsersRep + fileName)) fs.unlinkSync(door4UsersRep + fileName);869 if (fs.existsSync(rep_4A + fileName)) fs.unlinkSync(rep_4A + fileName);870 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);871 })872 if (cmd == choice_4D) member.addRole(role_4D).then(addRole => {873 fs.createFileSync(rep_4D + fileName)874 if (fs.existsSync(door4UsersRep + fileName)) fs.unlinkSync(door4UsersRep + fileName);875 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);876 if (fs.existsSync(rep_4A + fileName)) fs.unlinkSync(rep_4A + fileName);877 })878 if (cmd == choice_4A) member.addRole(role_4A).then(addRole => {879 fs.createFileSync(rep_4A + fileName)880 if (fs.existsSync(door4UsersRep + fileName)) fs.unlinkSync(door4UsersRep + fileName);881 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);882 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);883 })884 if (cmd == choice_4) member.addRole(door4Role).then(addRole => {885 fs.createFileSync(door4UsersRep + fileName)886 if (fs.existsSync(rep_4A + fileName)) fs.unlinkSync(rep_4A + fileName);887 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);888 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);889 })890 if (member.roles.has(role_4B.id)) member.removeRole(role_4B.id);891892 } else if ((message.channel == chan_4C) && ((cmd == choice_4E)||(cmd == choice_4G)||(cmd == choice_4D)||(cmd == choice_4B))) { // CHAN_4C893894 if (cmd == choice_4E) member.addRole(role_4E).then(addRole => {895 fs.createFileSync(rep_4E + fileName)896 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);897 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);898 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);899 })900 if (cmd == choice_4G) member.addRole(role_4G).then(addRole => {901 fs.createFileSync(rep_4G + fileName)902 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);903 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);904 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);905 })906 if (cmd == choice_4D) member.addRole(role_4D).then(addRole => {907 fs.createFileSync(rep_4D + fileName)908 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);909 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);910 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);911 })912 if (cmd == choice_4B) member.addRole(role_4B).then(addRole => {913 fs.createFileSync(rep_4B + fileName)914 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);915 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);916 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);917 })918 if (member.roles.has(role_4C.id)) member.removeRole(role_4C.id);919920 } else if ((message.channel == chan_4D) && ((cmd == choice_4E)||(cmd == choice_4F)||(cmd == choice_4C)||(cmd == choice_4B))) { // CHAN_4D921922 if (cmd == choice_4E) member.addRole(role_4E).then(addRole => {923 fs.createFileSync(rep_4E + fileName)924 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);925 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);926 })927 if (cmd == choice_4F) member.addRole(role_4F).then(addRole => {928 fs.createFileSync(rep_4F + fileName)929 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);930 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);931 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);932 })933 if (cmd == choice_4C) member.addRole(role_4C).then(addRole => {934 fs.createFileSync(rep_4C + fileName)935 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);936 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);937 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);938 })939 if (cmd == choice_4B) member.addRole(role_4B).then(addRole => {940 fs.createFileSync(rep_4B + fileName)941 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);942 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);943 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);944 })945 if (member.roles.has(role_4D.id)) member.removeRole(role_4D.id);946947 } else if ((message.channel == chan_4E) && ((cmd == choice_4F)||(cmd == choice_4G)||(cmd == choice_4C)||(cmd == choice_4D))) { // CHAN_4E948949 if (cmd == choice_4F) member.addRole(role_4E).then(addRole => {950 fs.createFileSync(rep_4E + fileName)951 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);952 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);953 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);954 })955 if (cmd == choice_4G) member.addRole(role_4G).then(addRole => {956 fs.createFileSync(rep_4G + fileName)957 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);958 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);959 })960 if (cmd == choice_4C) member.addRole(role_4D).then(addRole => {961 fs.createFileSync(rep_4D + fileName)962 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);963 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);964 })965 if (cmd == choice_4D) member.addRole(role_4B).then(addRole => {966 fs.createFileSync(rep_4B + fileName)967 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);968 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);969 })970 if (member.roles.has(role_4E.id)) member.removeRole(role_4E.id);971972 } else if ((message.channel == chan_4G) && ((cmd == choice_4I)||(cmd == choice_4H)||(cmd == choice_4C)||(cmd == choice_4E))) { // CHAN_4G973974 if (cmd == choice_4I) member.addRole(role_4I).then(addRole => {975 fs.createFileSync(rep_4I + fileName)976 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);977 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);978 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);979 })980 if (cmd == choice_4H) member.addRole(role_4H).then(addRole => {981 fs.createFileSync(rep_4H + fileName)982 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);983 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);984 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);985 })986 if (cmd == choice_4C) member.addRole(role_4C).then(addRole => {987 fs.createFileSync(rep_4C + fileName)988 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);989 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);990 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);991 })992 if (cmd == choice_4E) member.addRole(role_4E).then(addRole => {993 fs.createFileSync(rep_4E + fileName)994 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);995 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);996 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);997 })998 if (member.roles.has(role_4G.id)) member.removeRole(role_4G.id);9991000 } else if ((message.channel == chan_4I) && ((cmd == choice_4G)||(cmd == choice_4H))) { // CHAN_4G10011002 if (cmd == choice_4G) member.addRole(role_4G).then(addRole => {1003 fs.createFileSync(rep_4G + fileName)1004 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);1005 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);1006 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);1007 })1008 if (cmd == choice_4H) member.addRole(role_4H).then(addRole => {1009 fs.createFileSync(rep_4H + fileName)1010 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);1011 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);1012 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);1013 })1014 if (cmd == jumpCmd) member.addRole(role_2E).then(addRole => { // TELEPORTATION VERS CHAN_2E1015 fs.createFileSync(rep_2E + fileName)1016 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);1017 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);1018 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);1019 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);1020 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);1021 })1022 if (member.roles.has(role_4I.id)) member.removeRole(role_4I.id);10231024 }10251026});10271028client.on("guildMemberRemove", (member) => { // l'utilisateur quitte avant d'avoir réagit au règlement1029 var quitMsg = `${member.user.username} a quitté ${member.guild.name} avant d'avoir `;1030 var userFileConf = startedUsersRep + member.id + '.js'1031 1032 if (!fs.existsSync(userFileConf)) {1033 enterChan.send(quitMsg + 'lancé la partie.')1034 console.log(quitMsg + 'lancé la partie')1035 } else if (fs.existsSync(userFileConf)) {1036 fs.unlinkSync(userFileConf)1037 labyUsersFoldersList.forEach(folder => {1038 if (fs.existsSync(folder + member.id + '.js')) fs.unlinkSync(folder + member.id + '.js') && console.log(` Son fichier de configuration situé dans le dossier ${folder} a été supprimé`)1039 })1040 enterChan.send(quitMsg + 'trouvé les membres communauté')1041 console.log(quitMsg + 'trouvé les membres communauté')1042 }10431044});1045 ...

Full Screen

Full Screen

comebackCmd.js

Source:comebackCmd.js Github

copy

Full Screen

1function comebackCmd(message, prefix, client, member, msgChan, cmd, fileName, fs) {2 3 var comebackCmd = ((cmd == "faire demi-tour")||(cmd == "faire demi tour"));4 var doorCBmsg = `à ce stade votre seul moyen de faire marche arrière est de recommencer.\nSi c'est ce que vous souhaitez, je vous invite à taper ici-même la commande: **\`!restart\`**`;5 6 if (comebackCmd) {78 // 4 PRINCIPALS DOORS9 if (message.channel == chanDoor1) {10 if ((!fs.existsSync(rep_1A + fileName) && (!fs.existsSync(rep_1B + fileName)))) { // l'utilisateur ne provient d'aucune direction11 return message.reply(doorCBmsg).then(reply => reply.delete(10000));12 } else if (fs.existsSync(rep_1A + fileName)) {13 member.addRole(role_1A).then(addRole => member.removeRole(door1Role));14 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName)15 } else if (fs.existsSync(rep_1B + fileName)) {16 member.addRole(role_1B).then(addRole => member.removeRole(door1Role));17 if (fs.existsSync(rep_1A + fileName)) fs.unlinkSync(rep_1A + fileName)18 }1920 } else if (message.channel == chanDoor2) {21 if ((!fs.existsSync(rep_2A + fileName) && (!fs.existsSync(rep_2B + fileName)))) { // l'utilisateur ne provient d'aucune direction22 return message.reply(doorCBmsg).then(reply => reply.delete(10000));23 } else if (fs.existsSync(rep_2A + fileName)) {24 member.addRole(role_2A).then(addRole => member.removeRole(door2Role));25 } else if (fs.existsSync(rep_2B + fileName)) {26 member.addRole(role_2B).then(addRole => member.removeRole(door2Role));27 }2829 } else if (message.channel == chanDoor3) {30 if ((!fs.existsSync(rep_3A + fileName) && (!fs.existsSync(rep_3B + fileName)))) { // l'utilisateur ne provient d'aucune direction31 return message.reply(doorCBmsg).then(reply => reply.delete(10000));32 } else if (fs.existsSync(rep_3A + fileName)) {33 member.addRole(role_3A).then(addRole => member.removeRole(door3Role));34 } else if (fs.existsSync(rep_3B + fileName)) {35 member.addRole(role_3B).then(addRole => member.removeRole(door3Role));36 }3738 } else if (message.channel == chanDoor4) {39 if ((!fs.existsSync(rep_4A + fileName) && (!fs.existsSync(rep_4B + fileName)))) { // l'utilisateur ne provient d'aucune direction40 return message.reply(doorCBmsg).then(reply => reply.delete(10000));41 } else if (fs.existsSync(rep_4A + fileName)) {42 member.addRole(role_4A).then(addRole => member.removeRole(door4Role));43 } else if (fs.existsSync(rep_4B + fileName)) {44 member.addRole(role_4B).then(addRole => member.removeRole(door4Role));45 }4647 // LABYRINTHE CHANNELS48 } else if (msgChan == chan_1A) {49 if (fs.existsSync(door1UsersRep + fileName)) {50 member.addRole(door1Role);51 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);52 } else if (fs.existsSync(rep_1B + fileName)) {53 member.addRole(role_1B);54 if (fs.existsSync(door1UsersRep + fileName)) fs.unlinkSync(door1UsersRep + fileName);55 }56 member.removeRole(role_1A);5758 } else if (msgChan == chan_1B) {59 if (fs.existsSync(door1UsersRep + fileName)) {60 member.addRole(door1Role);61 if (fs.existsSync(rep_1A + fileName)) fs.unlinkSync(rep_1A + fileName);62 } else if (fs.existsSync(rep_1A + fileName)) {63 member.addRole(role_1A);64 if (fs.existsSync(door1UsersRep + fileName)) fs.unlinkSync(door1UsersRep + fileName);65 } else if (fs.existsSync(rep_1D + fileName)) {66 if (fs.existsSync(door1UsersRep + fileName)) fs.unlinkSync(door1UsersRep + fileName);67 if (fs.existsSync(rep_1A + fileName)) fs.unlinkSync(rep_1A + fileName);68 member.addRole(role_1D);69 }70 member.removeRole(role_1B);7172 } else if (msgChan == chan_1D) {7374 if (fs.existsSync(rep_1B + fileName)) {75 member.addRole(role_1B);76 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);77 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);78 } else if (fs.existsSync(rep_1E + fileName)) {79 member.addRole(role_1E);80 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);81 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);82 } else if (fs.existsSync(rep_1F + fileName)) {83 member.addRole(role_1F);84 if (fs.existsSync(rep_1B + fileName)) fs.unlinkSync(rep_1B + fileName);85 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);86 }87 member.removeRole(role_1D);8889 } else if (msgChan == chan_1E) {9091 if (fs.existsSync(rep_1D + fileName)) {92 member.addRole(role_1D);93 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);94 } else if (fs.existsSync(rep_1F + fileName)) {95 member.addRole(role_1F);96 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);97 }98 member.removeRole(role_1E);99100 } else if (msgChan == chan_1F) {101 102 if (fs.existsSync(rep_1D + fileName)) {103 member.addRole(role_1D);104 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);105 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);106 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);107 } else if (fs.existsSync(rep_1E + fileName)) {108 member.addRole(role_1E);109 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);110 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);111 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);112 } else if (fs.existsSync(rep_2A + fileName)) {113 member.addRole(role_2A);114 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);115 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);116 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);117 } else if (fs.existsSync(rep_2C + fileName)) {118 member.addRole(role_2C);119 if (fs.existsSync(rep_1D + fileName)) fs.unlinkSync(rep_1D + fileName);120 if (fs.existsSync(rep_1E + fileName)) fs.unlinkSync(rep_1E + fileName);121 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);122 }123 member.removeRole(role_1F);124125 } else if (msgChan == chan_2A) {126 if (fs.existsSync(door2UsersRep + fileName)) {127 member.addRole(door2Role);128 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);129 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);130 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);131 } else if (fs.existsSync(rep_2B + fileName)) {132 member.addRole(role_2B);133 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);134 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);135 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);136 } else if (fs.existsSync(rep_2C + fileName)) {137 member.addRole(role_2C);138 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);139 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);140 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);141 } else if (fs.existsSync(rep_1F + fileName)) {142 member.addRole(role_1F);143 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);144 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);145 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);146 }147 member.removeRole(role_2A);148149 } else if (msgChan == chan_2B) {150 if (fs.existsSync(door2UsersRep + fileName)) {151 member.addRole(door2Role);152 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);153 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);154 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);155 } else if (fs.existsSync(rep_2A + fileName)) {156 member.addRole(role_2A);157 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);158 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);159 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);160 } else if (fs.existsSync(rep_2C + fileName)) {161 member.addRole(role_2C);162 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);163 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);164 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);165 } else if (fs.existsSync(rep_2D + fileName)) {166 member.addRole(role_2D);167 if (fs.existsSync(door2UsersRep + fileName)) fs.unlinkSync(door2UsersRep + fileName);168 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);169 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);170 }171 member.removeRole(role_2B);172173 } else if (msgChan == chan_2C) {174 if (fs.existsSync(rep_1F + fileName)) {175 member.addRole(role_1F);176 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);177 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);178 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);179 } else if (fs.existsSync(rep_2A + fileName)) {180 member.addRole(role_2A);181 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);182 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);183 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);184 } else if (fs.existsSync(rep_2B + fileName)) {185 member.addRole(role_2B);186 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);187 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);188 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);189 } else if (fs.existsSync(rep_2D + fileName)) {190 member.addRole(role_2D);191 if (fs.existsSync(rep_1F + fileName)) fs.unlinkSync(rep_1F + fileName);192 if (fs.existsSync(rep_2A + fileName)) fs.unlinkSync(rep_2A + fileName);193 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);194 }195 member.removeRole(role_2C);196197 } else if (msgChan == chan_2D) {198 if (fs.existsSync(rep_2B + fileName)) {199 member.addRole(role_2B);200 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);201 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);202 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);203 } else if (fs.existsSync(rep_2C + fileName)) {204 member.addRole(role_2C);205 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);206 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);207 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);208 } else if (fs.existsSync(rep_2E + fileName)) {209 member.addRole(role_2E);210 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);211 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);212 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);213 } else if (fs.existsSync(rep_2F + fileName)) {214 member.addRole(role_2F);215 if (fs.existsSync(rep_2B + fileName)) fs.unlinkSync(rep_2B + fileName);216 if (fs.existsSync(rep_2C + fileName)) fs.unlinkSync(rep_2C + fileName);217 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);218 }219 member.removeRole(role_2D);220221 } else if (msgChan == chan_2E) {222 if (fs.existsSync(rep_2D + fileName)) {223 member.addRole(role_2D);224 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);225 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);226 } else if (fs.existsSync(rep_2F + fileName)) {227 member.addRole(role_2F);228 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);229 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);230 } else if (fs.existsSync(rep_3H + fileName)) {231 member.addRole(role_3H);232 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);233 if (fs.existsSync(rep_2F + fileName)) fs.unlinkSync(rep_2F + fileName);234 } else if (!fs.existsSync(rep_2D + fileName) && !fs.existsSync(rep_2F + fileName) && !fs.existsSync(rep_3H + fileName)) {235 message.channel.send(`**${member.user.username}** vous avez été téléporté.\nLe téléporteur est à sens unique, il ne peut vous ramener à votre précédent emplacement.\nSi vous ne savez pas quoi faire, je vous invite à taper: **\`!choix\`**`)236 }237 member.removeRole(role_2E);238239 } else if (msgChan == chan_2F) {240 if (fs.existsSync(rep_2D + fileName)) {241 member.addRole(role_2D);242 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);243 if (fs.existsSync(rep_2H + fileName)) fs.unlinkSync(rep_2H + fileName);244 } else if (fs.existsSync(rep_2E + fileName)) {245 member.addRole(role_2E);246 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);247 if (fs.existsSync(rep_2H + fileName)) fs.unlinkSync(rep_2H + fileName);248 } else if (fs.existsSync(rep_2H + fileName)) {249 member.addRole(role_2H);250 if (fs.existsSync(rep_2D + fileName)) fs.unlinkSync(rep_2D + fileName);251 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);252 }253 member.removeRole(role_2F);254255 } else if (msgChan == chan_2H) {256 if (fs.existsSync(rep_2F + fileName)) {257 member.addRole(role_2F);258 }259 member.removeRole(role_2H);260261 } else if (msgChan == chan_3A) {262 if (fs.existsSync(door3UsersRep + fileName)) {263 member.addRole(door3Role);264 if (fs.existsSync(rep_3B + fileName)) fs.unlinkSync(rep_3B + fileName);265 } else if (fs.existsSync(rep_3B + fileName)) {266 member.addRole(role_3B);267 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);268 }269 member.removeRole(role_3A);270271 } else if (msgChan == chan_3B) {272 if (fs.existsSync(door3UsersRep + fileName)) {273 member.addRole(door3Role);274 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);275 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);276 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);277 } else if (fs.existsSync(rep_3A + fileName)) {278 member.addRole(role_3A);279 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);280 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);281 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);282 } else if (fs.existsSync(rep_3C + fileName)) {283 member.addRole(role_3C);284 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);285 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);286 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);287 } else if (fs.existsSync(rep_3D + fileName)) {288 member.addRole(role_3D);289 if (fs.existsSync(door3UsersRep + fileName)) fs.unlinkSync(door3UsersRep + fileName);290 if (fs.existsSync(rep_3A + fileName)) fs.unlinkSync(rep_3A + fileName);291 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);292 }293 member.removeRole(role_3B);294295 } else if (msgChan == chan_3C) {296 if (fs.existsSync(rep_3B + fileName)) {297 member.addRole(role_3B);298 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);299 } else if (fs.existsSync(rep_3D + fileName)) {300 member.addRole(role_3D);301 if (fs.existsSync(rep_3B + fileName)) fs.unlinkSync(rep_3B + fileName);302 }303 member.removeRole(role_3C);304305 } else if (msgChan == chan_3D) {306 if (fs.existsSync(rep_3B + fileName)) {307 member.addRole(role_3B);308 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);309 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);310 } else if (fs.existsSync(rep_3C + fileName)) {311 member.addRole(role_3C);312 if (fs.existsSync(rep_3B + fileName)) fs.unlinkSync(rep_3B + fileName);313 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);314 } else if (fs.existsSync(rep_3F + fileName)) {315 member.addRole(role_3F);316 if (fs.existsSync(rep_3B + fileName)) fs.unlinkSync(rep_3B + fileName);317 if (fs.existsSync(rep_3C + fileName)) fs.unlinkSync(rep_3C + fileName);318 }319 member.removeRole(role_3D);320321 } else if (msgChan == chan_3F) {322 if (fs.existsSync(rep_3D + fileName)) {323 member.addRole(role_3D);324 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);325 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);326 } else if (fs.existsSync(rep_3G + fileName)) {327 member.addRole(role_3G);328 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);329 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);330 } else if (fs.existsSync(rep_3H + fileName)) {331 member.addRole(role_3H);332 if (fs.existsSync(rep_3D + fileName)) fs.unlinkSync(rep_3D + fileName);333 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);334 }335 member.removeRole(role_3F);336337 } else if (msgChan == chan_3G) {338 if (fs.existsSync(rep_3F + fileName)) {339 member.addRole(role_3F);340 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);341 if (fs.existsSync(rep_3I + fileName)) fs.unlinkSync(rep_3I + fileName);342 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);343 } else if (fs.existsSync(rep_3H + fileName)) {344 member.addRole(role_3H);345 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);346 if (fs.existsSync(rep_3I + fileName)) fs.unlinkSync(rep_3I + fileName);347 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);348 } else if (fs.existsSync(rep_3I + fileName)) {349 member.addRole(role_3I);350 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);351 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);352 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);353 } else if (fs.existsSync(rep_3J + fileName)) {354 member.addRole(role_3J);355 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);356 if (fs.existsSync(rep_3H + fileName)) fs.unlinkSync(rep_3H + fileName);357 if (fs.existsSync(rep_3I + fileName)) fs.unlinkSync(rep_3I + fileName);358 }359 member.removeRole(role_3G);360361 } else if (msgChan == chan_3H) {362 if (fs.existsSync(rep_2E + fileName)) {363 member.addRole(role_2E);364 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);365 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);366 } else if (fs.existsSync(rep_3F + fileName)) {367 member.addRole(role_3F);368 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);369 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);370 } else if (fs.existsSync(rep_3G + fileName)) {371 member.addRole(role_3G);372 if (fs.existsSync(rep_2E + fileName)) fs.unlinkSync(rep_2E + fileName);373 if (fs.existsSync(rep_3F + fileName)) fs.unlinkSync(rep_3F + fileName);374 }375 member.removeRole(role_3H);376377 } else if (msgChan == chan_3I) {378 if (fs.existsSync(rep_3G + fileName)) {379 member.addRole(role_3G);380 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);381 } else if (fs.existsSync(rep_3J + fileName)) { // CHANNEL ARRIVEE LABYRINTHE382 member.addRole(role_3J);383 if (fs.existsSync(rep_3G + fileName)) fs.unlinkSync(rep_3G + fileName);384 }385 member.removeRole(role_3I);386387 } else if (msgChan == chan_3J) {388 if (fs.existsSync(rep_3G + fileName)) {389 member.addRole(role_3G);390 if (fs.existsSync(rep_3I + fileName)) fs.unlinkSync(rep_3I + fileName);391 } else if (fs.existsSync(rep_3I + fileName)) { // CHANNEL ARRIVEE LABYRINTHE392 member.addRole(role_3I);393 if (fs.existsSync(rep_3J + fileName)) fs.unlinkSync(rep_3J + fileName);394 }395 member.removeRole(role_3J);396397 } else if (msgChan == chan_4A) {398 if (fs.existsSync(door4UsersRep + fileName)) {399 member.addRole(door4Role);400 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);401 } else if (fs.existsSync(rep_4B + fileName)) {402 member.addRole(role_4B);403 if (fs.existsSync(rep_4A + fileName)) fs.unlinkSync(rep_4A + fileName);404 }405 member.removeRole(role_4A);406407 } else if (msgChan == chan_4B) {408 if (fs.existsSync(door4UsersRep + fileName)) {409 member.addRole(door4Role);410 if (fs.existsSync(rep_4A + fileName)) fs.unlinkSync(rep_4A + fileName);411 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);412 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);413 } else if (fs.existsSync(rep_4A + fileName)) {414 member.addRole(role_4A);415 if (fs.existsSync(door4UsersRep + fileName)) fs.unlinkSync(door4UsersRep + fileName);416 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);417 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);418 } else if (fs.existsSync(rep_4C + fileName)) {419 member.addRole(role_4C);420 if (fs.existsSync(door4UsersRep + fileName)) fs.unlinkSync(door4UsersRep + fileName);421 if (fs.existsSync(rep_4A + fileName)) fs.unlinkSync(rep_4A + fileName);422 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);423 } else if (fs.existsSync(rep_4D + fileName)) {424 member.addRole(role_4D);425 if (fs.existsSync(door4UsersRep + fileName)) fs.unlinkSync(door4UsersRep + fileName);426 if (fs.existsSync(rep_4A + fileName)) fs.unlinkSync(rep_4A + fileName);427 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);428 }429 member.removeRole(role_4B);430431 } else if (msgChan == chan_4C) {432 if (fs.existsSync(rep_4B + fileName)) {433 member.addRole(role_4B);434 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);435 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);436 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);437 } else if (fs.existsSync(rep_4D + fileName)) {438 member.addRole(role_4D);439 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);440 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);441 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);442 } else if (fs.existsSync(rep_4E + fileName)) {443 member.addRole(role_4E);444 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);445 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);446 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);447 } else if (fs.existsSync(rep_4G + fileName)) {448 member.addRole(role_4G);449 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);450 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);451 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);452 }453 member.removeRole(role_4C);454455 } else if (msgChan == chan_4D) {456 if (fs.existsSync(rep_4B + fileName)) {457 member.addRole(role_4B);458 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);459 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);460 } else if (fs.existsSync(rep_4C + fileName)) {461 member.addRole(role_4C);462 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);463 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);464 } else if (fs.existsSync(rep_4E + fileName)) {465 member.addRole(role_4E);466 if (fs.existsSync(rep_4B + fileName)) fs.unlinkSync(rep_4B + fileName);467 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);468 }469 member.removeRole(role_4D);470471 } else if (msgChan == chan_4E) {472 if (fs.existsSync(rep_4C + fileName)) {473 member.addRole(role_4C);474 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);475 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);476 } else if (fs.existsSync(rep_4D + fileName)) {477 member.addRole(role_4D);478 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);479 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);480 } else if (fs.existsSync(rep_4I + fileName)) {481 member.addRole(role_4I);482 if (fs.existsSync(rep_4D + fileName)) fs.unlinkSync(rep_4D + fileName);483 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);484 }485 member.removeRole(role_4E);486487 } else if (msgChan == chan_4G) {488 if (fs.existsSync(rep_4C + fileName)) {489 member.addRole(role_4C);490 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);491 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);492 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);493 } else if (fs.existsSync(rep_4E + fileName)) {494 member.addRole(role_4E);495 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);496 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);497 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);498 } else if (fs.existsSync(rep_4H + fileName)) {499 member.addRole(role_4H);500 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);501 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);502 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);503 } else if (fs.existsSync(rep_4I + fileName)) {504 member.addRole(role_4I);505 if (fs.existsSync(rep_4C + fileName)) fs.unlinkSync(rep_4C + fileName);506 if (fs.existsSync(rep_4E + fileName)) fs.unlinkSync(rep_4E + fileName);507 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);508 }509 member.removeRole(role_4G);510511 } else if (msgChan == chan_4H) {512 if (fs.existsSync(rep_4G + fileName)) {513 member.addRole(role_4G);514 if (fs.existsSync(rep_4I + fileName)) fs.unlinkSync(rep_4I + fileName);515 } else if (fs.existsSync(rep_4I + fileName)) {516 member.addRole(role_4I);517 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);518 }519 member.removeRole(role_4H);520521 } else if (msgChan == chan_4I) {522 if (fs.existsSync(rep_4H + fileName)) {523 member.addRole(role_4H);524 if (fs.existsSync(rep_4G + fileName)) fs.unlinkSync(rep_4G + fileName);525 } else if (fs.existsSync(rep_4G + fileName)) {526 member.addRole(role_4G);527 if (fs.existsSync(rep_4H + fileName)) fs.unlinkSync(rep_4H + fileName);528 }529 member.removeRole(role_4I);530531 }532533 } // END OF USERS COME BACK CMD534535}536 ...

Full Screen

Full Screen

conflate.test.js

Source:conflate.test.js Github

copy

Full Screen

1'use strict';2const ReadLine = require('n-readlines');3const worker = require('../index').conflate;4const test = require('tape');5const path = require('path');6const fs = require('fs');7const db = require('./lib/db');8db.init(test);9test('conflate - in_persistent argument error', (t) => {10 t.throws(() => worker(), /in_persistent argument is required/);11 t.end();12});13test('conflate - in_address argument error', (t) => {14 t.throws(() => worker({15 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent.geojson')16 }), /in_address argument is required/);17 t.end();18});19test('conflate - output argument error', (t) => {20 t.throws(() => worker({21 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),22 'in_address': path.resolve(__dirname, './fixtures/dc-new.geojson')23 }), /Output file required/);24 t.end();25});26test('conflate - CREATE finds only exact duplicate features, adds nothing', (t) => {27 // Ensure files don't exist before test28 try {29 fs.unlinkSync('/tmp/output.geojson');30 fs.unlinkSync('/tmp/error-persistent');31 } catch (err) {32 console.error('ok - cleaned tmp files');33 }34 worker({35 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),36 'in_address': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),37 output: '/tmp/output.geojson',38 'error_persistent': '/tmp/error-persistent',39 context: {40 country: 'us',41 region: 'dc',42 languages: ['en']43 },44 db: 'pt_test'45 });46 const rl = new ReadLine('/tmp/output.geojson');47 t.notOk(rl.next(), 'no output features');48 t.doesNotThrow(() => {49 fs.accessSync('/tmp/error-persistent');50 });51 fs.unlinkSync('/tmp/output.geojson');52 fs.unlinkSync('/tmp/error-persistent');53 t.end();54});55test('conflate - CREATE finds features with same address number and street less than 1km away, adds nothing', (t) => {56 // Ensure files don't exist before test57 try {58 fs.unlinkSync('/tmp/output.geojson');59 fs.unlinkSync('/tmp/error-persistent');60 } catch (err) {61 console.error('ok - cleaned tmp files');62 }63 worker({64 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),65 'in_address': path.resolve(__dirname, './fixtures/dc-new-close.geojson'),66 output: '/tmp/output.geojson',67 'error_persistent': '/tmp/error-persistent',68 context: {69 country: 'us',70 region: 'dc',71 languages: ['en']72 },73 db: 'pt_test'74 });75 const rl = new ReadLine('/tmp/output.geojson');76 t.notOk(rl.next(), 'no output features');77 t.doesNotThrow(() => {78 fs.accessSync('/tmp/error-persistent');79 });80 fs.unlinkSync('/tmp/output.geojson');81 fs.unlinkSync('/tmp/error-persistent');82 t.end();83});84test('conflate - CREATE finds features with same address number and street more than 1km away, add new address', (t) => {85 // Ensure files don't exist before test86 try {87 fs.unlinkSync('/tmp/output.geojson');88 fs.unlinkSync('/tmp/error-persistent');89 } catch (err) {90 console.error('ok - cleaned tmp files');91 }92 worker({93 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),94 'in_address': path.resolve(__dirname, './fixtures/dc-new-far.geojson'),95 output: '/tmp/output.geojson',96 'error_persistent': '/tmp/error-persistent',97 context: {98 country: 'us',99 region: 'dc',100 languages: ['en']101 },102 db: 'pt_test'103 });104 const rl = new ReadLine('/tmp/output.geojson');105 t.deepEquals(JSON.parse(rl.next()), {106 action: 'create',107 type: 'Feature',108 properties: {109 number: '108',110 street: [{111 display: '4th St NE',112 priority: -1113 }]114 },115 geometry: {116 type: 'Point',117 coordinates: [-77.00055599212646, 38.880443352851955]118 }119 });120 t.notOk(rl.next(), '1 output feature');121 t.doesNotThrow(() => {122 fs.accessSync('/tmp/error-persistent');123 });124 fs.unlinkSync('/tmp/output.geojson');125 fs.unlinkSync('/tmp/error-persistent');126 t.end();127});128test('conflate - CREATE finds feature with different address number and street, adds new address', (t) => {129 // Ensure files don't exist before test130 try {131 fs.unlinkSync('/tmp/output.geojson');132 fs.unlinkSync('/tmp/error-persistent');133 } catch (err) {134 console.error('ok - cleaned tmp files');135 }136 worker({137 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),138 'in_address': path.resolve(__dirname, './fixtures/dc-new.geojson'),139 output: '/tmp/output.geojson',140 'error_persistent': '/tmp/error-persistent',141 context: {142 country: 'us',143 region: 'dc',144 languages: ['en']145 },146 db: 'pt_test'147 });148 const rl = new ReadLine('/tmp/output.geojson');149 t.deepEquals(JSON.parse(rl.next()), {150 action: 'create',151 type: 'Feature',152 properties: {153 number: '112',154 street: [{155 display: '4th St NE',156 priority: -1157 }]158 },159 geometry: {160 type: 'Point',161 coordinates: [-77.00080543756485, 38.89128752230519]162 }163 });164 t.notOk(rl.next(), 'output 1 feature');165 t.doesNotThrow(() => {166 fs.accessSync('/tmp/error-persistent');167 });168 fs.unlinkSync('/tmp/output.geojson');169 fs.unlinkSync('/tmp/error-persistent');170 t.end();171});172test('conflate - MODIFY adds new names to existing address names preferencing new names', (t) => {173 // Ensure files don't exist before test174 try {175 fs.unlinkSync('/tmp/output.geojson');176 fs.unlinkSync('/tmp/error-persistent');177 } catch (err) {178 console.error('ok - cleaned tmp files');179 }180 worker({181 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent-syns.geojson'),182 'in_address': path.resolve(__dirname, './fixtures/dc-modify.geojson'),183 output: '/tmp/output.geojson',184 'error_persistent': '/tmp/error-persistent',185 context: {186 country: 'us',187 region: 'dc',188 languages: ['en']189 },190 db: 'pt_test'191 });192 const rl = new ReadLine('/tmp/output.geojson');193 t.deepEquals(JSON.parse(rl.next()), {194 id: 1,195 version: 2,196 action: 'modify',197 type: 'Feature',198 properties: {199 number: 108,200 street: [{201 display: '4th Street Northeast',202 priority: -1203 }, {204 display: 'DC Route 101',205 priority: -2206 }, {207 display: 'Main St',208 priority: -2209 }]210 },211 geometry: {212 type: 'Point',213 coordinates: [-77.0008054375648, 38.8912875223052]214 }215 });216 t.notOk(rl.next(), 'output 1 feature');217 t.doesNotThrow(() => {218 fs.accessSync('/tmp/error-persistent');219 });220 fs.unlinkSync('/tmp/output.geojson');221 fs.unlinkSync('/tmp/error-persistent');222 t.end();223});224test('conflate - MODIFY does not update existing address, no new names are added', (t) => {225 // Ensure files don't exist before test226 try {227 fs.unlinkSync('/tmp/output.geojson');228 fs.unlinkSync('/tmp/error-persistent');229 } catch (err) {230 console.error('ok - cleaned tmp files');231 }232 worker({233 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent-syns.geojson'),234 'in_address': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),235 output: '/tmp/output.geojson',236 'error_persistent': '/tmp/error-persistent',237 context: {238 country: 'us',239 region: 'dc',240 languages: ['en']241 },242 db: 'pt_test'243 });244 const rl = new ReadLine('/tmp/output.geojson');245 t.notOk(rl.next(), 'no output features');246 t.doesNotThrow(() => {247 fs.accessSync('/tmp/error-persistent');248 });249 fs.unlinkSync('/tmp/output.geojson');250 fs.unlinkSync('/tmp/error-persistent');251 t.end();252});253test('conflate - MODIFY handles multiple updates to the same feature', (t) => {254 // Ensure files don't exist before test255 try {256 fs.unlinkSync('/tmp/output.geojson');257 fs.unlinkSync('/tmp/error-persistent');258 } catch (err) {259 console.error('ok - cleaned tmp files');260 }261 worker({262 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),263 'in_address': path.resolve(__dirname, './fixtures/dc-modify-multiple.geojson'),264 output: '/tmp/output.geojson',265 'error_persistent': '/tmp/error-persistent',266 context: {267 country: 'us',268 region: 'dc',269 languages: ['en']270 },271 db: 'pt_test'272 });273 const rl = new ReadLine('/tmp/output.geojson');274 t.deepEquals(JSON.parse(rl.next()), {275 id: 1,276 version: 2,277 action: 'modify',278 type: 'Feature',279 properties: {280 number: 108,281 street: [{282 display: '4th St NE',283 priority: -1284 }, {285 display: 'Main St',286 priority: -2287 }, {288 display: 'DC Route 101',289 priority: -2290 }]291 },292 geometry: {293 type: 'Point',294 coordinates: [-77.0008054375648, 38.8912875223052]295 }296 });297 t.notOk(rl.next(), 'output 1 feature');298 t.doesNotThrow(() => {299 fs.accessSync('/tmp/error-persistent');300 });301 fs.unlinkSync('/tmp/output.geojson');302 fs.unlinkSync('/tmp/error-persistent');303 t.end();304});305test('conflate - MODIFY all properties on the existing address are preserved, including overrides, excluding street names', (t) => {306 // Ensure files don't exist before test307 try {308 fs.unlinkSync('/tmp/output.geojson');309 fs.unlinkSync('/tmp/error-persistent');310 } catch (err) {311 console.error('ok - cleaned tmp files');312 }313 worker({314 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent-override.geojson'),315 'in_address': path.resolve(__dirname, './fixtures/dc-modify.geojson'),316 output: '/tmp/output.geojson',317 'error_persistent': '/tmp/error-persistent',318 context: {319 country: 'us',320 region: 'dc',321 languages: ['en']322 },323 db: 'pt_test'324 });325 const rl = new ReadLine('/tmp/output.geojson');326 t.deepEquals(JSON.parse(rl.next()), {327 id: 1,328 version: 2,329 action: 'modify',330 type: 'Feature',331 properties: {332 postcode: '00000',333 accuracy: 'rooftop',334 source: 'original-source',335 number: 108,336 street: [{337 display: '4th Street Northeast',338 priority: -1339 }, {340 display: 'DC Route 101',341 priority: -2342 }]343 },344 geometry: {345 type: 'Point',346 coordinates: [-77.0008054375648, 38.8912875223052]347 }348 });349 t.notOk(rl.next(), 'output 1 feature');350 t.doesNotThrow(() => {351 fs.accessSync('/tmp/error-persistent');352 });353 fs.unlinkSync('/tmp/output.geojson');354 fs.unlinkSync('/tmp/error-persistent');355 t.end();356});357test('conflate - MODIFY non-street properties on the new address are not included in updates', (t) => {358 // Ensure files don't exist before test359 try {360 fs.unlinkSync('/tmp/output.geojson');361 fs.unlinkSync('/tmp/error-persistent');362 } catch (err) {363 console.error('ok - cleaned tmp files');364 }365 worker({366 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent.geojson'),367 'in_address': path.resolve(__dirname, './fixtures/dc-persistent-override.geojson'),368 output: '/tmp/output.geojson',369 'error_persistent': '/tmp/error-persistent',370 context: {371 country: 'us',372 region: 'dc',373 languages: ['en']374 },375 db: 'pt_test'376 });377 const rl = new ReadLine('/tmp/output.geojson');378 t.notOk(rl.next(), 'no features output');379 t.doesNotThrow(() => {380 fs.accessSync('/tmp/error-persistent');381 });382 fs.unlinkSync('/tmp/output.geojson');383 fs.unlinkSync('/tmp/error-persistent');384 t.end();385});386test('conflate - MODIFY existing addresses with output==false are not modified', (t) => {387 // Ensure files don't exist before test388 try {389 fs.unlinkSync('/tmp/output.geojson');390 fs.unlinkSync('/tmp/error-persistent');391 } catch (err) {392 console.error('ok - cleaned tmp files');393 }394 worker({395 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent-output.geojson'),396 'in_address': path.resolve(__dirname, './fixtures/dc-modify-output.geojson'),397 output: '/tmp/output.geojson',398 'error_persistent': '/tmp/error-persistent',399 context: {400 country: 'us',401 region: 'dc',402 languages: ['en']403 },404 db: 'pt_test'405 });406 const rl = new ReadLine('/tmp/output.geojson');407 t.notOk(rl.next(), 'no features output');408 t.doesNotThrow(() => {409 fs.accessSync('/tmp/error-persistent');410 });411 fs.unlinkSync('/tmp/output.geojson');412 fs.unlinkSync('/tmp/error-persistent');413 t.end();414});415test('conflate - MODIFY existing addresses with output==false are not modified, cardinal to non-cardinal match', (t) => {416 // Ensure files don't exist before test417 try {418 fs.unlinkSync('/tmp/output.geojson');419 fs.unlinkSync('/tmp/error-persistent');420 } catch (err) {421 console.error('ok - cleaned tmp files');422 }423 worker({424 'in_persistent': path.resolve(__dirname, './fixtures/dc-persistent-output-cardinal.geojson'),425 'in_address': path.resolve(__dirname, './fixtures/dc-modify-output-cardinal.geojson'),426 output: '/tmp/output.geojson',427 'error_persistent': '/tmp/error-persistent',428 context: {429 country: 'us',430 region: 'dc',431 languages: ['en']432 },433 db: 'pt_test'434 });435 const rl = new ReadLine('/tmp/output.geojson');436 t.notOk(rl.next(), 'no features output');437 t.doesNotThrow(() => {438 fs.accessSync('/tmp/error-persistent');439 });440 fs.unlinkSync('/tmp/output.geojson');441 fs.unlinkSync('/tmp/error-persistent');442 t.end();...

Full Screen

Full Screen

clean.js

Source:clean.js Github

copy

Full Screen

1const fs = require("fs");2const path = require("path");3const {4 getOptions,5 deleteFolderRecursiveSync,6 deleteFolderIfEmptySync,7 deleteFolderRecursiveByAnotherFolderFilesSync8} = require("./utils");9const {createManifest} = require("./utils/serviceWorker");10const createWapplrJson = require("./utils/wapplrJson");11async function cleanByPaths(p = {}) {12 const {paths, options} = p;13 const {srcPath, buildPath, distPath, templatePath} = paths;14 let consoleLine = 0;15 function consoleLog(){16 consoleLine = consoleLine + 1;17 console.log(...arguments)18 }19 if (!fs.existsSync(buildPath)){20 fs.mkdirSync(buildPath, { recursive: true });21 }22 if (fs.existsSync(path.resolve(buildPath, "server.js"))){23 fs.unlinkSync(path.resolve(buildPath, "server.js"))24 }25 if (fs.existsSync(path.resolve(buildPath, "server.js.map"))){26 fs.unlinkSync(path.resolve(buildPath, "server.js.map"))27 }28 if (fs.existsSync(path.resolve(buildPath, "server.js.LICENSE.txt"))){29 fs.unlinkSync(path.resolve(buildPath, "server.js.LICENSE.txt"))30 }31 if (fs.existsSync(path.resolve(buildPath, "asset-manifest.json"))){32 const asset = require(path.resolve(buildPath, "asset-manifest.json"));33 Object.keys(asset).forEach(function (key){34 if (fs.existsSync(path.join(buildPath, "public", asset[key]))){35 consoleLog("Unlink file: " + path.join(buildPath, "public", asset[key]));36 fs.unlinkSync(path.join(buildPath, "public", asset[key]))37 }38 if (fs.existsSync(path.join(buildPath, "public", asset[key]+".map"))){39 consoleLog("Unlink file: " + path.join(buildPath, "public", asset[key]+".map"));40 fs.unlinkSync(path.join(buildPath, "public", asset[key]+".map"))41 }42 if (fs.existsSync(path.join(buildPath, "public", asset[key]+".LICENSE.txt"))){43 consoleLog("Unlink file: " + path.join(buildPath, "public", asset[key]+".LICENSE.txt"));44 fs.unlinkSync(path.join(buildPath, "public", asset[key]+".LICENSE.txt"))45 }46 });47 consoleLog("Unlink file: " + path.resolve(buildPath, "asset-manifest.json"));48 fs.unlinkSync(path.resolve(buildPath, "asset-manifest.json"))49 }50 if (fs.existsSync(path.resolve(buildPath, "server-asset-manifest.json"))){51 const asset = require(path.resolve(buildPath, "server-asset-manifest.json"));52 Object.keys(asset).forEach(function (key){53 if (fs.existsSync(path.join(buildPath, asset[key]))){54 consoleLog("Unlink file: " + path.join(buildPath, asset[key]));55 fs.unlinkSync(path.join(buildPath, asset[key]))56 }57 if (fs.existsSync(path.join(buildPath, asset[key]+".map"))){58 consoleLog("Unlink file: " + path.join(buildPath, asset[key]+".map"));59 fs.unlinkSync(path.join(buildPath, asset[key]+".map"))60 }61 if (fs.existsSync(path.join(buildPath, asset[key]+".LICENSE.txt"))){62 consoleLog("Unlink file: " + path.join(buildPath, asset[key]+".LICENSE.txt"));63 fs.unlinkSync(path.join(buildPath, asset[key]+".LICENSE.txt"))64 }65 });66 consoleLog("Unlink file: " + path.resolve(buildPath, "server-asset-manifest.json"));67 fs.unlinkSync(path.resolve(buildPath, "server-asset-manifest.json"))68 }69 if (fs.existsSync(path.resolve(buildPath, "chunk-manifest.json"))) {70 const chunk = require(path.resolve(buildPath, "chunk-manifest.json"));71 if (chunk.client){72 chunk.client.forEach(function (fileName){73 if (fs.existsSync(path.join(buildPath, "public", fileName))){74 consoleLog("Unlink file: " + path.join(buildPath, "public", fileName));75 fs.unlinkSync(path.join(buildPath, "public", fileName))76 }77 if (fs.existsSync(path.join(buildPath, "public", fileName+".map"))){78 consoleLog("Unlink file: " + path.join(buildPath, "public", fileName+".map"));79 fs.unlinkSync(path.join(buildPath, "public", fileName+".map"))80 }81 if (fs.existsSync(path.join(buildPath, "public", fileName+".LICENSE.txt"))){82 consoleLog("Unlink file: " + path.join(buildPath, "public", fileName+".LICENSE.txt"));83 fs.unlinkSync(path.join(buildPath, "public", fileName+".LICENSE.txt"))84 }85 })86 }87 consoleLog("Unlink file: " + path.resolve(buildPath, "chunk-manifest.json"));88 fs.unlinkSync(path.resolve(buildPath, "chunk-manifest.json"))89 }90 if (fs.existsSync(path.resolve(buildPath, "additional-asset-manifest.json"))){91 const asset = require(path.resolve(buildPath, "additional-asset-manifest.json"));92 Object.keys(asset).forEach(function (key){93 if (fs.existsSync(path.join(buildPath, "public", asset[key]))){94 consoleLog("Unlink file: " + path.join(buildPath, "public", asset[key]));95 fs.unlinkSync(path.join(buildPath, "public", asset[key]))96 }97 if (fs.existsSync(path.join(buildPath, "public", asset[key]+".map"))){98 consoleLog("Unlink file: " + path.join(buildPath, "public", asset[key]+".map"));99 fs.unlinkSync(path.join(buildPath, "public", asset[key]+".map"))100 }101 if (fs.existsSync(path.join(buildPath, "public", asset[key]+".LICENSE.txt"))){102 consoleLog("Unlink file: " + path.join(buildPath, "public", asset[key]+".LICENSE.txt"));103 fs.unlinkSync(path.join(buildPath, "public", asset[key]+".LICENSE.txt"))104 }105 });106 consoleLog("Unlink file: " + path.resolve(buildPath, "additional-asset-manifest.json"));107 fs.unlinkSync(path.resolve(buildPath, "additional-asset-manifest.json"))108 }109 if (fs.existsSync(path.resolve(buildPath, "updates"))) {110 consoleLog("Unlink folder: " + path.resolve(buildPath, "updates"));111 deleteFolderRecursiveSync(path.resolve(buildPath, "updates"));112 }113 if (fs.existsSync(path.resolve(buildPath, "packages"))) {114 consoleLog("Unlink folder: " + path.resolve(buildPath, "packages"));115 deleteFolderRecursiveSync(path.resolve(buildPath, "packages"));116 }117 try {118 const defaultManifest = require(path.resolve(templatePath, "run/public/manifest.json"));119 defaultManifest.icons.forEach(function (iconObject) {120 const srcPaths = iconObject.src.split("/");121 if (fs.existsSync(path.resolve(buildPath, "public", ...srcPaths))) {122 try {123 const currentImage = fs.statSync(path.resolve(buildPath, "public", ...srcPaths));124 const templateImage = fs.statSync(path.resolve(templatePath, "run", "public", ...srcPaths));125 if (JSON.stringify({size:currentImage.size}) ===126 JSON.stringify({size:templateImage.size})127 ) {128 consoleLog("Unlink file: " + path.resolve(buildPath, "public", ...srcPaths));129 fs.unlinkSync(path.resolve(buildPath, "public", ...srcPaths))130 }131 } catch (e) {}132 }133 });134 if (fs.existsSync(path.resolve(buildPath, "public", "manifest.json"))) {135 try {136 const manifest = require(path.resolve(buildPath, "public", "manifest.json"));137 const generatedManifest = createManifest({...options, return: "object", tryWithMissingExistsManifest: true});138 if (JSON.stringify(generatedManifest) === JSON.stringify(manifest)){139 consoleLog("Unlink file: " + path.resolve(buildPath, "public", "manifest.json"));140 fs.unlinkSync(path.resolve(buildPath, "public", "manifest.json"))141 }142 } catch (e) {}143 }144 } catch (e){}145 try {146 let existsServiceWorker = "";147 try {148 existsServiceWorker = fs.readFileSync(path.resolve(buildPath, "public", "serviceWorker.js")).toString()149 } catch (e) {}150 if (existsServiceWorker){151 try {152 let existsOverRides = "";153 try {154 // noinspection RegExpRedundantEscape155 existsOverRides = existsServiceWorker.match(/(\/\*overridesStart \[\*\/)([\S\s]*?)(\/\*\] overridesEnd\*\/)/)[2];156 } catch (e) {}157 if (existsOverRides) {158 existsOverRides = existsOverRides.replace(/\n/g, "").replace(/ /g, "");159 if (existsOverRides === "/***yourcodehere**/"){160 consoleLog("Unlink file: " + path.resolve(buildPath, "public", "serviceWorker.js"));161 fs.unlinkSync(path.resolve(buildPath, "public", "serviceWorker.js"))162 }163 }164 } catch (e){}165 }166 }catch (e){}167 if (fs.existsSync(path.resolve(buildPath, "package.json"))){168 fs.unlinkSync(path.resolve(buildPath, "package.json"))169 }170 deleteFolderIfEmptySync(path.resolve(buildPath, "public", "assets"));171 deleteFolderIfEmptySync(path.resolve(buildPath, "public"));172 deleteFolderIfEmptySync(buildPath);173 if (fs.existsSync(distPath)){174 deleteFolderRecursiveByAnotherFolderFilesSync(srcPath, distPath)175 }176 if (consoleLine){177 console.log("");178 }179}180module.exports = async function clean(p = {}) {181 const options = getOptions(p, "clean");182 const {paths} = options;183 const {rootPath} = paths;184 console.group("[WAPPLR] Clean start");185 const wapplrJson = (fs.existsSync(path.resolve(rootPath, "wapplr.json"))) ? require(path.resolve(rootPath, "wapplr.json")) : {};186 if (wapplrJson && wapplrJson.paths){187 await cleanByPaths({paths: wapplrJson.paths, options: wapplrJson});188 if (options.runScript === "clean"){189 await createWapplrJson({...options, paths: wapplrJson.paths});190 }191 } else {192 await cleanByPaths({paths, options});193 if (options.runScript === "clean") {194 await createWapplrJson(options);195 }196 }197 console.groupEnd();...

Full Screen

Full Screen

test-trace-events-fs-sync.js

Source:test-trace-events-fs-sync.js Github

copy

Full Screen

1'use strict';2const common = require('../common');3const assert = require('assert');4const cp = require('child_process');5const fs = require('fs');6const path = require('path');7const util = require('util');8const tests = new Array();9let gid = 1;10let uid = 1;11if (!common.isWindows) {12 gid = process.getgid();13 uid = process.getuid();14}15tests['fs.sync.access'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +16 'fs.accessSync("fs.txt");' +17 'fs.unlinkSync("fs.txt")';18tests['fs.sync.chmod'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +19 'fs.chmodSync("fs.txt",100);' +20 'fs.unlinkSync("fs.txt")';21tests['fs.sync.chown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +22 `fs.chownSync("fs.txt", ${uid}, ${gid});` +23 'fs.unlinkSync("fs.txt")';24tests['fs.sync.close'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +25 'fs.unlinkSync("fs.txt")';26tests['fs.sync.copyfile'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +27 'fs.copyFileSync("fs.txt","a.txt");' +28 'fs.unlinkSync("fs.txt")';29tests['fs.sync.fchmod'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +30 'const fd = fs.openSync("fs.txt", "r+");' +31 'fs.fchmodSync(fd,100);' +32 'fs.unlinkSync("fs.txt")';33tests['fs.sync.fchown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +34 'const fd = fs.openSync("fs.txt", "r+");' +35 `fs.fchownSync(fd, ${uid}, ${gid});` +36 'fs.unlinkSync("fs.txt")';37tests['fs.sync.fdatasync'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +38 'const fd = fs.openSync("fs.txt", "r+");' +39 'fs.fdatasyncSync(fd);' +40 'fs.unlinkSync("fs.txt")';41tests['fs.sync.fstat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +42 'fs.readFileSync("fs.txt");' +43 'fs.unlinkSync("fs.txt")';44tests['fs.sync.fsync'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +45 'const fd = fs.openSync("fs.txt", "r+");' +46 'fs.fsyncSync(fd);' +47 'fs.unlinkSync("fs.txt")';48tests['fs.sync.ftruncate'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +49 'const fd = fs.openSync("fs.txt", "r+");' +50 'fs.ftruncateSync(fd, 1);' +51 'fs.unlinkSync("fs.txt")';52tests['fs.sync.futimes'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +53 'const fd = fs.openSync("fs.txt", "r+");' +54 'fs.futimesSync(fd,1,1);' +55 'fs.unlinkSync("fs.txt")';56tests['fs.sync.lchown'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +57 `fs.lchownSync("fs.txt", ${uid}, ${gid});` +58 'fs.unlinkSync("fs.txt")';59tests['fs.sync.link'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +60 'fs.linkSync("fs.txt", "linkx");' +61 'fs.unlinkSync("linkx");' +62 'fs.unlinkSync("fs.txt")';63tests['fs.sync.lstat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +64 'fs.lstatSync("fs.txt");' +65 'fs.unlinkSync("fs.txt")';66tests['fs.sync.mkdir'] = 'fs.mkdirSync("fstemp");' +67 'fs.rmdirSync("fstemp")';68tests['fs.sync.mkdtemp'] = 'const fp = fs.mkdtempSync("fstest");' +69 'fs.rmdirSync(fp)';70tests['fs.sync.open'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +71 'fs.unlinkSync("fs.txt")';72tests['fs.sync.read'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +73 'fs.readFileSync("fs.txt");' +74 'fs.unlinkSync("fs.txt")';75tests['fs.sync.readdir'] = 'fs.readdirSync("./")';76tests['fs.sync.realpath'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +77 'fs.linkSync("fs.txt", "linkx");' +78 'fs.realpathSync.native("linkx");' +79 'fs.unlinkSync("linkx");' +80 'fs.unlinkSync("fs.txt")';81tests['fs.sync.rename'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +82 'fs.renameSync("fs.txt","xyz.txt"); ' +83 'fs.unlinkSync("xyz.txt")';84tests['fs.sync.rmdir'] = 'fs.mkdirSync("fstemp");' +85 'fs.rmdirSync("fstemp")';86tests['fs.sync.stat'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +87 'fs.statSync("fs.txt");' +88 'fs.unlinkSync("fs.txt")';89tests['fs.sync.unlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +90 'fs.linkSync("fs.txt", "linkx");' +91 'fs.unlinkSync("linkx");' +92 'fs.unlinkSync("fs.txt")';93tests['fs.sync.utimes'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +94 'fs.utimesSync("fs.txt",1,1);' +95 'fs.unlinkSync("fs.txt")';96tests['fs.sync.write'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +97 'fs.unlinkSync("fs.txt")';98// On windows, we need permissions to test symlink and readlink.99// We'll only try to run these tests if we have enough privileges.100if (common.canCreateSymLink()) {101 tests['fs.sync.symlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +102 'fs.symlinkSync("fs.txt", "linkx");' +103 'fs.unlinkSync("linkx");' +104 'fs.unlinkSync("fs.txt")';105 tests['fs.sync.readlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +106 'fs.symlinkSync("fs.txt", "linkx");' +107 'fs.readlinkSync("linkx");' +108 'fs.unlinkSync("linkx");' +109 'fs.unlinkSync("fs.txt")';110}111const tmpdir = require('../common/tmpdir');112tmpdir.refresh();113const traceFile = path.join(tmpdir.path, 'node_trace.1.log');114for (const tr in tests) {115 const proc = cp.spawnSync(process.execPath,116 [ '--trace-events-enabled',117 '--trace-event-categories', 'node.fs.sync',118 '-e', tests[tr] ],119 { cwd: tmpdir.path, encoding: 'utf8' });120 // Make sure the operation is successful.121 // Don't use assert with a custom message here. Otherwise the122 // inspection in the message is done eagerly and wastes a lot of CPU123 // time.124 if (proc.status !== 0) {125 throw new Error(`${tr}:\n${util.inspect(proc)}`);126 }127 // Confirm that trace log file is created.128 assert(fs.existsSync(traceFile));129 const data = fs.readFileSync(traceFile);130 const traces = JSON.parse(data.toString()).traceEvents;131 assert(traces.length > 0);132 // C++ fs sync trace events should be generated.133 assert(traces.some((trace) => {134 if (trace.pid !== proc.pid)135 return false;136 if (trace.cat !== 'node,node.fs,node.fs.sync')137 return false;138 if (trace.name !== tr)139 return false;140 return true;141 }));...

Full Screen

Full Screen

converter.js

Source:converter.js Github

copy

Full Screen

1const fs = require('fs')2const path = require('path')3const { spawn } = require('child_process')4function toAudio(buffer, ext) {5 return new Promise((resolve, reject) => {6 let tmp = path.join(__dirname, '../tmp', + new Date + '.' + ext)7 let out = tmp + '.mp3'8 fs.writeFileSync(tmp, buffer)9 spawn('ffmpeg', [10 '-y',11 '-i',tmp,12 '-vn',13 '-ac', '2',14 '-b:a','128k',15 '-ar','44100',16 '-f', 'mp3',17 out18 ])19 .on('error', reject)20 .on('error', () => fs.unlinkSync(tmp))21 .on('close', () => {22 fs.unlinkSync(tmp)23 resolve(fs.readFileSync(out))24 if (fs.existsSync(out)) fs.unlinkSync(out)25 })26 })27}28function toPTT(buffer, ext) {29 return new Promise((resolve, reject) => {30 let tmp = path.join(__dirname, '../tmp', + new Date + '.' + ext)31 let out = tmp + '.opus'32 fs.writeFileSync(tmp, buffer)33 spawn('ffmpeg', [34 '-y',35 '-i',tmp,36 '-vn',37 '-c:a','libopus',38 '-b:a','128k',39 '-vbr','on',40 '-compression_level','10',41 out,42 ])43 .on('error', reject)44 .on('error', () => fs.unlinkSync(tmp))45 .on('close', () => {46 fs.unlinkSync(tmp)47 resolve(fs.readFileSync(out))48 if (fs.existsSync(out)) fs.unlinkSync(out)49 })50 })51}52function toVideo(buffer, ext) {53 return new Promise((resolve, reject) => {54 let tmp = path.join(__dirname, '../tmp', + new Date + '.' + ext)55 let out = tmp + '.mp4'56 fs.writeFileSync(tmp, buffer)57 spawn('ffmpeg', [58 '-y',59 '-i', tmp,60 '-c:v','libx264',61 '-c:a','aac',62 '-ab','192k',63 '-ar','44100',64 out65 ])66 .on('error', reject)67 .on('error', () => fs.unlinkSync(tmp))68 .on('close', () => {69 fs.unlinkSync(tmp)70 resolve(fs.readFileSync(out))71 if (fs.existsSync(out)) fs.unlinkSync(out)72 })73 })74}75module.exports = {76 toAudio,77 toPTT,78 toVideo...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2fs.unlink('file.txt', function (err) {3 if (err) throw err;4 console.log('File deleted!');5});6var fs = require('fs');7fs.unlinkSync('file.txt');8console.log('File deleted!');9var fs = require('fs');10fs.readdir('/Users/username/Documents', function (err, files) {11 if (err) throw err;12 files.forEach( function (file) {13 console.log(file);14 });15});16var fs = require('fs');17var files = fs.readdirSync('/Users/username/Documents');18files.forEach( function (file) {19 console.log(file);20});21var fs = require('fs');22fs.mkdir('/Users/username/Documents/newfolder', function (err) {23 if (err) throw err;24 console.log('Folder created!');25});26var fs = require('fs');27fs.mkdirSync('/Users/username/Documents/newfolder');28console.log('Folder created!');29var fs = require('fs');30fs.rmdir('/Users/username/Documents/newfolder', function (err) {31 if (err) throw err;32 console.log('Folder deleted!');33});34var fs = require('fs');35fs.rmdirSync('/Users/username/Documents/newfolder');36console.log('Folder deleted!');37var fs = require('fs');38fs.rename('/Users/username/Documents/newfolder', '/Users/username/Documents/newfolder2', function (err) {39 if (err) throw err;40 console.log('Folder renamed!');41});42var fs = require('fs');43fs.renameSync('/Users/username/Documents/newfolder', '/Users/username/Documents/newfolder2');44console.log('Folder renamed!');45var fs = require('fs');46fs.stat('/Users/username/Documents/newfolder', function (err, stats) {47 if (err) throw err;48 console.log(stats);49});

Full Screen

Using AI Code Generation

copy

Full Screen

1fs.writeFile('test.txt', 'Hello World!', 'utf8', function(err) {2 if (err) {3 console.log(err);4 } else {5 fs.unlink('test.txt', function(err) {6 if (err) {7 console.log(err);8 } else {9 console.log('File deleted!');10 }11 });12 }13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2fs.unlink('/Users/username/Desktop/appium-1.2.2/sample-code/apps/UICatalog.app.zip',function(err){3if(err) return console.log(err);4console.log('file deleted successfully');5});6var fs = require('fs');7fs.unlinkSync('/Users/username/Desktop/appium-1.2.2/sample-code/apps/UICatalog.app.zip');8console.log('file deleted successfully');9var fs = require('fs');10fs.rmdir('/Users/username/Desktop/appium-1.2.2/sample-code/apps/UICatalog.app.zip',function(err){11if(err) return console.log(err);12console.log('file deleted successfully');13});14var fs = require('fs');15fs.rmdirSync('/Users/username/Desktop/appium-1.2.2/sample-code/apps/UICatalog.app.zip');16console.log('file deleted successfully');17var fs = require('fs');18fs.mkdir('/Users/username/Desktop/appium-1.2.2/sample-code/apps/UICatalog.app.zip',function(err){19if(err) return console.log(err);20console.log('file deleted successfully');21});22var fs = require('fs');23fs.mkdirSync('/Users/username/Desktop/appium-1.2.2/sample-code/apps/UICatalog.app.zip');24console.log('file deleted successfully');25var fs = require('fs');26fs.readdir('/Users/username/Desktop/appium-1.2.2/sample-code/apps/UICatalog.app.zip',function(err){27if(err) return console.log(err);28console.log('file deleted successfully');29});30var fs = require('fs');31fs.readdirSync('/Users/username/Desktop/appium-1.2.2/sample-code/apps/UICatalog.app.zip');32console.log('file deleted successfully');

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2fs.unlink("C:\Users\test\Downloads\test.txt", function(err) {3 if (err) {4 return console.error(err);5 }6 console.log("File deleted successfully!");7});8var fs = require('fs');9fs.unlinkSync("C:\Users\test\Downloads\test.txt");10console.log("File deleted successfully!");11var driver = new webdriver.Builder()12 .withCapabilities({13 })14 .build();15driver.removeFile("sdcard/Download/test.txt");16var driver = new webdriver.Builder()17 .withCapabilities({18 })19 .build();20driver.removeFileSync("sdcard/Download/test

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful