waifu game completely localizable?
This commit is contained in:
@@ -3,13 +3,11 @@ using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
@@ -49,8 +47,8 @@ namespace NadekoBot.Modules.Gambling
|
||||
[Group]
|
||||
public class WaifuClaimCommands : NadekoSubmodule
|
||||
{
|
||||
private static ConcurrentDictionary<ulong, DateTime> _divorceCooldowns { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
||||
private static ConcurrentDictionary<ulong, DateTime> _affinityCooldowns { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
||||
private static ConcurrentDictionary<ulong, DateTime> divorceCooldowns { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
||||
private static ConcurrentDictionary<ulong, DateTime> affinityCooldowns { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
||||
|
||||
enum WaifuClaimResult
|
||||
{
|
||||
@@ -65,20 +63,19 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
if (amount < 50)
|
||||
{
|
||||
await Context.Channel.SendErrorAsync($"{Context.User.Mention} No waifu is that cheap. You must pay at least 50{NadekoBot.BotConfig.CurrencySign} to get a waifu, even if their actual value is lower.").ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("waifu_isnt_cheap", 50 + CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.Id == Context.User.Id)
|
||||
{
|
||||
await Context.Channel.SendErrorAsync(Context.User.Mention + " You can't claim yourself.").ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("waifu_not_yourself").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
WaifuClaimResult result = WaifuClaimResult.NotEnoughFunds;
|
||||
int? oldPrice = null;
|
||||
WaifuClaimResult result;
|
||||
WaifuInfo w;
|
||||
var isAffinity = false;
|
||||
bool isAffinity;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
w = uow.Waifus.ByWaifuUserId(target.Id);
|
||||
@@ -120,7 +117,6 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
var oldClaimer = w.Claimer;
|
||||
w.Claimer = uow.DiscordUsers.GetOrCreate(Context.User);
|
||||
oldPrice = w.Price;
|
||||
w.Price = amount + (amount / 4);
|
||||
result = WaifuClaimResult.Success;
|
||||
|
||||
@@ -143,7 +139,6 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
var oldClaimer = w.Claimer;
|
||||
w.Claimer = uow.DiscordUsers.GetOrCreate(Context.User);
|
||||
oldPrice = w.Price;
|
||||
w.Price = amount;
|
||||
result = WaifuClaimResult.Success;
|
||||
|
||||
@@ -165,22 +160,20 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
if (result == WaifuClaimResult.InsufficientAmount)
|
||||
{
|
||||
await Context.Channel.SendErrorAsync($"{Context.User.Mention} You must pay {Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f))} or more to claim that waifu!").ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("waifu_not_enough", Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f))).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
else if (result == WaifuClaimResult.NotEnoughFunds)
|
||||
if (result == WaifuClaimResult.NotEnoughFunds)
|
||||
{
|
||||
await Context.Channel.SendConfirmAsync($"{Context.User.Mention} you don't have {amount}{NadekoBot.BotConfig.CurrencySign}!")
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var msg = $"{Context.User.Mention} claimed {target.Mention} as their waifu for {amount}{NadekoBot.BotConfig.CurrencySign}!";
|
||||
if (w.Affinity?.UserId == Context.User.Id)
|
||||
msg += $"\n🎉 Their love is fulfilled! 🎉\n**{target}'s** new value is {w.Price}{NadekoBot.BotConfig.CurrencySign}!";
|
||||
await Context.Channel.SendConfirmAsync(msg)
|
||||
.ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var msg = GetText("waifu_claimed",
|
||||
Format.Bold(target.ToString()),
|
||||
amount + CurrencySign);
|
||||
if (w.Affinity?.UserId == Context.User.Id)
|
||||
msg += "\n" + GetText("waifu_fulfilled", target, w.Price + CurrencySign);
|
||||
await Context.Channel.SendConfirmAsync(Context.User.Mention + msg).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public enum DivorceResult
|
||||
@@ -192,7 +185,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
}
|
||||
|
||||
|
||||
private static readonly TimeSpan DivorceLimit = TimeSpan.FromHours(6);
|
||||
private static readonly TimeSpan _divorceLimit = TimeSpan.FromHours(6);
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Divorce([Remainder]IUser target)
|
||||
@@ -200,19 +193,19 @@ namespace NadekoBot.Modules.Gambling
|
||||
if (target.Id == Context.User.Id)
|
||||
return;
|
||||
|
||||
var result = DivorceResult.NotYourWife;
|
||||
TimeSpan difference = TimeSpan.Zero;
|
||||
DivorceResult result;
|
||||
var difference = TimeSpan.Zero;
|
||||
var amount = 0;
|
||||
WaifuInfo w = null;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
w = uow.Waifus.ByWaifuUserId(target.Id);
|
||||
var now = DateTime.UtcNow;
|
||||
if (w == null || w.Claimer == null || w.Claimer.UserId != Context.User.Id)
|
||||
if (w?.Claimer == null || w.Claimer.UserId != Context.User.Id)
|
||||
result = DivorceResult.NotYourWife;
|
||||
else if (_divorceCooldowns.AddOrUpdate(Context.User.Id,
|
||||
else if (divorceCooldowns.AddOrUpdate(Context.User.Id,
|
||||
now,
|
||||
(key, old) => ((difference = now.Subtract(old)) > DivorceLimit) ? now : old) != now)
|
||||
(key, old) => ((difference = now.Subtract(old)) > _divorceLimit) ? now : old) != now)
|
||||
{
|
||||
result = DivorceResult.Cooldown;
|
||||
}
|
||||
@@ -249,37 +242,39 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
if (result == DivorceResult.SucessWithPenalty)
|
||||
{
|
||||
await Context.Channel.SendConfirmAsync($"{Context.User.Mention} You have divorced a waifu who likes you. You heartless monster.\n{w.Waifu} received {amount}{NadekoBot.BotConfig.CurrencySign} as a compensation.").ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + CurrencySign).ConfigureAwait(false);
|
||||
}
|
||||
else if (result == DivorceResult.Success)
|
||||
{
|
||||
await Context.Channel.SendConfirmAsync($"{Context.User.Mention} You have divorced a waifu who doesn't like you. You received {amount}{NadekoBot.BotConfig.CurrencySign} back.").ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("waifu_divorced_notlike", amount + CurrencySign).ConfigureAwait(false);
|
||||
}
|
||||
else if (result == DivorceResult.NotYourWife)
|
||||
{
|
||||
await Context.Channel.SendErrorAsync($"{Context.User.Mention} That waifu is not yours.").ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("waifu_not_yours").ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var remaining = DivorceLimit.Subtract(difference);
|
||||
await Context.Channel.SendErrorAsync($"{Context.User.Mention} You divorced recently. You must wait **{remaining.Hours} hours and {remaining.Minutes} minutes** to divorce again.").ConfigureAwait(false);
|
||||
var remaining = _divorceLimit.Subtract(difference);
|
||||
await ReplyErrorLocalized("waifu_recent_divorce",
|
||||
Format.Bold(((int)remaining.TotalHours).ToString()),
|
||||
Format.Bold(remaining.Minutes.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly TimeSpan AffinityLimit = TimeSpan.FromMinutes(30);
|
||||
private static readonly TimeSpan _affinityLimit = TimeSpan.FromMinutes(30);
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task WaifuClaimerAffinity([Remainder]IUser u = null)
|
||||
{
|
||||
if (u?.Id == Context.User.Id)
|
||||
{
|
||||
await Context.Channel.SendErrorAsync($"{Context.User.Mention} you can't set affinity to yourself, you egomaniac.").ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("waifu_egomaniac").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
DiscordUser oldAff = null;
|
||||
var sucess = false;
|
||||
var cooldown = false;
|
||||
TimeSpan difference = TimeSpan.Zero;
|
||||
var difference = TimeSpan.Zero;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var w = uow.Waifus.ByWaifuUserId(Context.User.Id);
|
||||
@@ -287,13 +282,11 @@ namespace NadekoBot.Modules.Gambling
|
||||
var now = DateTime.UtcNow;
|
||||
if (w?.Affinity?.UserId == u?.Id)
|
||||
{
|
||||
sucess = false;
|
||||
}
|
||||
else if (_affinityCooldowns.AddOrUpdate(Context.User.Id,
|
||||
else if (affinityCooldowns.AddOrUpdate(Context.User.Id,
|
||||
now,
|
||||
(key, old) => ((difference = now.Subtract(old)) > AffinityLimit) ? now : old) != now)
|
||||
(key, old) => ((difference = now.Subtract(old)) > _affinityLimit) ? now : old) != now)
|
||||
{
|
||||
sucess = false;
|
||||
cooldown = true;
|
||||
}
|
||||
else if (w == null)
|
||||
@@ -338,19 +331,29 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
if (cooldown)
|
||||
{
|
||||
var remaining = AffinityLimit.Subtract(difference);
|
||||
await Context.Channel.SendErrorAsync($"{Context.User.Mention} You must wait **{remaining.Hours} hours and {remaining.Minutes} minutes** in order to change your affinity again.").ConfigureAwait(false);
|
||||
var remaining = _affinityLimit.Subtract(difference);
|
||||
await ReplyErrorLocalized("waifu_affinity_cooldown",
|
||||
Format.Bold(((int)remaining.TotalHours).ToString()),
|
||||
Format.Bold(remaining.Minutes.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
await Context.Channel.SendErrorAsync($"{Context.User.Mention} your affinity is already set to that waifu or you're trying to remove your affinity while not having one.").ConfigureAwait(false);
|
||||
{
|
||||
await ReplyErrorLocalized("waifu_affinity_already").ConfigureAwait(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (u == null)
|
||||
await Context.Channel.SendConfirmAsync("Affinity Reset", $"{Context.User.Mention} Your affinity is reset. You no longer have a person you like.").ConfigureAwait(false);
|
||||
{
|
||||
await ReplyConfirmLocalized("waifu_affinity_reset").ConfigureAwait(false);
|
||||
}
|
||||
else if (oldAff == null)
|
||||
await Context.Channel.SendConfirmAsync("Affinity Set", $"{Context.User.Mention} wants to be {u.Mention}'s waifu. Aww <3").ConfigureAwait(false);
|
||||
{
|
||||
await ReplyConfirmLocalized("waifu_affinity_set", Format.Bold(u.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
await Context.Channel.SendConfirmAsync("Affinity Changed", $"{Context.User.Mention} changed their affinity from {oldAff} to {u.Mention}.\n\n*This is morally questionable.*🤔").ConfigureAwait(false);
|
||||
{
|
||||
await ReplyConfirmLocalized("waifu_affinity_changed", Format.Bold(oldAff.ToString()), Format.Bold(u.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@@ -365,19 +368,20 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
if (waifus.Count == 0)
|
||||
{
|
||||
await Context.Channel.SendConfirmAsync("No waifus have been claimed yet.").ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("waifu_none").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle("Top Waifus")
|
||||
.WithTitle(GetText("waifus_top_waifus"))
|
||||
.WithOkColor();
|
||||
|
||||
for (int i = 0; i < waifus.Count; i++)
|
||||
for (var i = 0; i < waifus.Count; i++)
|
||||
{
|
||||
var w = waifus[i];
|
||||
|
||||
embed.AddField(efb => efb.WithName("#" + (i + 1) + " - " + w.Price + NadekoBot.BotConfig.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
|
||||
var j = i;
|
||||
embed.AddField(efb => efb.WithName("#" + (j + 1) + " - " + w.Price + NadekoBot.BotConfig.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
|
||||
}
|
||||
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
@@ -419,15 +423,16 @@ namespace NadekoBot.Modules.Gambling
|
||||
var claimInfo = GetClaimTitle(target.Id);
|
||||
var affInfo = GetAffinityTitle(target.Id);
|
||||
|
||||
var nobody = GetText("nobody");
|
||||
var embed = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle("Waifu " + w.Waifu + " - \"the " + claimInfo.Title + "\"")
|
||||
.AddField(efb => efb.WithName("Price").WithValue(w.Price.ToString()).WithIsInline(true))
|
||||
.AddField(efb => efb.WithName("Claimed by").WithValue(w.Claimer?.ToString() ?? "No one").WithIsInline(true))
|
||||
.AddField(efb => efb.WithName("Likes").WithValue(w.Affinity?.ToString() ?? "Nobody").WithIsInline(true))
|
||||
.AddField(efb => efb.WithName("Changes Of Heart").WithValue($"{affInfo.Count} - \"the {affInfo.Title}\"").WithIsInline(true))
|
||||
.AddField(efb => efb.WithName("Divorces").WithValue(divorces.ToString()).WithIsInline(true))
|
||||
.AddField(efb => efb.WithName($"Waifus ({claims.Count})").WithValue(claims.Count == 0 ? "Nobody" : string.Join("\n", claims.Select(x => x.Waifu))).WithIsInline(true));
|
||||
.AddField(efb => efb.WithName(GetText("price")).WithValue(w.Price.ToString()).WithIsInline(true))
|
||||
.AddField(efb => efb.WithName(GetText("claimed_by")).WithValue(w.Claimer?.ToString() ?? nobody).WithIsInline(true))
|
||||
.AddField(efb => efb.WithName(GetText("likes")).WithValue(w.Affinity?.ToString() ?? nobody).WithIsInline(true))
|
||||
.AddField(efb => efb.WithName(GetText("changes_of_heart")).WithValue($"{affInfo.Count} - \"the {affInfo.Title}\"").WithIsInline(true))
|
||||
.AddField(efb => efb.WithName(GetText("divorces")).WithValue(divorces.ToString()).WithIsInline(true))
|
||||
.AddField(efb => efb.WithName($"Waifus ({claims.Count})").WithValue(claims.Count == 0 ? nobody : string.Join("\n", claims.Select(x => x.Waifu))).WithIsInline(true));
|
||||
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
@@ -447,13 +452,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
private static WaifuProfileTitle GetClaimTitle(ulong userId)
|
||||
{
|
||||
int count = 0;
|
||||
int count;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
count = uow.Waifus.ByClaimerUserId(userId).Count;
|
||||
}
|
||||
|
||||
ClaimTitles title = ClaimTitles.Lonely;
|
||||
ClaimTitles title;
|
||||
if (count == 0)
|
||||
title = ClaimTitles.Lonely;
|
||||
else if (count == 1)
|
||||
@@ -484,13 +489,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
private static WaifuProfileTitle GetAffinityTitle(ulong userId)
|
||||
{
|
||||
int count = 0;
|
||||
int count;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
count = uow._context.WaifuUpdates.Count(w => w.User.UserId == userId && w.UpdateType == WaifuUpdateType.AffinityChanged);
|
||||
}
|
||||
|
||||
AffinityTitles title = AffinityTitles.Pure;
|
||||
AffinityTitles title;
|
||||
if (count < 1)
|
||||
title = AffinityTitles.Pure;
|
||||
else if (count < 2)
|
||||
|
@@ -127,7 +127,7 @@ namespace NadekoBot.Modules.Searches
|
||||
.WithIconUrl("http://i.imgur.com/G46fm8J.png"))
|
||||
.WithDescription(res.Link)
|
||||
.WithImageUrl(res.Link)
|
||||
.WithTitle(Context.User.Mention);
|
||||
.WithTitle(Context.User.ToString());
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
@@ -157,7 +157,7 @@ namespace NadekoBot.Modules.Searches
|
||||
.WithIconUrl("http://s.imgur.com/images/logo-1200-630.jpg?"))
|
||||
.WithDescription(source)
|
||||
.WithImageUrl(source)
|
||||
.WithTitle(Context.User.Mention);
|
||||
.WithTitle(Context.User.ToString());
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@ namespace NadekoBot.Modules.Searches
|
||||
.WithIconUrl("http://i.imgur.com/G46fm8J.png"))
|
||||
.WithDescription(res.Link)
|
||||
.WithImageUrl(res.Link)
|
||||
.WithTitle(Context.User.Mention);
|
||||
.WithTitle(Context.User.ToString());
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
@@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Searches
|
||||
.WithIconUrl("http://s.imgur.com/images/logo-1200-630.jpg?"))
|
||||
.WithDescription(source)
|
||||
.WithImageUrl(source)
|
||||
.WithTitle(Context.User.Mention);
|
||||
.WithTitle(Context.User.ToString());
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user