diff --git a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs index 1ee7adbd..088b95d7 100644 --- a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs +++ b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs @@ -19,7 +19,7 @@ namespace NadekoBot.Modules.Games public partial class Games { [Group] - public class Acropobia : ModuleBase + public class Acropobia : NadekoSubmodule { //channelId, game public static ConcurrentDictionary AcrophobiaGames { get; } = new ConcurrentDictionary(); @@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Games } else { - await channel.SendErrorAsync("Acrophobia game is already running in this channel.").ConfigureAwait(false); + await ReplyErrorLocalized("acro_running").ConfigureAwait(false); } } } @@ -61,44 +61,44 @@ namespace NadekoBot.Modules.Games public class AcrophobiaGame { - private readonly ITextChannel channel; - private readonly int time; - private readonly NadekoRandom rng; - private readonly ImmutableArray startingLetters; - private readonly CancellationTokenSource source; + private readonly ITextChannel _channel; + private readonly int _time; + private readonly NadekoRandom _rng; + private readonly ImmutableArray _startingLetters; + private readonly CancellationTokenSource _source; private AcroPhase phase { get; set; } = AcroPhase.Submitting; - private readonly ConcurrentDictionary submissions = new ConcurrentDictionary(); - public IReadOnlyDictionary Submissions => submissions; + private readonly ConcurrentDictionary _submissions = new ConcurrentDictionary(); + public IReadOnlyDictionary Submissions => _submissions; - private readonly ConcurrentHashSet usersWhoSubmitted = new ConcurrentHashSet(); - private readonly ConcurrentHashSet usersWhoVoted = new ConcurrentHashSet(); + private readonly ConcurrentHashSet _usersWhoSubmitted = new ConcurrentHashSet(); + private readonly ConcurrentHashSet _usersWhoVoted = new ConcurrentHashSet(); - private int spamCount = 0; + private int _spamCount; //text, votes - private readonly ConcurrentDictionary votes = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _votes = new ConcurrentDictionary(); private readonly Logger _log; public AcrophobiaGame(ITextChannel channel, int time) { - this._log = LogManager.GetCurrentClassLogger(); + _log = LogManager.GetCurrentClassLogger(); - this.channel = channel; - this.time = time; - this.source = new CancellationTokenSource(); + _channel = channel; + _time = time; + _source = new CancellationTokenSource(); - this.rng = new NadekoRandom(); - var wordCount = rng.Next(3, 6); + _rng = new NadekoRandom(); + var wordCount = _rng.Next(3, 6); var lettersArr = new char[wordCount]; for (int i = 0; i < wordCount; i++) { - var randChar = (char)rng.Next(65, 91); - lettersArr[i] = randChar == 'X' ? (char)rng.Next(65, 88) : randChar; + var randChar = (char)_rng.Next(65, 91); + lettersArr[i] = randChar == 'X' ? (char)_rng.Next(65, 88) : randChar; } - startingLetters = lettersArr.ToImmutableArray(); + _startingLetters = lettersArr.ToImmutableArray(); } private EmbedBuilder GetEmbed() @@ -106,19 +106,19 @@ namespace NadekoBot.Modules.Games var i = 0; return phase == AcroPhase.Submitting - ? new EmbedBuilder().WithOkColor() - .WithTitle("Acrophobia") - .WithDescription($"Game started. Create a sentence with the following acronym: **{string.Join(".", startingLetters)}.**\n") - .WithFooter(efb => efb.WithText("You have " + this.time + " seconds to make a submission.")) + ? new EmbedBuilder().WithOkColor() + .WithTitle(GetText("acrophobia")) + .WithDescription(GetText("acro_started", Format.Bold(string.Join(".", _startingLetters)))) + .WithFooter(efb => efb.WithText(GetText("acro_started_footer", _time))) - : new EmbedBuilder() - .WithOkColor() - .WithTitle("Acrophobia - Submissions Closed") - .WithDescription($@"Acronym was **{string.Join(".", startingLetters)}.** --- -{this.submissions.Aggregate("", (agg, cur) => agg + $"`{++i}.` **{cur.Key.ToLowerInvariant().ToTitleCase()}**\n")} ---") - .WithFooter(efb => efb.WithText("Vote by typing a number of the submission")); + : new EmbedBuilder() + .WithOkColor() + .WithTitle(GetText("acrophobia") + " - " + GetText("submissions_closed")) + .WithDescription(GetText("acro_nym_was", Format.Bold(string.Join(".", _startingLetters)) + "\n" + +$@"-- +{_submissions.Aggregate("",(agg, cur) => agg + $"`{++i}.` **{cur.Key.ToLowerInvariant().ToTitleCase()}**\n")} +--")) + .WithFooter(efb => efb.WithText(GetText("acro_vote"))); } public async Task Run() @@ -127,10 +127,10 @@ namespace NadekoBot.Modules.Games var embed = GetEmbed(); //SUBMISSIONS PHASE - await channel.EmbedAsync(embed).ConfigureAwait(false); + await _channel.EmbedAsync(embed).ConfigureAwait(false); try { - await Task.Delay(time * 1000, source.Token).ConfigureAwait(false); + await Task.Delay(_time * 1000, _source.Token).ConfigureAwait(false); phase = AcroPhase.Idle; } catch (OperationCanceledException) @@ -139,30 +139,32 @@ namespace NadekoBot.Modules.Games } //var i = 0; - if (submissions.Count == 0) + if (_submissions.Count == 0) { - await channel.SendErrorAsync("Acrophobia", "Game ended with no submissions."); + await _channel.SendErrorAsync(GetText("acrophobia"), GetText("acro_ended_no_sub")); return; } - else if (submissions.Count == 1) + if (_submissions.Count == 1) { - await channel.EmbedAsync(new EmbedBuilder().WithOkColor() - .WithDescription($"{submissions.First().Value.Mention} is the winner for being the only user who made a submission!") - .WithFooter(efb => efb.WithText(submissions.First().Key.ToLowerInvariant().ToTitleCase()))) - .ConfigureAwait(false); + await _channel.EmbedAsync(new EmbedBuilder().WithOkColor() + .WithDescription( + GetText("acro_winner_only", + Format.Bold(_submissions.First().Value.ToString()))) + .WithFooter(efb => efb.WithText(_submissions.First().Key.ToLowerInvariant().ToTitleCase()))) + .ConfigureAwait(false); return; } var submissionClosedEmbed = GetEmbed(); - await channel.EmbedAsync(submissionClosedEmbed).ConfigureAwait(false); + await _channel.EmbedAsync(submissionClosedEmbed).ConfigureAwait(false); //VOTING PHASE - this.phase = AcroPhase.Voting; + phase = AcroPhase.Voting; try { //30 secondds for voting - await Task.Delay(30000, source.Token).ConfigureAwait(false); - this.phase = AcroPhase.Idle; + await Task.Delay(30000, _source.Token).ConfigureAwait(false); + phase = AcroPhase.Idle; } catch (OperationCanceledException) { @@ -176,10 +178,10 @@ namespace NadekoBot.Modules.Games try { var msg = arg as SocketUserMessage; - if (msg == null || msg.Author.IsBot || msg.Channel.Id != channel.Id) + if (msg == null || msg.Author.IsBot || msg.Channel.Id != _channel.Id) return; - ++spamCount; + ++_spamCount; var guildUser = (IGuildUser)msg.Author; @@ -187,37 +189,39 @@ namespace NadekoBot.Modules.Games if (phase == AcroPhase.Submitting) { - if (spamCount > 10) + if (_spamCount > 10) { - spamCount = 0; - try { await channel.EmbedAsync(GetEmbed()).ConfigureAwait(false); } + _spamCount = 0; + try { await _channel.EmbedAsync(GetEmbed()).ConfigureAwait(false); } catch { } } var inputWords = input.Split(' '); //get all words - if (inputWords.Length != startingLetters.Length) // number of words must be the same as the number of the starting letters + if (inputWords.Length != _startingLetters.Length) // number of words must be the same as the number of the starting letters return; - for (int i = 0; i < startingLetters.Length; i++) + for (int i = 0; i < _startingLetters.Length; i++) { - var letter = startingLetters[i]; + var letter = _startingLetters[i]; if (!inputWords[i].StartsWith(letter.ToString())) // all first letters must match return; } - if (!usersWhoSubmitted.Add(guildUser.Id)) + if (!_usersWhoSubmitted.Add(guildUser.Id)) return; //try adding it to the list of answers - if (!submissions.TryAdd(input, guildUser)) + if (!_submissions.TryAdd(input, guildUser)) { - usersWhoSubmitted.TryRemove(guildUser.Id); + _usersWhoSubmitted.TryRemove(guildUser.Id); return; } // all good. valid input. answer recorded - await channel.SendConfirmAsync("Acrophobia", $"{guildUser.Mention} submitted their sentence. ({submissions.Count} total)"); + await _channel.SendConfirmAsync(GetText("acrophobia"), + GetText("acro_submit", guildUser.Mention, + _submissions.Count)); try { await msg.DeleteAsync(); @@ -229,10 +233,10 @@ namespace NadekoBot.Modules.Games } else if (phase == AcroPhase.Voting) { - if (spamCount > 10) + if (_spamCount > 10) { - spamCount = 0; - try { await channel.EmbedAsync(GetEmbed()).ConfigureAwait(false); } + _spamCount = 0; + try { await _channel.EmbedAsync(GetEmbed()).ConfigureAwait(false); } catch { } } @@ -248,17 +252,17 @@ namespace NadekoBot.Modules.Games //} int num; - if (int.TryParse(input, out num) && num > 0 && num <= submissions.Count) + if (int.TryParse(input, out num) && num > 0 && num <= _submissions.Count) { - var kvp = submissions.Skip(num - 1).First(); + var kvp = _submissions.Skip(num - 1).First(); usr = kvp.Value; //can't vote for yourself, can't vote multiple times - if (usr.Id == guildUser.Id || !usersWhoVoted.Add(guildUser.Id)) + if (usr.Id == guildUser.Id || !_usersWhoVoted.Add(guildUser.Id)) return; - votes.AddOrUpdate(kvp.Key, 1, (key, old) => ++old); - await channel.SendConfirmAsync("Acrophobia", $"{guildUser.Mention} cast their vote!").ConfigureAwait(false); + _votes.AddOrUpdate(kvp.Key, 1, (key, old) => ++old); + await _channel.SendConfirmAsync(GetText("acrophobia"), + GetText("vote_cast", Format.Bold(guildUser.ToString()))).ConfigureAwait(false); await msg.DeleteAsync().ConfigureAwait(false); - return; } } @@ -271,27 +275,33 @@ namespace NadekoBot.Modules.Games public async Task End() { - if (!votes.Any()) + if (!_votes.Any()) { - await channel.SendErrorAsync("Acrophobia", "No votes cast. Game ended with no winner.").ConfigureAwait(false); + await _channel.SendErrorAsync(GetText("acrophobia"), GetText("no_votes_cast")).ConfigureAwait(false); return; } - var table = votes.OrderByDescending(v => v.Value); + var table = _votes.OrderByDescending(v => v.Value); var winner = table.First(); var embed = new EmbedBuilder().WithOkColor() - .WithTitle("Acrophobia") - .WithDescription($"Winner is {submissions[winner.Key].Mention} with {winner.Value} points.\n") + .WithTitle(GetText("acrophobia")) + .WithDescription(GetText("winner", Format.Bold(_submissions[winner.Key].ToString()), + Format.Bold(winner.Value.ToString()))) .WithFooter(efb => efb.WithText(winner.Key.ToLowerInvariant().ToTitleCase())); - await channel.EmbedAsync(embed).ConfigureAwait(false); + await _channel.EmbedAsync(embed).ConfigureAwait(false); } public void EnsureStopped() { NadekoBot.Client.MessageReceived -= PotentialAcro; - if (!source.IsCancellationRequested) - source.Cancel(); + if (!_source.IsCancellationRequested) + _source.Cancel(); } + + private string GetText(string key, params object[] replacements) + => NadekoModule.GetTextStatic(key, + NadekoBot.Localization.GetCultureInfo(_channel.Guild), + typeof(Games).Name.ToLowerInvariant()); } } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs b/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs index 0541a4ae..1f33bc2a 100644 --- a/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/CleverBotCommands.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Modules.Games public partial class Games { [Group] - public class CleverBotCommands : ModuleBase + public class CleverBotCommands : NadekoSubmodule { private static Logger _log { get; } diff --git a/src/NadekoBot/Modules/Games/Commands/HangmanCommands.cs b/src/NadekoBot/Modules/Games/Commands/HangmanCommands.cs index f3f09da0..0fb8e2f3 100644 --- a/src/NadekoBot/Modules/Games/Commands/HangmanCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/HangmanCommands.cs @@ -13,7 +13,7 @@ namespace NadekoBot.Modules.Games public partial class Games { [Group] - public class HangmanCommands : ModuleBase + public class HangmanCommands : NadekoSubmodule { private static Logger _log { get; } diff --git a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs index 3088546c..1434ee9e 100644 --- a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs @@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Games public partial class Games { [Group] - public class PollCommands : ModuleBase + public class PollCommands : NadekoSubmodule { public static ConcurrentDictionary ActivePolls = new ConcurrentDictionary(); diff --git a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs index fc5a67a2..7dec0992 100644 --- a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs @@ -147,7 +147,7 @@ namespace NadekoBot.Modules.Games } [Group] - public class SpeedTypingCommands : ModuleBase + public class SpeedTypingCommands : NadekoSubmodule { public static List TypingArticles { get; } = new List(); diff --git a/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs b/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs index de36fe3b..2e115fd2 100644 --- a/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs +++ b/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Modules.Games { //todo timeout [Group] - public class TicTacToeCommands : ModuleBase + public class TicTacToeCommands : NadekoSubmodule { //channelId/game private static readonly Dictionary _games = new Dictionary(); diff --git a/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs b/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs index 6f43ff83..be7d135c 100644 --- a/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/TriviaCommands.cs @@ -14,7 +14,7 @@ namespace NadekoBot.Modules.Games public partial class Games { [Group] - public class TriviaCommands : ModuleBase + public class TriviaCommands : NadekoSubmodule { public static ConcurrentDictionary RunningTrivias { get; } = new ConcurrentDictionary(); diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index 9c67460f..b6b9130b 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -6,6 +6,7 @@ using NadekoBot.Attributes; using System; using System.Linq; using System.Collections.Generic; +using System.Collections.Immutable; using NadekoBot.Extensions; namespace NadekoBot.Modules.Games @@ -13,7 +14,7 @@ namespace NadekoBot.Modules.Games [NadekoModule("Games", ">")] public partial class Games : NadekoModule { - private static string[] _8BallResponses { get; } = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToArray(); + private static readonly ImmutableArray _8BallResponses = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToImmutableArray(); [NadekoCommand, Usage, Description, Aliases] public async Task Choose([Remainder] string list = null) @@ -34,8 +35,8 @@ namespace NadekoBot.Modules.Games return; await Context.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor) - .AddField(efb => efb.WithName("❓ Question").WithValue(question).WithIsInline(false)) - .AddField(efb => efb.WithName("🎱 8Ball").WithValue(_8BallResponses[new NadekoRandom().Next(0, _8BallResponses.Length)]).WithIsInline(false))); + .AddField(efb => efb.WithName("❓ " + GetText("question") ).WithValue(question).WithIsInline(false)) + .AddField(efb => efb.WithName("🎱 " + GetText("8ball")).WithValue(_8BallResponses[new NadekoRandom().Next(0, _8BallResponses.Length)]).WithIsInline(false))); } [NadekoCommand, Usage, Description, Aliases] @@ -43,11 +44,15 @@ namespace NadekoBot.Modules.Games { Func GetRPSPick = (p) => { - if (p == 0) - return "🚀"; - if (p == 1) - return "📎"; - return "✂️"; + switch (p) + { + case 0: + return "🚀"; + case 1: + return "📎"; + default: + return "✂️"; + } }; int pick; @@ -71,15 +76,17 @@ namespace NadekoBot.Modules.Games return; } var nadekoPick = new NadekoRandom().Next(0, 3); - var msg = ""; + string msg; if (pick == nadekoPick) - msg = $"It's a draw! Both picked {GetRPSPick(pick)}"; + msg = GetText("rps_draw", GetRPSPick(pick)); else if ((pick == 0 && nadekoPick == 1) || (pick == 1 && nadekoPick == 2) || (pick == 2 && nadekoPick == 0)) - msg = $"{NadekoBot.Client.CurrentUser.Mention} won! {GetRPSPick(nadekoPick)} beats {GetRPSPick(pick)}"; + msg = GetText("rps_win", NadekoBot.Client.CurrentUser.Mention, + GetRPSPick(nadekoPick), GetRPSPick(pick)); else - msg = $"{Context.User.Mention} won! {GetRPSPick(pick)} beats {GetRPSPick(nadekoPick)}"; + msg = GetText("rps_win", Context.User.Mention, GetRPSPick(pick), + GetRPSPick(nadekoPick)); await Context.Channel.SendConfirmAsync(msg).ConfigureAwait(false); } diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index 6e3c725a..e2d01a97 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -2734,6 +2734,159 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to 8ball. + /// + public static string games_8ball { + get { + return ResourceManager.GetString("games_8ball", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Game ended with no submissions.. + /// + public static string games_acro_ended_no_sub { + get { + return ResourceManager.GetString("games_acro_ended_no_sub", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No votes cast. Game ended with no winner.. + /// + public static string games_acro_no_votes_cast { + get { + return ResourceManager.GetString("games_acro_no_votes_cast", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Acronym was {0}.. + /// + public static string games_acro_nym_was { + get { + return ResourceManager.GetString("games_acro_nym_was", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Acrophobia game is already running in this channel.. + /// + public static string games_acro_running { + get { + return ResourceManager.GetString("games_acro_running", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Game started. Create a sentence with the following acronym: {0}.. + /// + public static string games_acro_started { + get { + return ResourceManager.GetString("games_acro_started", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You have {0} seconds to make a submission.. + /// + public static string games_acro_started_footer { + get { + return ResourceManager.GetString("games_acro_started_footer", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} submitted their sentence. ({1} total). + /// + public static string games_acro_submit { + get { + return ResourceManager.GetString("games_acro_submit", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Vote by typing a number of the submission. + /// + public static string games_acro_vote { + get { + return ResourceManager.GetString("games_acro_vote", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} cast their vote!. + /// + public static string games_acro_vote_cast { + get { + return ResourceManager.GetString("games_acro_vote_cast", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Winner is {0} with {1} points.. + /// + public static string games_acro_winner { + get { + return ResourceManager.GetString("games_acro_winner", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} is the winner for being the only user who made a submission!. + /// + public static string games_acro_winner_only { + get { + return ResourceManager.GetString("games_acro_winner_only", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Acrophobia. + /// + public static string games_acrophobia { + get { + return ResourceManager.GetString("games_acrophobia", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Question. + /// + public static string games_question { + get { + return ResourceManager.GetString("games_question", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to It's a draw! Both picked {0}. + /// + public static string games_rps_draw { + get { + return ResourceManager.GetString("games_rps_draw", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} won! {1} beats {2}. + /// + public static string games_rps_win { + get { + return ResourceManager.GetString("games_rps_win", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Submissions Closed. + /// + public static string games_submissions_closed { + get { + return ResourceManager.GetString("games_submissions_closed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Back to ToC. /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 4db9ff76..90024cd2 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -1105,6 +1105,9 @@ Don't forget to leave your discord name or id in the message. Likes + + Nobody + Price @@ -1164,4 +1167,19 @@ Don't forget to leave your discord name or id in the message. You divorced recently. You must wait {0} hours and {1} minutes to divorce again. + + 8ball + + + Acrophobia game is already running in this channel. + + + Question + + + It's a draw! Both picked {0} + + + {0} won! {1} beats {2} + \ No newline at end of file