Skip to content

Commit

Permalink
Add additional error messages to basefile upload
Browse files Browse the repository at this point in the history
  • Loading branch information
OliBomby committed Oct 3, 2023
1 parent 7b97d99 commit ef98776
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
5 changes: 3 additions & 2 deletions osu-collaboration-bot/Commands/ProjectModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public async Task UploadBaseFile([RequireProjectManager][Autocomplete(typeof(Pro
return;
}

if (!await _fileHandler.DownloadBaseFile(Context.Guild, projectName, attachment)) {
await RespondAsync(Strings.UploadBaseFileFail);
string errorMsg = await _fileHandler.DownloadBaseFile(Context.Guild, projectName, attachment);
if (errorMsg is not null) {
await RespondAsync(errorMsg);
return;
}

Expand Down
27 changes: 27 additions & 0 deletions osu-collaboration-bot/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions osu-collaboration-bot/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,13 @@ Replace the part with the [square brackets] with the relevant value.</value>
<data name="GuildCreateRolesFail" xml:space="preserve">
<value>Could not change create roles setting.</value>
</data>
<data name="FileTypeNeedsToBeOsu" xml:space="preserve">
<value>The file type needs to be '.osu'.</value>
</data>
<data name="CouldNotFindLocalProjectPath" xml:space="preserve">
<value>Could not find local project path.</value>
</data>
<data name="CouldNotCreateUri" xml:space="preserve">
<value>Could not create download URI.</value>
</data>
</root>
16 changes: 10 additions & 6 deletions osu-collaboration-bot/Services/FileHandlingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using CsvHelper.Configuration.Attributes;
using Discord;
using NLog;
using Strings = CollaborationBot.Resources.Strings;

namespace CollaborationBot.Services {
public class FileHandlingService {
Expand All @@ -34,15 +35,18 @@ public void Initialize(string path) {
_path = path;
}

public async Task<bool> DownloadBaseFile(IGuild guild, string projectName, Attachment att) {
public async Task<string> DownloadBaseFile(IGuild guild, string projectName, Attachment att) {
try {
if (!IsFilePermissible(att.Url, PermissibleFileType.DotOsu)) return false;
if (!IsFilePermissible(att.Url, PermissibleFileType.DotOsu)) return Strings.FileTypeNeedsToBeOsu;

var localProjectPath = GetProjectPath(guild, projectName);

if (!Directory.Exists(localProjectPath)) return false;
if (!Directory.Exists(localProjectPath)) {
logger.Error("Could not find local project path: {projectPath}", localProjectPath);
return Strings.CouldNotFindLocalProjectPath;
}

if (!Uri.TryCreate(att.Url, UriKind.Absolute, out var uri)) return false;
if (!Uri.TryCreate(att.Url, UriKind.Absolute, out var uri)) return Strings.CouldNotCreateUri;

var oldFilePath = GetProjectBaseFilePath(guild, projectName);
var filePath = Path.Combine(localProjectPath, att.Filename);
Expand All @@ -57,11 +61,11 @@ public async Task<bool> DownloadBaseFile(IGuild guild, string projectName, Attac
File.Delete(oldFilePath);
}

return true;
return null;
}
catch (Exception e) {
logger.Error(e);
return false;
return Strings.UploadBaseFileFail;
}
}

Expand Down

0 comments on commit ef98776

Please sign in to comment.