Make the EmojiConverter static
This commit is contained in:
parent
df6672305d
commit
5d6e5cf2ad
9 changed files with 20 additions and 56 deletions
|
@ -1,9 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Bot.CommandPreconditions;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Converters;
|
||||
using Geekbot.Core.Database;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
|
@ -13,15 +10,13 @@ namespace Geekbot.Bot.Commands.User
|
|||
{
|
||||
public class Rank : GeekbotCommandBase
|
||||
{
|
||||
private readonly IEmojiConverter _emojiConverter;
|
||||
private readonly IHighscoreManager _highscoreManager;
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager, IGuildSettingsManager guildSettingsManager)
|
||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IHighscoreManager highscoreManager, IGuildSettingsManager guildSettingsManager)
|
||||
: base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_database = database;
|
||||
_emojiConverter = emojiConverter;
|
||||
_highscoreManager = highscoreManager;
|
||||
}
|
||||
|
||||
|
@ -35,7 +30,7 @@ namespace Geekbot.Bot.Commands.User
|
|||
{
|
||||
try
|
||||
{
|
||||
var res = new Geekbot.Commands.Rank(_database, _emojiConverter, _highscoreManager)
|
||||
var res = new Geekbot.Commands.Rank(_database, _highscoreManager)
|
||||
.Run(typeUnformated, amount, season, Context.Guild.Id, Context.Guild.Name);
|
||||
await ReplyAsync(res);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
|
@ -16,11 +12,9 @@ namespace Geekbot.Bot.Commands.Utils.Corona
|
|||
{
|
||||
public class CoronaStats : GeekbotCommandBase
|
||||
{
|
||||
private readonly IEmojiConverter _emojiConverter;
|
||||
|
||||
public CoronaStats(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager, IEmojiConverter emojiConverter) : base(errorHandler, guildSettingsManager)
|
||||
public CoronaStats(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
|
||||
{
|
||||
_emojiConverter = emojiConverter;
|
||||
}
|
||||
|
||||
[Command("corona", RunMode = RunMode.Async)]
|
||||
|
@ -54,7 +48,7 @@ namespace Geekbot.Bot.Commands.Utils.Corona
|
|||
if (!string.IsNullOrEmpty(summary.Country))
|
||||
{
|
||||
embedTitleBuilder.Append(" - ");
|
||||
embedTitleBuilder.Append(_emojiConverter.CountryCodeToEmoji(summary.Country));
|
||||
embedTitleBuilder.Append(EmojiConverter.CountryCodeToEmoji(summary.Country));
|
||||
}
|
||||
|
||||
var eb = new EmbedBuilder
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.Converters;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
|
@ -9,13 +7,11 @@ namespace Geekbot.Bot.Commands.Utils
|
|||
{
|
||||
public class Emojify : TransactionModuleBase
|
||||
{
|
||||
private readonly IEmojiConverter _emojiConverter;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Emojify(IErrorHandler errorHandler, IEmojiConverter emojiConverter)
|
||||
public Emojify(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_emojiConverter = emojiConverter;
|
||||
}
|
||||
|
||||
[Command("emojify", RunMode = RunMode.Async)]
|
||||
|
@ -24,7 +20,7 @@ namespace Geekbot.Bot.Commands.Utils
|
|||
{
|
||||
try
|
||||
{
|
||||
var emojis = _emojiConverter.TextToEmoji(text);
|
||||
var emojis = EmojiConverter.TextToEmoji(text);
|
||||
if (emojis.Length > 1999)
|
||||
{
|
||||
await ReplyAsync("I can't take that much at once!");
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Geekbot.Core.Converters;
|
||||
using Geekbot.Core.Database;
|
||||
|
@ -13,13 +10,11 @@ namespace Geekbot.Commands
|
|||
public class Rank
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IEmojiConverter _emojiConverter;
|
||||
private readonly IHighscoreManager _highscoreManager;
|
||||
|
||||
public Rank(DatabaseContext database, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager)
|
||||
public Rank(DatabaseContext database, IHighscoreManager highscoreManager)
|
||||
{
|
||||
_database = database;
|
||||
_emojiConverter = emojiConverter;
|
||||
_highscoreManager = highscoreManager;
|
||||
}
|
||||
|
||||
|
@ -84,7 +79,7 @@ namespace Geekbot.Commands
|
|||
foreach (var (user, value) in highscoreUsers)
|
||||
{
|
||||
replyBuilder.Append(highscorePlace < 11
|
||||
? $"{_emojiConverter.NumberToEmoji(highscorePlace)} "
|
||||
? $"{EmojiConverter.NumberToEmoji(highscorePlace)} "
|
||||
: $"`{highscorePlace}.` ");
|
||||
|
||||
replyBuilder.Append(user.Username != null
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
using System.Collections;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
|
||||
namespace Geekbot.Core.Converters
|
||||
{
|
||||
public class EmojiConverter : IEmojiConverter
|
||||
public static class EmojiConverter
|
||||
{
|
||||
private readonly string[] NumberEmojiMap =
|
||||
private static readonly string[] NumberEmojiMap =
|
||||
{
|
||||
":zero:",
|
||||
":one:",
|
||||
|
@ -20,7 +19,7 @@ namespace Geekbot.Core.Converters
|
|||
":nine:"
|
||||
};
|
||||
|
||||
public string NumberToEmoji(int number)
|
||||
public static string NumberToEmoji(int number)
|
||||
{
|
||||
if (number == 10)
|
||||
{
|
||||
|
@ -36,7 +35,7 @@ namespace Geekbot.Core.Converters
|
|||
return returnString.ToString();
|
||||
}
|
||||
|
||||
private readonly Hashtable TextEmojiMap = new Hashtable
|
||||
private static readonly Hashtable TextEmojiMap = new Hashtable
|
||||
{
|
||||
['A'] = ":regional_indicator_a: ",
|
||||
['B'] = ":b: ",
|
||||
|
@ -82,7 +81,7 @@ namespace Geekbot.Core.Converters
|
|||
[' '] = " "
|
||||
};
|
||||
|
||||
public string TextToEmoji(string text)
|
||||
public static string TextToEmoji(string text)
|
||||
{
|
||||
var letters = text.ToUpper().ToCharArray();
|
||||
var returnString = new StringBuilder();
|
||||
|
@ -94,7 +93,7 @@ namespace Geekbot.Core.Converters
|
|||
return returnString.ToString();
|
||||
}
|
||||
|
||||
private readonly Hashtable RegionalIndicatorMap = new Hashtable()
|
||||
private static readonly Hashtable RegionalIndicatorMap = new Hashtable()
|
||||
{
|
||||
['A'] = new Rune(0x1F1E6),
|
||||
['B'] = new Rune(0x1F1E7),
|
||||
|
@ -124,7 +123,7 @@ namespace Geekbot.Core.Converters
|
|||
['Z'] = new Rune(0x1F1FF)
|
||||
};
|
||||
|
||||
public string CountryCodeToEmoji(string countryCode)
|
||||
public static string CountryCodeToEmoji(string countryCode)
|
||||
{
|
||||
var letters = countryCode.ToUpper().ToCharArray();
|
||||
var returnString = new StringBuilder();
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
namespace Geekbot.Core.Converters
|
||||
{
|
||||
public interface IEmojiConverter
|
||||
{
|
||||
string NumberToEmoji(int number);
|
||||
string TextToEmoji(string text);
|
||||
string CountryCodeToEmoji(string countryCode);
|
||||
}
|
||||
}
|
|
@ -92,7 +92,6 @@ ServiceCollection RegisterServices()
|
|||
var guildSettingsManager = new GuildSettingsManager(databaseInitializer.Initialize());
|
||||
var fortunes = new FortunesProvider(logger);
|
||||
var levelCalc = new LevelCalc();
|
||||
var emojiConverter = new EmojiConverter();
|
||||
var mtgManaConverter = new MtgManaConverter();
|
||||
var wikipediaClient = new WikipediaClient();
|
||||
var randomNumberGenerator = new RandomNumberGenerator();
|
||||
|
@ -104,7 +103,6 @@ ServiceCollection RegisterServices()
|
|||
services.AddSingleton<IUserRepository>(userRepository);
|
||||
services.AddSingleton<IGeekbotLogger>(logger);
|
||||
services.AddSingleton<ILevelCalc>(levelCalc);
|
||||
services.AddSingleton<IEmojiConverter>(emojiConverter);
|
||||
services.AddSingleton<IFortunesProvider>(fortunes);
|
||||
services.AddSingleton<IMediaProvider>(mediaProvider);
|
||||
services.AddSingleton<IMtgManaConverter>(mtgManaConverter);
|
||||
|
|
|
@ -11,13 +11,11 @@ namespace Geekbot.Web.Commands;
|
|||
public class Rank : InteractionBase
|
||||
{
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IEmojiConverter _emojiConverter;
|
||||
private readonly IHighscoreManager _highscoreManager;
|
||||
|
||||
public Rank(DatabaseContext database, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager)
|
||||
public Rank(DatabaseContext database, IHighscoreManager highscoreManager)
|
||||
{
|
||||
_database = database;
|
||||
_emojiConverter = emojiConverter;
|
||||
_highscoreManager = highscoreManager;
|
||||
}
|
||||
|
||||
|
@ -75,7 +73,7 @@ public class Rank : InteractionBase
|
|||
var amountOption = interaction.Data.Options.Find(o => o.Name == Options.Amount);
|
||||
var seasonOption = interaction.Data.Options.Find(o => o.Name == Options.Season);
|
||||
|
||||
var res = new Geekbot.Commands.Rank(_database, _emojiConverter, _highscoreManager)
|
||||
var res = new Geekbot.Commands.Rank(_database, _highscoreManager)
|
||||
.Run(
|
||||
counterTypeOption?.Value.GetString() ?? HighscoreTypes.messages.ToString(),
|
||||
amountOption?.Value.GetInt32() ?? 10,
|
||||
|
|
|
@ -51,8 +51,7 @@ namespace Tests.Core.Converters
|
|||
[Theory, MemberData(nameof(NumberToEmojiTestData))]
|
||||
public void NumberToEmoji(string testName, NumberToEmojiTestDto testData)
|
||||
{
|
||||
var emojiConverter = new EmojiConverter();
|
||||
var result = emojiConverter.NumberToEmoji(testData.Number);
|
||||
var result = EmojiConverter.NumberToEmoji(testData.Number);
|
||||
Assert.Equal(result, testData.Expected);
|
||||
}
|
||||
|
||||
|
@ -86,8 +85,7 @@ namespace Tests.Core.Converters
|
|||
[Theory, MemberData(nameof(TextToEmojiTestData))]
|
||||
public void TextToEmoji(string testName, TextToEmojiTestDto testData)
|
||||
{
|
||||
var emojiConverter = new EmojiConverter();
|
||||
var result = emojiConverter.TextToEmoji(testData.Text);
|
||||
var result = EmojiConverter.TextToEmoji(testData.Text);
|
||||
Assert.Equal(result, testData.Expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue