Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start adding localization #2

Open
wants to merge 10 commits 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
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Common/StringUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public static string ToLowerWithoutDiacritics(string text)
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Globalization;

namespace PoGo.DiscordBot.Configuration.Options
{
Expand All @@ -14,6 +15,7 @@ public class GuildOptions
{
public string Name { get; set; }
public ulong Id { get; set; }
public CultureInfo Language { get; set; }
public bool IgnoreMention { get; set; }
public string[] FreeRoles { get; set; }
public ChannelOptions[] Channels { get; set; }
Expand Down Expand Up @@ -43,4 +45,4 @@ public class GymInfoOptions
public string Latitude { get; set; }
public string Longitude { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Configuration/PokemonTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public enum PokemonTeam
Instinct,
Valor
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Configuration/TeamRoleColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public static Color GetColor(PokemonTeam team)
}
}
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Dto/GymInfoDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public class GymInfoDto
public string Latitude { get; set; }
public string Longitude { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Dto/PlayerDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public class PlayerDto

public override string ToString() => User.Nickname ?? User.Username;
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Dto/RaidBossDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public class RaidBossDto
public string[] ChargeAttacks { get; set; }
public string[] Counters { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Dto/RaidChannelBindingDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class RaidChannelBindingDto
public IMentionable Mention { get; set; }
public bool AllowScheduledRaids { get; set; }
}
}
}
29 changes: 15 additions & 14 deletions PoGo.DiscordBot/Dto/RaidInfoDto.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Discord;
using PoGo.DiscordBot.Configuration;
using PoGo.DiscordBot.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -58,51 +59,51 @@ Color GetColor()
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder
.WithColor(GetColor())
.AddInlineField("Boss", BossName)
.AddInlineField("Kde", Location)
.AddInlineField(RaidType == RaidType.Normal ? "Čas" : "Datum", DateTimeAsString)
.AddInlineField(Resources.Boss, BossName)
.AddInlineField(Resources.Where, Location)
.AddInlineField(RaidType == RaidType.Normal ? Resources.Time : Resources.Date, DateTimeAsString)
;

if (Players.Any())
if (Players.Count > 0)
{
string playerFieldValue = Players.Count >= 10 ?
PlayersToGroupString(Players.Values) :
PlayersToString(Players.Values);

embedBuilder.AddField($"Hráči ({Players.Count})", playerFieldValue);
embedBuilder.AddField(Resources.Players + $"({Players.Count})", playerFieldValue);
}

if (ExtraPlayers.Any())
if (ExtraPlayers.Count > 0)
{
string extraPlayersFieldValue = string.Join(" + ", ExtraPlayers.Select(t => t.Count));
embedBuilder.AddField($"Další hráči (bez Discordu, 2. mobil atd.) ({ExtraPlayers.Sum(t => t.Count)})", extraPlayersFieldValue);
embedBuilder.AddField(Resources.OtherPlayers + $"({ExtraPlayers.Sum(t => t.Count)})", extraPlayersFieldValue);
}

return embedBuilder.Build();
}

public string ToSimpleString() => $"{BossName} {Location} {DateTimeAsString}";
public string ToSimpleString() => $"{BossName} {Location} {DateTimeAsString}";

string PlayersToString(IEnumerable<PlayerDto> players) => string.Join(", ", players);

string PlayersToGroupString(IEnumerable<PlayerDto> allPlayers)
{
string TeamToString(PokemonTeam? team) => team != null ? team.ToString() : "Bez teamu";
string TeamToString(PokemonTeam? team) => team != null ? team.ToString() : Resources.WithoutTeam;

List<string> formatterGroupedPlayers = new List<string>();

var teams = new PokemonTeam?[] { PokemonTeam.Mystic, PokemonTeam.Instinct, PokemonTeam.Valor, null };
foreach (PokemonTeam? team in teams)
{
var players = allPlayers.Where(t => t.Team == team).ToList();
if (players.Any())
if (players.Count > 0)
formatterGroupedPlayers.Add($"{TeamToString(team)} ({players.Count}) - {PlayersToString(players)}");
}

return string.Join(Environment.NewLine, formatterGroupedPlayers);
}

public static DateTime? ParseTime(string time) => ParseTime(time, DateTime.Now.Date);
public static DateTime? ParseTime(string time) => ParseTime(time, DateTime.Now.Date);

public static DateTime? ParseTime(string time, DateTime date)
{
Expand Down Expand Up @@ -140,7 +141,7 @@ public static RaidInfoDto Parse(IUserMessage message)

RaidInfoDto result = null;

if (embed.Fields[2].Name == "Čas")
if (embed.Fields[2].Name.Equals(Resources.Time, StringComparison.OrdinalIgnoreCase))
{
var time = ParseTime(embed.Fields[2].Value, message.CreatedAt.Date);
if (!time.HasValue)
Expand All @@ -155,7 +156,7 @@ public static RaidInfoDto Parse(IUserMessage message)
DateTime = time.Value,
};
}
else if (embed.Fields[2].Name == "Datum")
else if (embed.Fields[2].Name.Equals(Resources.Date, StringComparison.OrdinalIgnoreCase))
{
var dateTime = ParseDateTime(embed.Fields[2].Value);
if (!dateTime.HasValue)
Expand All @@ -174,4 +175,4 @@ public static RaidInfoDto Parse(IUserMessage message)
return result;
}
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Dto/TeamRolesDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public class TeamRolesDto
public IReadOnlyDictionary<ulong, PokemonTeam> RoleTeams { get; set; } // <RoleId, PokemonTeam>
public IReadOnlyDictionary<PokemonTeam, IRole> TeamRoles { get; set; } // <PokemonTeam, Role>
}
}
}
3 changes: 1 addition & 2 deletions PoGo.DiscordBot/Emojis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ internal class UnicodeEmojis
public const string ThumbsDown = "👎";
public const string Check = "✅";
public const string Cross = "❌";

const char Border = '⃣';
public static readonly string[] KeycapDigits;

Expand All @@ -35,4 +34,4 @@ static Emojis()
KeycapDigits = UnicodeEmojis.KeycapDigits.Select(t => new Emoji(t)).ToArray();
}
}
}
}
8 changes: 8 additions & 0 deletions PoGo.DiscordBot/Localizing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
If you wish to support the PoGo Discord bot in
your native language, create a pull request.
The easiest way to add a new .resx file is to
use the Zeta Resource Editor at
https://archive.codeplex.com/?p=ZetaResourceEditor and make a pull request.


Thank you for wanting to contribute additional languages.
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/LogSeverityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public static LogLevel ToLogLevel(this LogSeverity logSeverity)
}
}
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Modules/BlameModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ public async Task ListPlayersWithoutTeam()
await ReplyAsync($"`{message}`");
}
}
}
}
21 changes: 11 additions & 10 deletions PoGo.DiscordBot/Modules/CleanModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Discord;
using Discord.Commands;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

Expand All @@ -9,25 +10,25 @@ namespace PoGo.DiscordBot.Modules
public class CleanModule : ModuleBase
{
[Command("hardclean", RunMode = RunMode.Async)]
[Summary("Smaže všechny zprávy (omezeno počtem).")]
public async Task FullClean([Summary("Počet zpráv.")]int count = 10)
[Summary("DeleteAllMessagesSummary")]
public async Task FullClean([Summary("MessageNumber")]int count = 10)
{
var batchMessages = AsyncEnumerable.ToEnumerable(Context.Channel.GetMessagesAsync(count));
var batchMessages = AsyncEnumerable.ToEnumerable(Context.Channel.GetMessagesAsync(count));
foreach (var messages in batchMessages)
await Context.Channel.DeleteMessagesAsync(messages);
}

[Command("clean", RunMode = RunMode.Async)]
[Summary("Smaže tvoje zprávy (omezeno počtem).")]
public async Task DeleteLastMessagesFromCurrentUser([Summary("Počet zpráv.")]int count = 5)
[Summary("DeleteYourMessageSummary")]
public async Task DeleteLastMessagesFromCurrentUser([Summary("MessageNumber")]int count = 5)
{
await DeleteMessagesAsync(Context.User.Id, count);
}

[Command("clean", RunMode = RunMode.Async)]
[Summary("Smaže zprávy označeného uživatele (omezeno počtem).")]
public async Task DeleteLastMessages([Summary("Uživatel.")]IUser user,
[Summary("Počet zpráv.")]int count = 5)
[Summary("DeleteLastMessageSummary")]
public async Task DeleteLastMessages([Summary("User")]IUser user,
[Summary("MessageNumber")]int count = 5)
{
ulong userId = user != null ? user.Id : Context.User.Id;

Expand All @@ -36,12 +37,12 @@ public async Task DeleteLastMessages([Summary("Uživatel.")]IUser user,

async Task DeleteMessagesAsync(ulong userId, int count)
{
foreach (var messages in AsyncEnumerable.ToEnumerable(Context.Channel.GetMessagesAsync()))
foreach (var messages in Context.Channel.GetMessagesAsync().ToEnumerable())
{
var messagesToDelete = messages.Where(t => t.Author.Id == userId).Take(count);
if (messagesToDelete != null)
await Context.Channel.DeleteMessagesAsync(messagesToDelete.Take(count));
}
}
}
}
}
2 changes: 1 addition & 1 deletion PoGo.DiscordBot/Modules/DiagnosticModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public async Task ProcessInfo()
await ReplyAsync(string.Empty, embed: embedBuilder.Build());
}
}
}
}
Loading