-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #535 from gowon-bot/534-move-rymimport-to-use-lilac
[534] Change !rymimport to use lilac
- Loading branch information
Showing
19 changed files
with
265 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import fetch from "node-fetch"; | ||
import streamToString from "stream-to-string"; | ||
import { WrongFileFormatAttachedError } from "../../../errors/commands/library"; | ||
import { AttachmentArgument } from "../../../lib/context/arguments/argumentTypes/discord/AttachmentArgument"; | ||
import { ArgumentsMap } from "../../../lib/context/arguments/types"; | ||
import { RatingsImportProgressView } from "../../../lib/ui/views/RatingsImportProgressView"; | ||
import { RateYourMusicChildCommand } from "./RateYourMusicChildCommand"; | ||
|
||
const args = { | ||
ratings: new AttachmentArgument({ | ||
index: 0, | ||
description: "The file containing your RateYourMusic ratings", | ||
required: { | ||
customMessage: `Please attach your ratings! (See \`rym help\` for more info)`, | ||
}, | ||
}), | ||
} satisfies ArgumentsMap; | ||
|
||
export class ImportRatings extends RateYourMusicChildCommand<typeof args> { | ||
idSeed = "sonamoo high d"; | ||
aliases = ["rymimport", "rymsimport"]; | ||
description = | ||
"Import your RateYourMusic ratings. See rym help for more info on how to import"; | ||
|
||
arguments = args; | ||
|
||
slashCommand = true; | ||
|
||
async run() { | ||
await this.getMentions({ | ||
senderRequired: true, | ||
syncedRequired: true, | ||
}); | ||
|
||
const ratings = await this.getRatings(); | ||
|
||
const ratingsProgress = this.lilacRatingsService.importProgress(this.ctx, { | ||
discordID: this.author.id, | ||
}); | ||
|
||
const embed = this.minimalEmbed().setDescription(`Preparing import...`); | ||
|
||
await this.reply(embed); | ||
|
||
const syncProgressView = new RatingsImportProgressView( | ||
this.ctx, | ||
embed, | ||
ratingsProgress | ||
); | ||
|
||
syncProgressView.subscribeToObservable(); | ||
|
||
await this.lilacRatingsService.import(this.ctx, ratings, { | ||
discordID: this.author.id, | ||
}); | ||
} | ||
|
||
private async getRatings(): Promise<string> { | ||
const ratingsAttachment = this.parsedArguments.ratings; | ||
|
||
const file = await fetch(ratingsAttachment.url); | ||
|
||
const fileContent = await streamToString(file.body); | ||
|
||
const ratings = fileContent.trim(); | ||
|
||
if (!ratings.startsWith("RYM Album,")) { | ||
throw new WrongFileFormatAttachedError(); | ||
} | ||
|
||
return ratings; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.