Skip to content

Commit

Permalink
tmx fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reaby committed Jul 8, 2024
1 parent afba653 commit fad5ad9
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions core/plugins/tmx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default class Tmx extends Plugin {
async onLoad() {
tmc.addCommand("//add", this.addMap.bind(this), "Add map from TMX");
tmc.addCommand("//addpack", this.addMapPack.bind(this), "Add map pack from TMX");
tmc.addCommand("//cancelpack", () => {
tmc.chat("Admin cancelled the download!");
this.cancelToken = true;
}, "Cancel pack download")
}

async onUnload() {
Expand Down Expand Up @@ -80,7 +84,7 @@ export default class Tmx extends Plugin {
tmc.chat("¤info¤To cancel: ¤cmd¤//addpack cancel", login);
return;
}

if (params[0].toLowerCase() === "cancel") {
this.cancelToken = true;
tmc.chat("Map Pack download cancelled.", login);
Expand Down Expand Up @@ -158,7 +162,12 @@ export default class Tmx extends Plugin {
}
await tmc.server.call("AddMap", filePath);
await tmc.maps.syncMaplist();
tmc.chat(`Added MapId ¤white¤${map.id} ¤info¤from ¤white¤${map.baseUrl}!`);
const info = await tmc.server.call("GetMapInfo", `${tmc.mapsPath}${filePath}`); await tmc.maps.syncMaplist();
const author = info.AuthorNickname || info.Author || "n/a";
tmc.chat(`¤info¤Map ¤white¤${info.Name} ¤info¤by ¤white¤${author} ¤info¤from ¤white¤${map.baseUrl}!`);
if (Object.keys(tmc.plugins).includes("maps")) {
await tmc.chatCmd.execute(login, `/addqueue ${info.UId}`);
}
return;
} catch (err: any) {
tmc.chat(err, login);
Expand All @@ -171,7 +180,12 @@ export default class Tmx extends Plugin {
fs.writeFileSync(`${tmc.mapsPath}${filePath}`, Buffer.from(abuffer));
await tmc.server.call("AddMap", filePath);
await tmc.maps.syncMaplist();
tmc.chat(`Added MapId ¤white¤${map.id} ¤info¤from ¤white¤${map.baseUrl}!`);
const info = await tmc.server.call("GetMapInfo", `${tmc.mapsPath}${filePath}`); await tmc.maps.syncMaplist();
const author = info.AuthorNickname || info.Author || "n/a";
tmc.chat(`¤info¤Added map ¤white¤${info.Name} ¤info¤by ¤white¤${author} ¤info¤from ¤white¤${map.baseUrl}!`);
if (Object.keys(tmc.plugins).includes("maps")) {
await tmc.chatCmd.execute(login, `/addqueue ${info.UId}`);
}
}

async parseAndDownloadTrackPack(packId: string, login: string) {
Expand Down Expand Up @@ -225,9 +239,9 @@ export default class Tmx extends Plugin {

const res = await fetch(url, { keepalive: false });
const json: any = await res.json();
tmc.chat("Processing Map Pack " + packId);
tmc.chat("Processing Map Pack ¤white¤" + packId);
if (!json) {
tmc.chat(`Error while adding Pack ID ${packId}: ${res.statusText}`, login);
tmc.chat(`¤error¤Error while adding Pack ID ${packId}: ${res.statusText}`, login);
}
let results = json;
if (tmc.game.Name === "TmForever") results = json.Results;
Expand All @@ -236,13 +250,13 @@ export default class Tmx extends Plugin {
try {
let mapName = tmc.game.Name === "TmForever" ? data.TrackName : data.GbxMapName;
let id = tmc.game.Name === "TmForever" ? data.TrackId : data.TrackID;
tmc.chat(`Downloading: ${mapName}`);
tmc.chat(`Downloading: ¤white¤${mapName}`);
const map: Map = { id, baseUrl, site }
await this.downloadMap(map, login);
} catch (err: any) {
tmc.chat(`¤error¤Error: ${err.message}`);
}
}
tmc.chat("All Done!");
tmc.chat("¤white¤Done!");
}
}

0 comments on commit fad5ad9

Please sign in to comment.