diff --git a/Geekbot.net/Commands/Rpg/Cookies.cs b/Geekbot.net/Commands/Rpg/Cookies.cs index f55fa6c..21077bf 100644 --- a/Geekbot.net/Commands/Rpg/Cookies.cs +++ b/Geekbot.net/Commands/Rpg/Cookies.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading.Tasks; +using Discord; using Discord.Commands; using Geekbot.net.Database; using Geekbot.net.Database.Models; @@ -67,6 +68,37 @@ namespace Geekbot.net.Commands.Rpg } } + [Command("give", RunMode = RunMode.Async)] + [Summary("Give cookies to someone")] + public async Task PeekIntoCookieJar([Summary("User")] IUser user, [Summary("amount")] int amount) + { + try + { + var transDict = await _translation.GetDict(Context); + var giver = await GetUser(Context.User.Id); + + if (giver.Cookies < amount) + { + await ReplyAsync(string.Format(transDict["NotEnoughToGive"])); + return; + } + + var taker = await GetUser(user.Id); + + giver.Cookies -= amount; + taker.Cookies += amount; + + await SetUser(giver); + await SetUser(taker); + + await ReplyAsync(string.Format(transDict["Given"], amount, user.Username)); + } + catch (Exception e) + { + await _errorHandler.HandleCommandException(e, Context); + } + } + private async Task GetUser(ulong userId) { var user = _database.Cookies.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId); diff --git a/Geekbot.net/Lib/Localization/Translations.json b/Geekbot.net/Lib/Localization/Translations.json index 41865a1..191c4ff 100644 --- a/Geekbot.net/Lib/Localization/Translations.json +++ b/Geekbot.net/Lib/Localization/Translations.json @@ -109,6 +109,14 @@ "InYourJar": { "EN": "There are {0} cookies in you cookie jar", "CHDE": "Es hät {0} guetzli ih dineri büchs" + }, + "Given": { + "EN": "You gave {0} cookies to {1}", + "CHDE": "Du hesch {1} {0} guetzli geh" + }, + "NotEnoughToGive": { + "EN": "You don't have enough cookies", + "CHDE": "Du hesch nid gnueg guetzli" } } } \ No newline at end of file