Delete the TranslationHandler and the old translations file. Refactor GeekbotCommandBase to get the server language from guild settings. Create DateLocalization to create a localized relative time remaining string.
This commit is contained in:
parent
078c884df7
commit
33829e91bc
22 changed files with 156 additions and 579 deletions
|
@ -1,17 +1,16 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Bot.Utils;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.CommandPreconditions;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.Database.Models;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.Localization;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
|
||||
namespace Geekbot.Bot.Commands.User
|
||||
{
|
||||
|
@ -19,12 +18,10 @@ namespace Geekbot.Bot.Commands.User
|
|||
public class Karma : GeekbotCommandBase
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly ITranslationHandler _translations;
|
||||
|
||||
public Karma(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translations) : base(errorHandler, translations)
|
||||
public Karma(DatabaseContext database, IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_translations = translations;
|
||||
}
|
||||
|
||||
[Command("good", RunMode = RunMode.Async)]
|
||||
|
@ -33,8 +30,6 @@ namespace Geekbot.Bot.Commands.User
|
|||
{
|
||||
try
|
||||
{
|
||||
var transContext = await _translations.GetGuildContext(Context);
|
||||
|
||||
var actor = await GetUser(Context.User.Id);
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
|
@ -42,7 +37,7 @@ namespace Geekbot.Bot.Commands.User
|
|||
}
|
||||
else if (TimeoutFinished(actor.TimeOut))
|
||||
{
|
||||
var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
|
||||
var formatedWaitTime = DateLocalization.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
|
||||
await ReplyAsync(string.Format(Localization.Karma.WaitUntill, Context.User.Username, formatedWaitTime));
|
||||
}
|
||||
else
|
||||
|
@ -81,8 +76,6 @@ namespace Geekbot.Bot.Commands.User
|
|||
{
|
||||
try
|
||||
{
|
||||
var transContext = await _translations.GetGuildContext(Context);
|
||||
|
||||
var actor = await GetUser(Context.User.Id);
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
|
@ -90,7 +83,7 @@ namespace Geekbot.Bot.Commands.User
|
|||
}
|
||||
else if (TimeoutFinished(actor.TimeOut))
|
||||
{
|
||||
var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
|
||||
var formatedWaitTime = DateLocalization.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
|
||||
await ReplyAsync(string.Format(Localization.Karma.WaitUntill, Context.User.Username, formatedWaitTime));
|
||||
}
|
||||
else
|
||||
|
|
|
@ -10,8 +10,8 @@ using Geekbot.Core.Converters;
|
|||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.Extensions;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
using Geekbot.Core.Highscores;
|
||||
using Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Bot.Commands.User.Ranking
|
||||
{
|
||||
|
@ -21,7 +21,8 @@ namespace Geekbot.Bot.Commands.User.Ranking
|
|||
private readonly IHighscoreManager _highscoreManager;
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager, ITranslationHandler translations): base(errorHandler, translations)
|
||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager, IGuildSettingsManager guildSettingsManager)
|
||||
: base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_emojiConverter = emojiConverter;
|
||||
|
@ -53,7 +54,7 @@ namespace Geekbot.Bot.Commands.User.Ranking
|
|||
await ReplyAsync(Localization.Rank.LimitingTo20Warning);
|
||||
amount = 20;
|
||||
}
|
||||
|
||||
|
||||
var guildId = Context.Guild.Id;
|
||||
Dictionary<HighscoreUserDto, int> highscoreUsers;
|
||||
try
|
||||
|
@ -78,9 +79,9 @@ namespace Geekbot.Bot.Commands.User.Ranking
|
|||
var failedToRetrieveUser = highscoreUsers.Any(e => string.IsNullOrEmpty(e.Key.Username));
|
||||
|
||||
if (failedToRetrieveUser) replyBuilder.AppendLine(Localization.Rank.FailedToResolveAllUsernames).AppendLine();
|
||||
|
||||
|
||||
replyBuilder.AppendLine(string.Format(Localization.Rank.HighscoresFor, type.ToString().CapitalizeFirst(), Context.Guild.Name));
|
||||
|
||||
|
||||
var highscorePlace = 1;
|
||||
foreach (var (user, value) in highscoreUsers)
|
||||
{
|
||||
|
@ -91,7 +92,7 @@ namespace Geekbot.Bot.Commands.User.Ranking
|
|||
replyBuilder.Append(user.Username != null
|
||||
? $"**{user.Username}#{user.Discriminator}**"
|
||||
: $"**{user.Id}**");
|
||||
|
||||
|
||||
replyBuilder.Append(type == HighscoreTypes.messages
|
||||
? $" - {value} {type} - {Math.Round((double) (100 * value) / guildMessages, 2)}%\n"
|
||||
: $" - {value} {type}\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue