Let users eat their cookies

This commit is contained in:
runebaas 2019-05-10 22:42:53 +02:00
parent fd75fef973
commit fe08eee049
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
2 changed files with 37 additions and 1 deletions

View file

@ -70,7 +70,7 @@ 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)
public async Task GiveACookie([Summary("User")] IUser user, [Summary("amount")] int amount)
{
try
{
@ -99,6 +99,34 @@ namespace Geekbot.net.Commands.Rpg
}
}
[Command("eat", RunMode = RunMode.Async)]
[Summary("Eat a cookie")]
public async Task EatACookie()
{
try
{
var transDict = await _translation.GetDict(Context);
var actor = await GetUser(Context.User.Id);
if (actor.Cookies < 5)
{
await ReplyAsync(string.Format(transDict["NotEnoughCookiesToEat"]));
return;
}
var amount = new Random().Next(1, 5);
actor.Cookies -= amount;
await SetUser(actor);
await ReplyAsync(string.Format(transDict["AteCookies"], amount, actor.Cookies));
}
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

@ -117,6 +117,14 @@
"NotEnoughToGive": {
"EN": "You don't have enough cookies",
"CHDE": "Du hesch nid gnueg guetzli"
},
"NotEnoughCookiesToEat": {
"EN": "Your cookie jar looks almost empty, you should probably not eat a cookie",
"CHDE": "Du hesch chuum no guetzli ih dineri büchs, du sötsch warschinli keini esse"
},
"AteCookies": {
"EN": "You ate {0} cookies, you've only got {1} cookies left",
"CHDE": "Du hesch {0} guetzli gesse und hesch jezt no {1} übrig"
}
}
}