Add the ability for users to give cookies away

This commit is contained in:
runebaas 2019-05-10 22:30:48 +02:00
parent ba4de946dc
commit fd75fef973
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
2 changed files with 40 additions and 0 deletions

View file

@ -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<CookiesModel> GetUser(ulong userId)
{
var user = _database.Cookies.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId);

View file

@ -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"
}
}
}