yolkbot 0.1.0-alpha.51 → 0.1.0-alpha.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yolkbot",
3
3
  "description": "create a shell shockers (self) bot in under 10 lines.",
4
- "version": "0.1.0-alpha.51",
4
+ "version": "0.1.0-alpha.52",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
package/src/bot.js CHANGED
@@ -665,23 +665,25 @@ export class Bot {
665
665
  if (!IsBrowser) {
666
666
  const { existsSync, mkdirSync, readFileSync, writeFileSync } = await import('node:fs');
667
667
  const { join } = await import('node:path');
668
+ const { homedir } = await import('node:os');
668
669
 
669
- if (existsSync(join(import.meta.dirname, '..', 'data', 'cache', 'maps', `${name}-${hash}.json`))) {
670
- return JSON.parse(readFileSync(join(import.meta.dirname, '..', 'data', 'cache', 'maps', `${name}-${hash}.json`), 'utf-8'));
671
- }
670
+ const yolkbotCache = join(homedir(), '.yolkbot');
671
+ const mapCache = join(yolkbotCache, 'maps');
672
+
673
+ if (!existsSync(yolkbotCache)) mkdirSync(yolkbotCache);
674
+ if (!existsSync(mapCache)) mkdirSync(mapCache);
675
+
676
+ const mapFile = join(mapCache, `${name}-${hash}.json`);
672
677
 
673
- console.warn(`Map "${name}" not found in cache, fetching...`);
678
+ if (existsSync(mapFile))
679
+ return JSON.parse(readFileSync(mapFile, 'utf-8'));
680
+
681
+ console.log('map not in cache, IMPORT!!', name, hash);
674
682
 
675
683
  const data = await (await fetch(`https://${this.instance}/maps/${name}.json?${hash}`)).json();
676
684
 
677
- const dir = join(import.meta.dirname, '..', 'data', 'cache', 'maps');
678
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
685
+ writeFileSync(mapFile, JSON.stringify(data, null, 4), { flag: 'w+' });
679
686
 
680
- writeFileSync(
681
- join(dir, `${name}-${hash}.json`),
682
- JSON.stringify(data, null, 4),
683
- { flag: 'w+' }
684
- );
685
687
  return data;
686
688
  } else {
687
689
  const data = await (await fetch(`https://${this.instance}/maps/${name}.json?${hash}`)).json();