discord-mudlet-map 0.1.3 → 0.5.0
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/README.md +1 -1
- package/dist/bot-configurator.d.ts +5 -0
- package/dist/bot-configurator.d.ts.map +1 -0
- package/dist/bot-configurator.js +40 -0
- package/dist/bot-configurator.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/location-resolvers.d.ts +5 -0
- package/dist/location-resolvers.d.ts.map +1 -0
- package/dist/location-resolvers.js +10 -0
- package/dist/location-resolvers.js.map +1 -0
- package/dist/map-providers.d.ts +8 -0
- package/dist/map-providers.d.ts.map +1 -0
- package/dist/map-providers.js +45 -0
- package/dist/map-providers.js.map +1 -0
- package/dist/message-create.d.ts +4 -0
- package/dist/message-create.d.ts.map +1 -0
- package/dist/message-create.js +71 -0
- package/dist/message-create.js.map +1 -0
- package/dist/prepare-map.d.ts +4 -0
- package/dist/prepare-map.d.ts.map +1 -0
- package/dist/prepare-map.js +33 -0
- package/dist/prepare-map.js.map +1 -0
- package/dist/search-functions.d.ts +3 -0
- package/dist/search-functions.d.ts.map +1 -0
- package/dist/search-functions.js +15 -0
- package/dist/search-functions.js.map +1 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +50 -32
- package/CHANGELOG.md +0 -34
- package/events/messageCreate.js +0 -65
- package/index.js +0 -6
- package/maps/bot-configurator.js +0 -31
- package/maps/location-resolvers.js +0 -15
- package/maps/map-providers.js +0 -45
- package/maps/prepare-map.js +0 -44
- package/maps/search-functions.js +0 -19
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ let config = {
|
|
|
17
17
|
locationExtractor: LocationResolvers.plainRegexp("!achaea (\\d+)"),
|
|
18
18
|
provider: MapProviders.retryingDownloader("https://raw.githubusercontent.com/IRE-Mudlet-Mapping/AchaeaCrowdmap/gh-pages/Map/map", { retries: 5, delay : 10000 }) },
|
|
19
19
|
messageCreator: (key, area, room) => `${key} - ${area.areaName} (${room.id})`,
|
|
20
|
-
|
|
20
|
+
renderArea: false, // if missing or false will render part of map around location (recommended), otherwise will render whole area with locaiton marked
|
|
21
21
|
settings: {
|
|
22
22
|
isRound: true
|
|
23
23
|
} // Reffer to: https://github.com/Delwing/js-mudlet-map-renderer#settings-and-their-default-values
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot-configurator.d.ts","sourceRoot":"","sources":["../src/bot-configurator.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AASjD,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,YAAY,CAAC;AAuB5D,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,CAqBvE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import "konva/canvas-backend";
|
|
2
|
+
import { Events } from "discord.js";
|
|
3
|
+
import { MapRenderer, createSettings, } from "mudlet-map-renderer";
|
|
4
|
+
import mapCommand from "./message-create.js";
|
|
5
|
+
import { prepareMap } from "./prepare-map.js";
|
|
6
|
+
function buildRenderer(entry, reader) {
|
|
7
|
+
const options = entry.renderer ?? {};
|
|
8
|
+
if (entry.settings && !options.settings) {
|
|
9
|
+
console.warn("config.settings is deprecated, use config.renderer.settings instead");
|
|
10
|
+
}
|
|
11
|
+
const settings = options.settings ?? entry.settings ?? createSettings();
|
|
12
|
+
if (!entry.renderArea && settings.areaName === undefined) {
|
|
13
|
+
settings.areaName = false;
|
|
14
|
+
}
|
|
15
|
+
const renderer = new MapRenderer(reader, settings);
|
|
16
|
+
if (options.style) {
|
|
17
|
+
renderer.setStyle(options.style);
|
|
18
|
+
}
|
|
19
|
+
return renderer;
|
|
20
|
+
}
|
|
21
|
+
export function configure(client, config) {
|
|
22
|
+
const configurator = () => {
|
|
23
|
+
for (const key of Object.keys(config)) {
|
|
24
|
+
prepareMap(key, config[key].provider)
|
|
25
|
+
.then((reader) => {
|
|
26
|
+
config[key].reader = reader;
|
|
27
|
+
config[key].mapRenderer = buildRenderer(config[key], reader);
|
|
28
|
+
console.log(`${key} map ready!`);
|
|
29
|
+
})
|
|
30
|
+
.catch((err) => console.log(err));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
configurator();
|
|
34
|
+
client.on(Events.MessageCreate, mapCommand(config));
|
|
35
|
+
client.on(Events.ClientReady, () => {
|
|
36
|
+
console.log("Bot enhanced with Mudlet maps ready.");
|
|
37
|
+
});
|
|
38
|
+
return configurator;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=bot-configurator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot-configurator.js","sourceRoot":"","sources":["../src/bot-configurator.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAe,MAAM,YAAY,CAAC;AACjD,OAAO,EACL,WAAW,EACX,cAAc,GAEf,MAAM,qBAAqB,CAAC;AAE7B,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,SAAS,aAAa,CACpB,KAAqB,EACrB,MAAiB;IAEjB,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;IACrC,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACxC,OAAO,CAAC,IAAI,CACV,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,IAAI,cAAc,EAAE,CAAC;IACxE,IAAI,CAA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AAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { configure } from "./bot-configurator.js";
|
|
2
|
+
export * as LocationResolvers from "./location-resolvers.js";
|
|
3
|
+
export * as MapProviders from "./map-providers.js";
|
|
4
|
+
export * as SearchFunctions from "./search-functions.js";
|
|
5
|
+
export { prepareMap } from "./prepare-map.js";
|
|
6
|
+
export type { MapConfig, MapConfigEntry, MapProvider, LocationExtractor, MessageCreator, RendererOptions, } from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,iBAAiB,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EACV,SAAS,EACT,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { configure } from "./bot-configurator.js";
|
|
2
|
+
export * as LocationResolvers from "./location-resolvers.js";
|
|
3
|
+
export * as MapProviders from "./map-providers.js";
|
|
4
|
+
export * as SearchFunctions from "./search-functions.js";
|
|
5
|
+
export { prepareMap } from "./prepare-map.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,iBAAiB,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MapReader } from "mudlet-map-renderer";
|
|
2
|
+
import type { LocationExtractor } from "./types.js";
|
|
3
|
+
export type SearchFunction = (matches: RegExpMatchArray, reader: MapReader) => string | number;
|
|
4
|
+
export declare function plainRegexp(regexp: RegExp | string, searchFunction?: SearchFunction): LocationExtractor;
|
|
5
|
+
//# sourceMappingURL=location-resolvers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location-resolvers.d.ts","sourceRoot":"","sources":["../src/location-resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG,CAC3B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,SAAS,KACd,MAAM,GAAG,MAAM,CAAC;AAErB,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,cAAc,CAAC,EAAE,cAAc,GAC9B,iBAAiB,CAOnB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function plainRegexp(regexp, searchFunction) {
|
|
2
|
+
const fn = searchFunction ?? ((arg) => arg[1]);
|
|
3
|
+
return (message, reader) => {
|
|
4
|
+
const matches = message.match(regexp);
|
|
5
|
+
if (matches)
|
|
6
|
+
return fn(matches, reader);
|
|
7
|
+
return false;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=location-resolvers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location-resolvers.js","sourceRoot":"","sources":["../src/location-resolvers.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,WAAW,CACzB,MAAuB,EACvB,cAA+B;IAE/B,MAAM,EAAE,GAAmB,cAAc,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,OAAO;YAAE,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MapProvider } from "./types.js";
|
|
2
|
+
export interface RetryOptions {
|
|
3
|
+
retries?: number;
|
|
4
|
+
delay?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function downloader(url: string): MapProvider;
|
|
7
|
+
export declare function retryingDownloader(url: string, retryOptions?: RetryOptions): MapProvider;
|
|
8
|
+
//# sourceMappingURL=map-providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-providers.d.ts","sourceRoot":"","sources":["../src/map-providers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAwBnD;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,YAAY,GAC1B,WAAW,CAoBb"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import http from "http";
|
|
2
|
+
import https from "https";
|
|
3
|
+
export function downloader(url) {
|
|
4
|
+
return (writeStream) => new Promise((resolve, reject) => {
|
|
5
|
+
const protocol = url.startsWith("https") ? https : http;
|
|
6
|
+
protocol
|
|
7
|
+
.get(url, (response) => {
|
|
8
|
+
const status = response.statusCode ?? 500;
|
|
9
|
+
if (status < 400) {
|
|
10
|
+
response.pipe(writeStream);
|
|
11
|
+
writeStream.on("finish", () => {
|
|
12
|
+
writeStream.close();
|
|
13
|
+
resolve();
|
|
14
|
+
});
|
|
15
|
+
response.on("error", reject);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
reject(new Error(`Can't download map: ${response.statusCode} ${response.statusMessage}`));
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
.on("error", reject);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function retryingDownloader(url, retryOptions) {
|
|
25
|
+
return (writeStream) => {
|
|
26
|
+
const options = {
|
|
27
|
+
retries: 3,
|
|
28
|
+
delay: 1000,
|
|
29
|
+
...retryOptions,
|
|
30
|
+
};
|
|
31
|
+
return downloader(url)(writeStream).catch((err) => {
|
|
32
|
+
if (options.retries > 0) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
options.retries--;
|
|
36
|
+
console.log(`Retrying download from ${url}`);
|
|
37
|
+
resolve(retryingDownloader(url, options)(writeStream));
|
|
38
|
+
}, options.delay);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
throw err;
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=map-providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-providers.js","sourceRoot":"","sources":["../src/map-providers.ts"],"names":[],"mappings":"AAAA,OAAO,IAA8B,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,MAAM,UAAU,UAAU,CA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CAAC;gBACxB,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;oBACnC,UAAU,CAAC,GAAG,EAAE;wBACd,OAAO,CAAC,OAAO,EAAE,CAAC;wBAClB,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC;wBAC7C,OAAO,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;oBACzD,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC,CAAC,CAAC;YACL,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-create.d.ts","sourceRoot":"","sources":["../src/message-create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,YAAY,CAAC;AAKlE,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,MAAM,EAAE,SAAS,IACpC,SAAS,OAAO,mBAwE/B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { PngBytesExporter } from "mudlet-map-renderer";
|
|
2
|
+
const defaultMessageCreator = (key, area) => `${key} - ${area.areaName}`;
|
|
3
|
+
export default function mapCommand(config) {
|
|
4
|
+
return async (message) => {
|
|
5
|
+
const channel = message.channel;
|
|
6
|
+
if (!("send" in channel))
|
|
7
|
+
return;
|
|
8
|
+
for (const key of Object.keys(config)) {
|
|
9
|
+
const element = config[key];
|
|
10
|
+
element.renderArea = element.renderArea ?? false;
|
|
11
|
+
const reader = element.reader;
|
|
12
|
+
if (!reader)
|
|
13
|
+
continue;
|
|
14
|
+
const extracted = element.locationExtractor(message.content, reader);
|
|
15
|
+
if (!extracted)
|
|
16
|
+
continue;
|
|
17
|
+
if (!element.mapRenderer) {
|
|
18
|
+
await channel.send(`${key} - map not ready`);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const roomId = Number(extracted);
|
|
22
|
+
let room;
|
|
23
|
+
let area;
|
|
24
|
+
try {
|
|
25
|
+
room = reader.getRoom(roomId);
|
|
26
|
+
area = reader.getArea(room.area);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
await channel.send(`${key} - no location ID`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!room || !area) {
|
|
33
|
+
await channel.send(`${key} - no location ID`);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const renderer = element.mapRenderer;
|
|
38
|
+
renderer.drawArea(room.area, room.z);
|
|
39
|
+
const bytes = renderer.export(new PngBytesExporter({
|
|
40
|
+
width: 1200,
|
|
41
|
+
height: 1200,
|
|
42
|
+
roomId: element.renderArea ? undefined : roomId,
|
|
43
|
+
padding: element.renderArea ? 3 : 10,
|
|
44
|
+
overlays: { position: { roomId } },
|
|
45
|
+
}));
|
|
46
|
+
if (!bytes) {
|
|
47
|
+
console.log(`${key} - PNG export returned empty buffer`);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const areaInfo = {
|
|
51
|
+
areaName: area.getAreaName(),
|
|
52
|
+
areaId: area.getAreaId(),
|
|
53
|
+
};
|
|
54
|
+
const content = (element.messageCreator ?? defaultMessageCreator)(key, areaInfo, room);
|
|
55
|
+
await channel.send({
|
|
56
|
+
content,
|
|
57
|
+
files: [
|
|
58
|
+
{
|
|
59
|
+
attachment: Buffer.from(bytes),
|
|
60
|
+
name: `${key} - ${roomId}.png`,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.log(err);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=message-create.js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gBACF,MAAM,OAAO,CAAC,IAAI,CAAC;oBACjB,OAAO;oBACP,KAAK,EAAE;wBACL;4BACE,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;4BAC9B,IAAI,EAAE,GAAG,GAAG,MAAM,MAAM,MAAM;yBAC/B;qBACF;iBACF,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare-map.d.ts","sourceRoot":"","sources":["../src/prepare-map.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAmB9C,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,WAAW,GACpB,OAAO,CAAC,SAAS,CAAC,CAgBpB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { MudletMapReader } from "mudlet-map-binary-reader";
|
|
4
|
+
import { MapReader } from "mudlet-map-renderer";
|
|
5
|
+
const downloadDir = "downloads";
|
|
6
|
+
function ensureDirectoryExists(dirPath) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
fs.access(dirPath, (err) => {
|
|
9
|
+
if (err) {
|
|
10
|
+
fs.mkdir(dirPath, { recursive: true }, (mkErr) => {
|
|
11
|
+
if (mkErr)
|
|
12
|
+
reject(mkErr);
|
|
13
|
+
else
|
|
14
|
+
resolve();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
resolve();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export async function prepareMap(key, provider) {
|
|
24
|
+
const dir = path.join(downloadDir, key);
|
|
25
|
+
await ensureDirectoryExists(dir);
|
|
26
|
+
await provider(fs.createWriteStream(path.join(dir, "map.dat")));
|
|
27
|
+
const map = MudletMapReader.read(path.join(dir, "map.dat"));
|
|
28
|
+
MudletMapReader.export(map, `${dir}/`);
|
|
29
|
+
const mapData = JSON.parse(fs.readFileSync(path.join(dir, "mapExport.json"), "utf8"));
|
|
30
|
+
const mapColors = JSON.parse(fs.readFileSync(path.join(dir, "colors.json"), "utf8"));
|
|
31
|
+
return new MapReader(mapData, mapColors);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=prepare-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare-map.js","sourceRoot":"","sources":["../src/prepare-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhD,MAAM,WAAW,GAAG,WAAW,CAAC;AAEhC,SAAS,qBAAqB,CAAC,OAAe;IAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACzB,IAAI,GAAG,EAAE,CAAC;gBACR,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE;oBAC/C,IAAI,KAAK;wBAAE,MAAM,CAAC,KAAK,CAAC,CAAC;;wBACpB,OAAO,EAAE,CAAC;gBACjB,CAAC,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,QAAqB;IAErB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IACxC,MAAM,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,QAAQ,CAAC,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAEhE,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5D,eAAe,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;IAEvC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CACxB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC,CAC1D,CAAC;IACF,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAC1B,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CACvD,CAAC;IAEF,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-functions.d.ts","sourceRoot":"","sources":["../src/search-functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIrD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,SAAS,GAChB,MAAM,GAAG,MAAM,CAWjB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
let hashCache;
|
|
2
|
+
export function hashOrIdSearch(matches, reader) {
|
|
3
|
+
const raw = matches[1];
|
|
4
|
+
if (!Number.isNaN(parseInt(raw, 10)))
|
|
5
|
+
return raw;
|
|
6
|
+
if (!hashCache) {
|
|
7
|
+
hashCache = {};
|
|
8
|
+
for (const room of reader.getRooms()) {
|
|
9
|
+
if (room.hash)
|
|
10
|
+
hashCache[room.hash] = room.id;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return hashCache[raw] ?? -1;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=search-functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-functions.js","sourceRoot":"","sources":["../src/search-functions.ts"],"names":[],"mappings":"AAEA,IAAI,SAA6C,CAAC;AAElD,MAAM,UAAU,cAAc,CAC5B,OAAyB,EACzB,MAAiB;IAEjB,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IAEjD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,EAAE,CAAC;QACf,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,IAAI;gBAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { WriteStream } from "fs";
|
|
2
|
+
import type { MapReader, MapRenderer, Settings, Style } from "mudlet-map-renderer";
|
|
3
|
+
export type MapProvider = (writeStream: WriteStream) => Promise<void>;
|
|
4
|
+
export type LocationExtractor = (message: string, reader: MapReader) => string | number | false;
|
|
5
|
+
export type Room = ReturnType<MapReader["getRoom"]>;
|
|
6
|
+
export type MessageCreator = (key: string, area: {
|
|
7
|
+
areaName: string;
|
|
8
|
+
areaId: number;
|
|
9
|
+
}, room: Room) => string;
|
|
10
|
+
export interface RendererOptions {
|
|
11
|
+
settings?: Settings;
|
|
12
|
+
style?: Style;
|
|
13
|
+
}
|
|
14
|
+
export interface MapConfigEntry {
|
|
15
|
+
provider: MapProvider;
|
|
16
|
+
locationExtractor: LocationExtractor;
|
|
17
|
+
messageCreator?: MessageCreator;
|
|
18
|
+
renderArea?: boolean;
|
|
19
|
+
renderer?: RendererOptions;
|
|
20
|
+
/** @deprecated Use `renderer.settings` instead. */
|
|
21
|
+
settings?: Settings;
|
|
22
|
+
reader?: MapReader;
|
|
23
|
+
mapRenderer?: MapRenderer;
|
|
24
|
+
}
|
|
25
|
+
export type MapConfig = Record<string, MapConfigEntry>;
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEnF,MAAM,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtE,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,SAAS,KACd,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAE7B,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC1C,IAAI,EAAE,IAAI,KACP,MAAM,CAAC;AAEZ,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,WAAW,CAAC;IACtB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,32 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "discord-mudlet-map",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "discord-mudlet-map",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mudlet",
|
|
19
|
+
"map",
|
|
20
|
+
"mud",
|
|
21
|
+
"discord"
|
|
22
|
+
],
|
|
23
|
+
"author": "Delwing",
|
|
24
|
+
"repository": {
|
|
25
|
+
"url": "git+https://github.com/Delwing/discord-mudlet-map.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/Delwing/discord-mudlet-map/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/Delwing/discord-mudlet-map#readme",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"prepublishOnly": "yarn build"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"canvas": "^3.2.3",
|
|
37
|
+
"konva": "^10.2.4",
|
|
38
|
+
"mudlet-map-binary-reader": "^0.7.1",
|
|
39
|
+
"mudlet-map-renderer": "^0.37.0-konva"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"discord.js": "^14.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^20.0.0",
|
|
46
|
+
"discord.js": "^14.0.0",
|
|
47
|
+
"dotenv": "^16.0.0",
|
|
48
|
+
"typescript": "^5.4.0"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# 0.2.0
|
|
2
|
-
- add message creator configuration
|
|
3
|
-
|
|
4
|
-
# 0.1.2
|
|
5
|
-
- fix hash search
|
|
6
|
-
|
|
7
|
-
# 0.1.1
|
|
8
|
-
- fix dependency
|
|
9
|
-
|
|
10
|
-
# 0.1.0
|
|
11
|
-
- add location search functions
|
|
12
|
-
- fix no room handling
|
|
13
|
-
|
|
14
|
-
# 0.0.7
|
|
15
|
-
- fix map downloader - should prevent attempts to read map before stream finishes writes, thus failing to read map
|
|
16
|
-
- move configuration loop into bot-configurator.js
|
|
17
|
-
|
|
18
|
-
# 0.0.6
|
|
19
|
-
- remove debug messages
|
|
20
|
-
|
|
21
|
-
# 0.0.5
|
|
22
|
-
- Use limitting function for generating area image
|
|
23
|
-
|
|
24
|
-
# 0.0.4
|
|
25
|
-
- Update dependencies
|
|
26
|
-
|
|
27
|
-
# 0.0.3
|
|
28
|
-
- Add way of customizing map rendering settings
|
|
29
|
-
|
|
30
|
-
# 0.0.2
|
|
31
|
-
- Fix README example
|
|
32
|
-
|
|
33
|
-
# 0.0.1
|
|
34
|
-
- Initial release
|
package/events/messageCreate.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const { Message } = require("discord.js");
|
|
2
|
-
const { Renderer } = require("mudlet-map-renderer");
|
|
3
|
-
const sharp = require("sharp");
|
|
4
|
-
|
|
5
|
-
const defaultMessageCreator = function (key, area, room) {
|
|
6
|
-
return `${key} - ${area.areaName}`;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
module.exports = (config) => {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @param {Message} message
|
|
13
|
-
*/
|
|
14
|
-
return async (message) => {
|
|
15
|
-
Object.keys(config).forEach((key) => {
|
|
16
|
-
let element = config[key];
|
|
17
|
-
let reader = element.reader;
|
|
18
|
-
let roomId = element.locationExtractor(message.content, reader);
|
|
19
|
-
if (roomId) {
|
|
20
|
-
if (!reader) {
|
|
21
|
-
message.channel.send(`${key} - map not ready`);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
let area = reader.getAreaByRoomId(roomId);
|
|
25
|
-
let room = reader.getRoomById(roomId);
|
|
26
|
-
if (!area || !room) {
|
|
27
|
-
message.channel.send(`${key} - no location ID`);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (element.renderFragment) {
|
|
31
|
-
area = area.limit(roomId, 15);
|
|
32
|
-
if (element.settings == undefined) {
|
|
33
|
-
element.settings = {};
|
|
34
|
-
}
|
|
35
|
-
if (element.settings.areaName == undefined) {
|
|
36
|
-
element.settings.areaName = false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async function render() {
|
|
40
|
-
let renderer = new Renderer(
|
|
41
|
-
null,
|
|
42
|
-
reader,
|
|
43
|
-
area,
|
|
44
|
-
reader.getColors(),
|
|
45
|
-
element.settings
|
|
46
|
-
);
|
|
47
|
-
renderer.renderPosition(roomId);
|
|
48
|
-
sharp(Buffer.from(renderer.exportSvg(roomId, 10)))
|
|
49
|
-
.png()
|
|
50
|
-
.toBuffer()
|
|
51
|
-
.then((buffer) => {
|
|
52
|
-
message.channel.send({
|
|
53
|
-
content: (element.messageCreator || defaultMessageCreator)(key, area, room),
|
|
54
|
-
files: [{ attachment: buffer, name: `${key} - ${roomId}.png` }],
|
|
55
|
-
});
|
|
56
|
-
})
|
|
57
|
-
.catch(function (err) {
|
|
58
|
-
console.log(err);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
render();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
};
|
package/index.js
DELETED
package/maps/bot-configurator.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const { Client, version } = require("discord.js");
|
|
2
|
-
const mapCommand = require("../events/messageCreate");
|
|
3
|
-
const MapResolver = require("../maps/prepare-map");
|
|
4
|
-
const major = parseInt(version.substring(0, version.indexOf(".")));
|
|
5
|
-
const eventName = major >= 13 ? "messageCreate" : "message";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {Client} client
|
|
10
|
-
*/
|
|
11
|
-
module.exports = (client, config) => {
|
|
12
|
-
const configurator = () => {
|
|
13
|
-
Object.keys(config).map(async (key) => {
|
|
14
|
-
MapResolver.prepareMap(key, config[key].provider)
|
|
15
|
-
.then((reader) => {
|
|
16
|
-
config[key].reader = reader;
|
|
17
|
-
console.log(`${key} map ready!`);
|
|
18
|
-
})
|
|
19
|
-
.catch((err) => console.log(err));
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
configurator();
|
|
23
|
-
|
|
24
|
-
client.on(eventName, mapCommand(config));
|
|
25
|
-
|
|
26
|
-
client.on("ready", () => {
|
|
27
|
-
console.log("Bot enhanced with Mudlet maps ready.");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return configurator
|
|
31
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
let plainRegexp = (regexp, searchFunction) => (message, reader) => {
|
|
2
|
-
if (!searchFunction) {
|
|
3
|
-
searchFunction = (arg) => arg[1]
|
|
4
|
-
}
|
|
5
|
-
let matches = message.match(regexp)
|
|
6
|
-
if (matches) {
|
|
7
|
-
return searchFunction(matches, reader);
|
|
8
|
-
} else {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
plainRegexp: plainRegexp,
|
|
15
|
-
};
|
package/maps/map-providers.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const http = require("http");
|
|
2
|
-
const https = require("https");
|
|
3
|
-
|
|
4
|
-
let downloader = (url) => (writeStream) => {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
let protocol = url.startsWith("https") ? https : http;
|
|
7
|
-
protocol.get(url, function (response) {
|
|
8
|
-
if (response.statusCode < 400) {
|
|
9
|
-
response.pipe(writeStream);
|
|
10
|
-
writeStream.on("finish", () => {
|
|
11
|
-
writeStream.close()
|
|
12
|
-
resolve()
|
|
13
|
-
})
|
|
14
|
-
response.on("error", (err) => reject(err));
|
|
15
|
-
} else {
|
|
16
|
-
reject(new Error(`Can't download map: ${response.statusCode} ${response.statusMessage}`));
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
let retryingDownloader = (url, retryOptions) => (writeStream) => {
|
|
23
|
-
let defaultOptions = {
|
|
24
|
-
retries: 3,
|
|
25
|
-
delay: 1000,
|
|
26
|
-
};
|
|
27
|
-
let options = { ...defaultOptions, ...retryOptions };
|
|
28
|
-
return downloader(url)(writeStream).catch((err) => {
|
|
29
|
-
if (options.retries > 0) {
|
|
30
|
-
return new Promise((resolve, reject) =>
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
options.retries--;
|
|
33
|
-
console.log(`Retrying download from ${url}`)
|
|
34
|
-
resolve(retryingDownloader(url, options)(writeStream));
|
|
35
|
-
}, options.delay)
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
throw err;
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
module.exports = {
|
|
43
|
-
downloader: downloader,
|
|
44
|
-
retryingDownloader: retryingDownloader,
|
|
45
|
-
};
|
package/maps/prepare-map.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
|
|
3
|
-
const { MudletMapReader } = require("mudlet-map-binary-reader");
|
|
4
|
-
const { MapReader } = require("mudlet-map-renderer");
|
|
5
|
-
|
|
6
|
-
const downloadDir = "downloads";
|
|
7
|
-
|
|
8
|
-
function ensureDirectoryExists(key) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
fs.access(key, (err) => {
|
|
11
|
-
if (err) {
|
|
12
|
-
fs.mkdir(key, { recursive: true }, (err) => {
|
|
13
|
-
if (!err) {
|
|
14
|
-
resolve();
|
|
15
|
-
} else {
|
|
16
|
-
reject(err);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
} else {
|
|
20
|
-
resolve();
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function prepareMap(key, provider) {
|
|
27
|
-
return ensureDirectoryExists(`./${downloadDir}/${key}`)
|
|
28
|
-
.then(() => provider(fs.createWriteStream(`./${downloadDir}/${key}/map.dat`)))
|
|
29
|
-
.then(
|
|
30
|
-
() =>
|
|
31
|
-
new Promise((resolve, reject) => {
|
|
32
|
-
let map = MudletMapReader.read(`./${downloadDir}/${key}/map.dat`);
|
|
33
|
-
MudletMapReader.export(map, `./${downloadDir}/${key}/`);
|
|
34
|
-
let mapData = JSON.parse(fs.readFileSync(`./${downloadDir}/${key}/mapExport.json`));
|
|
35
|
-
let mapColors = JSON.parse(fs.readFileSync(`./${downloadDir}/${key}/colors.json`));
|
|
36
|
-
let reader = new MapReader(mapData, mapColors);
|
|
37
|
-
resolve(reader);
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
module.exports = {
|
|
43
|
-
prepareMap: prepareMap,
|
|
44
|
-
};
|
package/maps/search-functions.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
let hashCache;
|
|
2
|
-
|
|
3
|
-
let hashOrIdSearch = (matches, reader) => {
|
|
4
|
-
if (!isNaN(parseInt(matches[1]))) {
|
|
5
|
-
return matches[1];
|
|
6
|
-
} else {
|
|
7
|
-
if (!hashCache) {
|
|
8
|
-
hashCache = {};
|
|
9
|
-
Object.entries(reader.roomIndex).forEach((room, index) => {
|
|
10
|
-
hashCache[room[1].hash] = room[1].id;
|
|
11
|
-
})
|
|
12
|
-
}
|
|
13
|
-
return hashCache[matches[1]] ?? -1;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
hashOrIdSearch
|
|
19
|
-
};
|