diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ef3a154..8c05c57d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog. - Added `.massban` to ban multiple people at once. 30 second cooldown - Added `.youtubeuploadnotif` / `.yun` as a shortcut for subscribing to a youtube channel's rss feed -- Added `.imageonlychannel` / `.imageonly` to prevent users from posting anything but images in the channel +- Added `.imageonlychannel` / `.imageonly` to prevent users from posting anything but images in the channel +- Added `.config games hangman.currency_reward` and a property with the same name in games.yml + - If set, users will gain the specified amount of currency for each hangman win - Fully translated to Spanish, Russian and Ukrainian 🎉 ### Changed diff --git a/src/NadekoBot/Modules/Games/Common/GamesConfig.cs b/src/NadekoBot/Modules/Games/Common/GamesConfig.cs index 9e88c7969..297c105ed 100644 --- a/src/NadekoBot/Modules/Games/Common/GamesConfig.cs +++ b/src/NadekoBot/Modules/Games/Common/GamesConfig.cs @@ -8,6 +8,15 @@ namespace NadekoBot.Modules.Games.Common [Cloneable] public sealed partial class GamesConfig : ICloneable { + [Comment("DO NOT CHANGE")] + public int Version { get; set; } + + [Comment("Hangman related settings (.hangman command)")] + public HangmanConfig Hangman { get; set; } = new HangmanConfig() + { + CurrencyReward = 0 + }; + [Comment("Trivia related settings (.t command)")] public TriviaConfig Trivia { get; set; } = new TriviaConfig() { @@ -57,6 +66,13 @@ namespace NadekoBot.Modules.Games.Common }; } + [Cloneable] + public sealed partial class HangmanConfig + { + [Comment("The amount of currency awarded to the winner of a hangman game")] + public long CurrencyReward { get; set; } + } + [Cloneable] public sealed partial class TriviaConfig { diff --git a/src/NadekoBot/Modules/Games/Common/Hangman/Hangman.cs b/src/NadekoBot/Modules/Games/Common/Hangman/Hangman.cs index 753a1fe2b..36e99a2ec 100644 --- a/src/NadekoBot/Modules/Games/Common/Hangman/Hangman.cs +++ b/src/NadekoBot/Modules/Games/Common/Hangman/Hangman.cs @@ -45,7 +45,7 @@ namespace NadekoBot.Modules.Games.Common.Hangman public uint Errors { get; private set; } = 0; public uint MaxErrors { get; } = 6; - public event Func OnGameEnded = delegate { return Task.CompletedTask; }; + public event Func OnGameEnded = delegate { return Task.CompletedTask; }; public event Func OnLetterAlreadyUsed = delegate { return Task.CompletedTask; }; public event Func OnGuessFailed = delegate { return Task.CompletedTask; }; public event Func OnGuessSucceeded = delegate { return Task.CompletedTask; }; @@ -68,7 +68,7 @@ namespace NadekoBot.Modules.Games.Common.Hangman { if (++Errors > MaxErrors) { - var _ = OnGameEnded(this, null); + var _ = OnGameEnded(this, null, 0); CurrentPhase = Phase.Ended; } } @@ -102,7 +102,7 @@ namespace NadekoBot.Modules.Games.Common.Hangman if (input != Term.Word) // failed return; - var _ = OnGameEnded?.Invoke(this, userName); + var _ = OnGameEnded?.Invoke(this, userName, userId); CurrentPhase = Phase.Ended; return; } @@ -127,7 +127,7 @@ namespace NadekoBot.Modules.Games.Common.Hangman else if (Term.Word.All(x => _previousGuesses.IsSupersetOf(Term.Word.ToLowerInvariant() .Where(char.IsLetterOrDigit)))) { - var _ = OnGameEnded.Invoke(this, userName); // if all letters are guessed + var _ = OnGameEnded.Invoke(this, userName, userId); // if all letters are guessed CurrentPhase = Phase.Ended; } else // guessed but not last letter diff --git a/src/NadekoBot/Modules/Games/HangmanCommands.cs b/src/NadekoBot/Modules/Games/HangmanCommands.cs index cd3dd02b8..533c22f11 100644 --- a/src/NadekoBot/Modules/Games/HangmanCommands.cs +++ b/src/NadekoBot/Modules/Games/HangmanCommands.cs @@ -8,6 +8,7 @@ using NadekoBot.Common.Attributes; using NadekoBot.Modules.Games.Common.Hangman; using NadekoBot.Modules.Games.Services; using NadekoBot.Modules.Games.Common.Hangman.Exceptions; +using NadekoBot.Services; namespace NadekoBot.Modules.Games { @@ -17,10 +18,14 @@ namespace NadekoBot.Modules.Games public class HangmanCommands : NadekoSubmodule { private readonly DiscordSocketClient _client; + private readonly ICurrencyService _cs; + private readonly GamesConfigService _gcs; - public HangmanCommands(DiscordSocketClient client) + public HangmanCommands(DiscordSocketClient client, ICurrencyService cs, GamesConfigService gcs) { _client = client; + _cs = cs; + _gcs = gcs; } [NadekoCommand, Aliases] @@ -83,7 +88,7 @@ namespace NadekoBot.Modules.Games } } - Task Hm_OnGameEnded(Hangman game, string winner) + Task Hm_OnGameEnded(Hangman game, string winner, ulong userId) { if (winner is null) { @@ -99,6 +104,10 @@ namespace NadekoBot.Modules.Games return ctx.Channel.EmbedAsync(loseEmbed); } + var reward = _gcs.Data.Hangman.CurrencyReward; + if (reward > 0) + _cs.AddAsync(userId, "hangman win", reward, true); + var winEmbed = _eb.Create().WithTitle($"Hangman Game ({game.TermType}) - Ended") .WithDescription(Format.Bold($"{winner} Won.")) .AddField("It was", game.Term.GetWord()) diff --git a/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs b/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs index e3749b177..390c4fb30 100644 --- a/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs +++ b/src/NadekoBot/Modules/Games/Services/GamesConfigService.cs @@ -18,6 +18,25 @@ namespace NadekoBot.Modules.Games.Services ConfigPrinters.ToString, val => val > 0); AddParsedProp("trivia.currency_reward", gs => gs.Trivia.CurrencyReward, long.TryParse, ConfigPrinters.ToString, val => val >= 0); + AddParsedProp("hangman.currency_reward", gs => gs.Hangman.CurrencyReward, long.TryParse, + ConfigPrinters.ToString, val => val >= 0); + + Migrate(); + } + + private void Migrate() + { + if (_data.Version < 1) + { + ModifyConfig(c => + { + c.Version = 1; + c.Hangman = new HangmanConfig() + { + CurrencyReward = 0 + }; + }); + } } } } \ No newline at end of file diff --git a/src/NadekoBot/data/games.yml b/src/NadekoBot/data/games.yml index 3dc887d01..0261304a0 100644 --- a/src/NadekoBot/data/games.yml +++ b/src/NadekoBot/data/games.yml @@ -1,3 +1,9 @@ +# DO NOT CHANGE +version: 1 +# Hangman related settings (.hangman command) +hangman: +# The amount of currency awarded to the winner of a hangman game + currencyReward: 0 # Trivia related settings (.t command) trivia: # The amount of currency awarded to the winner of the trivia game.