Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Added Multilanguage support by Languagefiles #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20,300 changes: 0 additions & 20,300 deletions Requestrr.WebApi/ClientApp/package-lock.json

This file was deleted.

20 changes: 17 additions & 3 deletions Requestrr.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,31 @@ public class Program
{
public static int Port = 4545;
public static string BaseUrl = string.Empty;

public static dynamic LocalizedStrings = null;
public static void Main(string[] args)
{
UpdateSettingsFile();

CheckForLanguageFiles();
Port = (int)SettingsFile.Read().Port;
BaseUrl = SettingsFile.Read().BaseUrl;

LocalizedStrings = Localization.Read(SettingsFile.Read().Language.ToString());
CreateWebHostBuilder(args).Build().Run();
}

private static void CheckForLanguageFiles()
{
if(!Directory.Exists("config/local"))
{
Directory.CreateDirectory("config/local");
FileInfo[] files = new DirectoryInfo("local/").GetFiles();
foreach(FileInfo file in files)
{
string tempPath = Path.Combine("config/local",file.Name);
file.CopyTo(tempPath, false);
}
}
}

private static void UpdateSettingsFile()
{
if (!File.Exists(SettingsFile.FilePath))
Expand Down
37 changes: 14 additions & 23 deletions Requestrr.WebApi/Requestrr.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,25 @@
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="2.3.1"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.4"/>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.4"/>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0"/>
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0"/>
<PackageReference Include="Discord.Net" Version="2.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.4" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0" />
</ItemGroup>
<ItemGroup>
<Content Remove="$(SpaRoot)**"/>
<None Remove="$(SpaRoot)**"/>
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**"/>
<Content Remove="$(SpaRoot)**" />
<None Remove="$(SpaRoot)**" />
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install"/>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE."/>
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..."/>
</Target>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build"/>
<ItemGroup>
<DistFiles Include="$(SpaRoot)build\**; $(SpaRoot)build-ssr\**"/>
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public Task HandleDisabledCommandAsync()
{
if (!_discordSettings.EnableRequestsThroughDirectMessages && this.Context.Guild == null)
{
return ReplyToUserAsync($"This command is only available within a server.");
return ReplyToUserAsync(Program.LocalizedStrings.OnlyAvailableWithinServer.ToString());
}
else if (this.Context.Guild != null && _discordSettings.MonitoredChannels.Any() && _discordSettings.MonitoredChannels.All(c => !Context.Message.Channel.Name.Equals(c, StringComparison.InvariantCultureIgnoreCase)))
{
return Task.CompletedTask;
}

return ReplyToUserAsync($"This command has been disabled by the server owner.");
return ReplyToUserAsync(Program.LocalizedStrings.DisabledCommand.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public async Task HandleHelpAsync()
{
var channel = await Context.User.GetOrCreateDMChannelAsync();
await channel.SendMessageAsync(messageBuilder.ToString());
await ReplyToUserAsync("I sent you a DM with the help information!");
await ReplyToUserAsync(Program.LocalizedStrings.DisplayHelpCommandInDM.ToString());
}
catch
{
await ReplyToUserAsync("I was unable to send you a DM with the help information, make sure that you haven't blocked me and that you allow direct messages from server members");
await ReplyToUserAsync(Program.LocalizedStrings.DisplayHelpCommandInDMError.ToString());
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task HandleMovieRequestAsync(object[] args)

if (!_discordSettings.EnableRequestsThroughDirectMessages && this.Context.Guild == null)
{
await ReplyToUserAsync($"This command is only available within a server.");
await ReplyToUserAsync(Program.LocalizedStrings.OnlyAvailableWithinServer.ToString());
return;
}
else if (this.Context.Guild != null && _discordSettings.MonitoredChannels.Any() && _discordSettings.MonitoredChannels.All(c => !Context.Message.Channel.Name.Equals(c, StringComparison.InvariantCultureIgnoreCase)))
Expand All @@ -51,12 +51,12 @@ public async Task HandleMovieRequestAsync(object[] args)
}
else if (this.Context.Guild != null && _discordSettings.MovieRoles.Any() && Context.Message.Author is SocketGuildUser guildUser && _discordSettings.MovieRoles.All(r => !guildUser.Roles.Any(ur => r.Equals(ur.Name, StringComparison.InvariantCultureIgnoreCase))))
{
await ReplyToUserAsync($"You do not have the required role to request movies, please ask the server owner.");
await ReplyToUserAsync(Program.LocalizedStrings.MovieRequestWrongRole.ToString());
return;
}
else if (!stringArgs.Any())
{
await ReplyToUserAsync($"The correct usage of this command is: ```{_discordSettings.CommandPrefix}{_discordSettings.MovieCommand} name of movie```");
await ReplyToUserAsync(Program.LocalizedStrings.MovieRequestCorrectUsageText.ToString().Replace($"{{CommandPrefix}}", _discordSettings.CommandPrefix).Replace($"{{MovieCommand}}", _discordSettings.MovieCommand));
return;
}

Expand Down Expand Up @@ -98,12 +98,12 @@ public async Task HandleMovieRequestAsync(object[] args)

public Task WarnNoMovieFoundAsync(string movieName)
{
return ReplyToUserAsync($"I could not find any movie with the name \"{movieName}\", please try something different.");
return ReplyToUserAsync(Program.LocalizedStrings.MovieNotFound.ToString().Replace($"{{movie.Title}}",movieName));
}

public Task WarnNoMovieFoundByTheMovieDbIdAsync(string theMovieDbIdTextValue)
{
return ReplyToUserAsync($"I could not find any movie with TheMovieDbId of \"{theMovieDbIdTextValue}\", please try something different.");
return ReplyToUserAsync(Program.LocalizedStrings.MovieNotFoundByMovieDB.ToString().Replace($"{{theMovieDbIdTextValue}}", theMovieDbIdTextValue));
}

public async Task<MovieSelection> GetMovieSelectionAsync(IReadOnlyList<Movie> movies)
Expand All @@ -127,12 +127,12 @@ public async Task<MovieSelection> GetMovieSelectionAsync(IReadOnlyList<Movie> mo
}

var embedBuilder = new EmbedBuilder()
.WithTitle("Movie Search")
.AddField("__Search Results__", embedContent.ToString())
.WithTitle(Program.LocalizedStrings.MovieSearch.ToString())
.AddField(Program.LocalizedStrings.SearchResults.ToString(), embedContent.ToString())
.WithThumbnailUrl("https://i.imgur.com/44ueTES.png");

var reply = await ReplyAsync(string.Empty, false, embedBuilder.Build());
var replyHelp = await ReplyToUserAsync($"Please select one of the search results shown above by typing its corresponding number shown on the left. (ex: **{_discordSettings.CommandPrefix}2**) To abort type **{_discordSettings.CommandPrefix}cancel**");
var replyHelp = await ReplyToUserAsync(Program.LocalizedStrings.GetMovieSelectionText.ToString().Replace($"{{CommandPrefix}}",_discordSettings.CommandPrefix));

var selectionMessage = await NextMessageAsync(Context);
var selectionMessageContent = selectionMessage?.Content?.Trim() ?? "cancel";
Expand All @@ -141,12 +141,12 @@ public async Task<MovieSelection> GetMovieSelectionAsync(IReadOnlyList<Movie> mo
? selectionMessageContent.Remove(0, _discordSettings.CommandPrefix.Length)
: selectionMessageContent;

if (selectionMessageContent.ToLower().StartsWith("cancel"))
if (selectionMessageContent.ToLower().StartsWith(Program.LocalizedStrings.CancelText.ToString()))
{
await DeleteSafeAsync(reply);
await DeleteSafeAsync(replyHelp);
await DeleteSafeAsync(selectionMessage);
await ReplyToUserAsync("Your request has been cancelled!!");
await ReplyToUserAsync(Program.LocalizedStrings.RequestCancelledResponse.ToString());

return new MovieSelection
{
Expand All @@ -170,7 +170,7 @@ public async Task<MovieSelection> GetMovieSelectionAsync(IReadOnlyList<Movie> mo

public Task WarnInvalidMovieSelectionAsync()
{
return ReplyToUserAsync("I didn't understand your dramatic babbling, I'm afraid you'll have to make a new request.");
return ReplyToUserAsync(Program.LocalizedStrings.InvalidMovieSelectionWarning.ToString());
}

public async Task DisplayMovieDetailsAsync(Movie movie)
Expand Down Expand Up @@ -198,7 +198,7 @@ public static async Task<Embed> GenerateMovieDetailsAsync(Movie movie, SocketUse
}

if (!string.IsNullOrEmpty(movie.PosterPath) && movie.PosterPath.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) embedBuilder.WithImageUrl(movie.PosterPath);
if (!string.IsNullOrWhiteSpace(movie.Quality)) embedBuilder.AddField("__Quality__", $"{movie.Quality}p", true);
if (!string.IsNullOrWhiteSpace(movie.Quality)) embedBuilder.AddField(Program.LocalizedStrings.MovieQuality.ToString(), $"{movie.Quality}p", true);

if (movieSearcher != null)
{
Expand All @@ -208,11 +208,11 @@ public static async Task<Embed> GenerateMovieDetailsAsync(Movie movie, SocketUse

if (!string.IsNullOrWhiteSpace(details.InTheatersDate))
{
embedBuilder.AddField("__In Theaters__", $"{details.InTheatersDate}", true);
embedBuilder.AddField(Program.LocalizedStrings.MovieInTheaters.ToString(), $"{details.InTheatersDate}", true);
}
else if (!string.IsNullOrWhiteSpace(movie.ReleaseDate))
{
embedBuilder.AddField("__In Theaters__", $"{DateTime.Parse(movie.ReleaseDate).ToString("MMMM dd yyyy", DateTimeFormatInfo.InvariantInfo)}", true);
embedBuilder.AddField(Program.LocalizedStrings.MovieInTheaters.ToString(), $"{DateTime.Parse(movie.ReleaseDate).ToString("MMMM dd yyyy", DateTimeFormatInfo.InvariantInfo)}", true);
}

if (!string.IsNullOrWhiteSpace(details.PhysicalReleaseName) && !string.IsNullOrWhiteSpace(details.PhysicalReleaseDate))
Expand Down Expand Up @@ -240,16 +240,16 @@ public async Task<bool> GetMovieRequestAsync(Movie movie)
{
if (releaseDate > DateTime.UtcNow)
{
await ReplyToUserAsync("This movie has not released yet, if you want to request this movie please click on the ⬇ reaction directly above this message.");
await ReplyToUserAsync(Program.LocalizedStrings.MovieNotReleased.ToString().Replace($"{{movie.Title}}", movie.Title));
}
else
{
await ReplyToUserAsync("If you want to request this movie please click on the ⬇ reaction directly above this message.");
await ReplyToUserAsync(Program.LocalizedStrings.MovieRequestAsk.ToString().Replace($"{{movie.Title}}", movie.Title));
}
}
else
{
await ReplyToUserAsync("If you want to request this movie please click on the ⬇ reaction directly above this message.");
await ReplyToUserAsync(Program.LocalizedStrings.MovieRequestAsk.ToString().Replace($"{{movie.Title}}", movie.Title));
}

var reaction = await WaitForReactionAsync(Context, _lastCommandMessage, new Emoji("⬇"));
Expand All @@ -259,18 +259,18 @@ public async Task<bool> GetMovieRequestAsync(Movie movie)

public Task WarnMovieAlreadyAvailableAsync()
{
return ReplyToUserAsync("This movie is already available, enjoy!");
return ReplyToUserAsync(Program.LocalizedStrings.MovieIsAvailable.ToString());
}

public Task DisplayRequestSuccessAsync(Movie movie)
{
return ReplyToUserAsync($"Your request for **{movie.Title}** was sent successfully!");
return ReplyToUserAsync(Program.LocalizedStrings.MovieRequestSuccess.ToString().Replace($"{{movie.Title}}", movie.Title));
}

public async Task<bool> AskForNotificationRequestAsync()
{
await _lastCommandMessage?.AddReactionAsync(new Emoji("🔔"));
await ReplyToUserAsync("This movie has already been requested, you can click on the 🔔 reaction directly above this message to be notified when it becomes available.");
await ReplyToUserAsync(Program.LocalizedStrings.MovieAlreadyRequestedAskForNotification.ToString());

var reaction = await WaitForReactionAsync(Context, _lastCommandMessage, new Emoji("🔔"));

Expand All @@ -279,22 +279,22 @@ public async Task<bool> AskForNotificationRequestAsync()

public Task DisplayNotificationSuccessAsync(Movie movie)
{
return ReplyToUserAsync($"You will now receive a notification as soon as **{movie.Title}** becomes available to watch.");
return ReplyToUserAsync(Program.LocalizedStrings.MovieNotificationEnableSuccess.ToString().Replace($"{{movie.Title}}", movie.Title));
}

public Task DisplayRequestDeniedAsync(Movie movie)
{
return ReplyToUserAsync($"Your request was denied by the provider due to insufficient permissions or quota limits.");
return ReplyToUserAsync(Program.LocalizedStrings.MovieRequestDenied.ToString().Replace($"{{movie.Title}}", movie.Title));
}

public Task WarnMovieUnavailableAndAlreadyHasNotificationAsync()
{
return ReplyToUserAsync("This movie has already been requested and you will be notified when it becomes available.");
return ReplyToUserAsync(Program.LocalizedStrings.MovieRequestedAndNotificationsEnabled.ToString());
}

public Task WarnMovieAlreadyRequestedAsync()
{
return ReplyToUserAsync("This movie has already been requested.");
return ReplyToUserAsync(Program.LocalizedStrings.MovieAlreadyRequested.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Task HandlePingAsync()
return Task.CompletedTask;
}

return ReplyToUserAsync($"pong");
return ReplyToUserAsync(Program.LocalizedStrings.PongResponse.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class DiscordSettings
public string[] NotificationChannels { get; set; }
public bool AutomaticallyPurgeCommandMessages { get; set; }
public bool DisplayHelpCommandInDMs { get; set; }

public override bool Equals(object obj)
{
return obj is DiscordSettings settings &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public DiscordSettings Provide()
NotificationMode = settings.ChatClients.Discord.NotificationMode,
NotificationChannels = settings.ChatClients.Discord.NotificationChannels.ToObject<string[]>(),
AutomaticallyPurgeCommandMessages = settings.ChatClients.Discord.AutomaticallyPurgeCommandMessages,
DisplayHelpCommandInDMs = settings.ChatClients.Discord.DisplayHelpCommandInDMs,
DisplayHelpCommandInDMs = settings.ChatClients.Discord.DisplayHelpCommandInDMs
};
}

Expand Down
Loading