2017-01-22 20:06:10 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using NadekoBot.Services;
|
|
|
|
|
using NadekoBot.Services.Database.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common;
|
|
|
|
|
using NadekoBot.Common.Attributes;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Gambling
|
|
|
|
|
{
|
|
|
|
|
public partial class Gambling
|
|
|
|
|
{
|
|
|
|
|
public enum ClaimTitles
|
|
|
|
|
{
|
|
|
|
|
Lonely,
|
|
|
|
|
Devoted,
|
|
|
|
|
Rookie,
|
|
|
|
|
Schemer,
|
|
|
|
|
Dilettante,
|
|
|
|
|
Intermediate,
|
|
|
|
|
Seducer,
|
|
|
|
|
Expert,
|
|
|
|
|
Veteran,
|
|
|
|
|
Incubis,
|
|
|
|
|
Harem_King,
|
|
|
|
|
Harem_God,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum AffinityTitles
|
|
|
|
|
{
|
|
|
|
|
Pure,
|
|
|
|
|
Faithful,
|
|
|
|
|
Defiled,
|
|
|
|
|
Cheater,
|
|
|
|
|
Tainted,
|
|
|
|
|
Corrupted,
|
|
|
|
|
Lewd,
|
|
|
|
|
Sloot,
|
|
|
|
|
Depraved,
|
|
|
|
|
Harlot
|
|
|
|
|
}
|
2017-10-09 00:52:46 +00:00
|
|
|
|
//todo unclaimed waifus should lose 3% of their value a day
|
2017-01-22 20:06:10 +00:00
|
|
|
|
[Group]
|
2017-02-15 10:03:40 +00:00
|
|
|
|
public class WaifuClaimCommands : NadekoSubmodule
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-09-10 01:52:34 +00:00
|
|
|
|
private static ConcurrentDictionary<ulong, DateTime> _divorceCooldowns { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
|
|
|
|
private static ConcurrentDictionary<ulong, DateTime> _affinityCooldowns { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
2017-01-22 20:06:10 +00:00
|
|
|
|
|
|
|
|
|
enum WaifuClaimResult
|
|
|
|
|
{
|
|
|
|
|
Success,
|
|
|
|
|
NotEnoughFunds,
|
|
|
|
|
InsufficientAmount
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 03:10:39 +00:00
|
|
|
|
public WaifuClaimCommands(IBotConfigProvider bc, CurrencyService cs, DbService db)
|
2017-05-24 20:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
_bc = bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
_cs = cs;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
_db = db;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-22 20:06:10 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
public async Task WaifuClaim(int amount, [Remainder]IUser target)
|
|
|
|
|
{
|
|
|
|
|
if (amount < 50)
|
|
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
|
await ReplyErrorLocalized("waifu_isnt_cheap", 50 + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (target.Id == Context.User.Id)
|
|
|
|
|
{
|
2017-02-19 01:11:31 +00:00
|
|
|
|
await ReplyErrorLocalized("waifu_not_yourself").ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
WaifuClaimResult result;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
WaifuInfo w;
|
2017-02-19 01:11:31 +00:00
|
|
|
|
bool isAffinity;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
w = uow.Waifus.ByWaifuUserId(target.Id);
|
|
|
|
|
isAffinity = (w?.Affinity?.UserId == Context.User.Id);
|
|
|
|
|
if (w == null)
|
|
|
|
|
{
|
|
|
|
|
var claimer = uow.DiscordUsers.GetOrCreate(Context.User);
|
|
|
|
|
var waifu = uow.DiscordUsers.GetOrCreate(target);
|
2017-05-29 04:13:22 +00:00
|
|
|
|
if (!await _cs.RemoveAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
result = WaifuClaimResult.NotEnoughFunds;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
uow.Waifus.Add(w = new WaifuInfo()
|
|
|
|
|
{
|
|
|
|
|
Waifu = waifu,
|
|
|
|
|
Claimer = claimer,
|
|
|
|
|
Affinity = null,
|
|
|
|
|
Price = amount
|
|
|
|
|
});
|
|
|
|
|
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
|
|
|
|
{
|
|
|
|
|
User = waifu,
|
|
|
|
|
Old = null,
|
|
|
|
|
New = claimer,
|
|
|
|
|
UpdateType = WaifuUpdateType.Claimed
|
|
|
|
|
});
|
|
|
|
|
result = WaifuClaimResult.Success;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-11 14:21:09 +00:00
|
|
|
|
else if (isAffinity && amount > w.Price * 0.88f)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
if (!await _cs.RemoveAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
result = WaifuClaimResult.NotEnoughFunds;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var oldClaimer = w.Claimer;
|
|
|
|
|
w.Claimer = uow.DiscordUsers.GetOrCreate(Context.User);
|
|
|
|
|
w.Price = amount + (amount / 4);
|
|
|
|
|
result = WaifuClaimResult.Success;
|
|
|
|
|
|
|
|
|
|
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
|
|
|
|
{
|
|
|
|
|
User = w.Waifu,
|
|
|
|
|
Old = oldClaimer,
|
|
|
|
|
New = w.Claimer,
|
|
|
|
|
UpdateType = WaifuUpdateType.Claimed
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (amount >= w.Price * 1.1f) // if no affinity
|
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
if (!await _cs.RemoveAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
result = WaifuClaimResult.NotEnoughFunds;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var oldClaimer = w.Claimer;
|
|
|
|
|
w.Claimer = uow.DiscordUsers.GetOrCreate(Context.User);
|
|
|
|
|
w.Price = amount;
|
|
|
|
|
result = WaifuClaimResult.Success;
|
|
|
|
|
|
|
|
|
|
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
|
|
|
|
{
|
|
|
|
|
User = w.Waifu,
|
|
|
|
|
Old = oldClaimer,
|
|
|
|
|
New = w.Claimer,
|
|
|
|
|
UpdateType = WaifuUpdateType.Claimed
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
result = WaifuClaimResult.InsufficientAmount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result == WaifuClaimResult.InsufficientAmount)
|
|
|
|
|
{
|
2017-02-19 01:11:31 +00:00
|
|
|
|
await ReplyErrorLocalized("waifu_not_enough", Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f))).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-02-19 01:11:31 +00:00
|
|
|
|
if (result == WaifuClaimResult.NotEnoughFunds)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
|
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
2017-02-19 01:11:31 +00:00
|
|
|
|
return;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
2017-02-19 01:11:31 +00:00
|
|
|
|
var msg = GetText("waifu_claimed",
|
|
|
|
|
Format.Bold(target.ToString()),
|
2017-07-20 03:10:39 +00:00
|
|
|
|
amount + _bc.BotConfig.CurrencySign);
|
2017-02-19 01:11:31 +00:00
|
|
|
|
if (w.Affinity?.UserId == Context.User.Id)
|
2017-07-20 03:10:39 +00:00
|
|
|
|
msg += "\n" + GetText("waifu_fulfilled", target, w.Price + _bc.BotConfig.CurrencySign);
|
2017-05-16 21:57:25 +00:00
|
|
|
|
else
|
|
|
|
|
msg = " " + msg;
|
2017-02-19 01:11:31 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync(Context.User.Mention + msg).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum DivorceResult
|
|
|
|
|
{
|
|
|
|
|
Success,
|
|
|
|
|
SucessWithPenalty,
|
|
|
|
|
NotYourWife,
|
|
|
|
|
Cooldown
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
private static readonly TimeSpan _divorceLimit = TimeSpan.FromHours(6);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-07-15 03:04:16 +00:00
|
|
|
|
[Priority(0)]
|
2017-05-17 12:28:50 +00:00
|
|
|
|
public Task Divorce([Remainder]IGuildUser target) => Divorce(target.Id);
|
2017-05-16 16:53:10 +00:00
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-07-15 03:04:16 +00:00
|
|
|
|
[Priority(1)]
|
2017-05-16 16:53:10 +00:00
|
|
|
|
public async Task Divorce([Remainder]ulong targetId)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-05-16 16:53:10 +00:00
|
|
|
|
if (targetId == Context.User.Id)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
DivorceResult result;
|
|
|
|
|
var difference = TimeSpan.Zero;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
var amount = 0;
|
|
|
|
|
WaifuInfo w = null;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-05-16 16:53:10 +00:00
|
|
|
|
w = uow.Waifus.ByWaifuUserId(targetId);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
var now = DateTime.UtcNow;
|
2017-02-19 01:11:31 +00:00
|
|
|
|
if (w?.Claimer == null || w.Claimer.UserId != Context.User.Id)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
result = DivorceResult.NotYourWife;
|
2017-09-10 01:52:34 +00:00
|
|
|
|
else if (_divorceCooldowns.AddOrUpdate(Context.User.Id,
|
2017-01-22 20:06:10 +00:00
|
|
|
|
now,
|
2017-02-19 01:11:31 +00:00
|
|
|
|
(key, old) => ((difference = now.Subtract(old)) > _divorceLimit) ? now : old) != now)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
result = DivorceResult.Cooldown;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
amount = w.Price / 2;
|
|
|
|
|
|
|
|
|
|
if (w.Affinity?.UserId == Context.User.Id)
|
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
await _cs.AddAsync(w.Waifu.UserId, "Waifu Compensation", amount, uow).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
w.Price = (int)Math.Floor(w.Price * 0.75f);
|
|
|
|
|
result = DivorceResult.SucessWithPenalty;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
await _cs.AddAsync(Context.User.Id, "Waifu Refund", amount, uow).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
|
|
|
|
|
result = DivorceResult.Success;
|
|
|
|
|
}
|
|
|
|
|
var oldClaimer = w.Claimer;
|
|
|
|
|
w.Claimer = null;
|
|
|
|
|
|
|
|
|
|
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
|
|
|
|
{
|
|
|
|
|
User = w.Waifu,
|
|
|
|
|
Old = oldClaimer,
|
|
|
|
|
New = null,
|
|
|
|
|
UpdateType = WaifuUpdateType.Claimed
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result == DivorceResult.SucessWithPenalty)
|
|
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
|
await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
else if (result == DivorceResult.Success)
|
|
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
|
await ReplyConfirmLocalized("waifu_divorced_notlike", amount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
else if (result == DivorceResult.NotYourWife)
|
|
|
|
|
{
|
2017-02-19 01:11:31 +00:00
|
|
|
|
await ReplyErrorLocalized("waifu_not_yours").ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-19 01:11:31 +00:00
|
|
|
|
var remaining = _divorceLimit.Subtract(difference);
|
|
|
|
|
await ReplyErrorLocalized("waifu_recent_divorce",
|
|
|
|
|
Format.Bold(((int)remaining.TotalHours).ToString()),
|
|
|
|
|
Format.Bold(remaining.Minutes.ToString())).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
private static readonly TimeSpan _affinityLimit = TimeSpan.FromMinutes(30);
|
2017-07-20 03:10:39 +00:00
|
|
|
|
private readonly IBotConfigProvider _bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly CurrencyService _cs;
|
|
|
|
|
private readonly DbService _db;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
|
2017-01-22 20:06:10 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-04-25 04:53:03 +00:00
|
|
|
|
public async Task WaifuClaimerAffinity([Remainder]IGuildUser u = null)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
if (u?.Id == Context.User.Id)
|
|
|
|
|
{
|
2017-02-19 01:11:31 +00:00
|
|
|
|
await ReplyErrorLocalized("waifu_egomaniac").ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DiscordUser oldAff = null;
|
|
|
|
|
var sucess = false;
|
|
|
|
|
var cooldown = false;
|
2017-02-19 01:11:31 +00:00
|
|
|
|
var difference = TimeSpan.Zero;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
var w = uow.Waifus.ByWaifuUserId(Context.User.Id);
|
|
|
|
|
var newAff = u == null ? null : uow.DiscordUsers.GetOrCreate(u);
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
if (w?.Affinity?.UserId == u?.Id)
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-09-10 01:52:34 +00:00
|
|
|
|
else if (_affinityCooldowns.AddOrUpdate(Context.User.Id,
|
2017-01-22 20:06:10 +00:00
|
|
|
|
now,
|
2017-02-19 01:11:31 +00:00
|
|
|
|
(key, old) => ((difference = now.Subtract(old)) > _affinityLimit) ? now : old) != now)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
cooldown = true;
|
|
|
|
|
}
|
|
|
|
|
else if (w == null)
|
|
|
|
|
{
|
|
|
|
|
var thisUser = uow.DiscordUsers.GetOrCreate(Context.User);
|
|
|
|
|
uow.Waifus.Add(new WaifuInfo()
|
|
|
|
|
{
|
|
|
|
|
Affinity = newAff,
|
|
|
|
|
Waifu = thisUser,
|
|
|
|
|
Price = 1,
|
|
|
|
|
Claimer = null
|
|
|
|
|
});
|
|
|
|
|
sucess = true;
|
|
|
|
|
|
|
|
|
|
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
|
|
|
|
{
|
|
|
|
|
User = thisUser,
|
|
|
|
|
Old = null,
|
|
|
|
|
New = newAff,
|
|
|
|
|
UpdateType = WaifuUpdateType.AffinityChanged
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (w.Affinity != null)
|
|
|
|
|
oldAff = w.Affinity;
|
|
|
|
|
w.Affinity = newAff;
|
|
|
|
|
sucess = true;
|
|
|
|
|
|
|
|
|
|
uow._context.WaifuUpdates.Add(new WaifuUpdate()
|
|
|
|
|
{
|
|
|
|
|
User = w.Waifu,
|
|
|
|
|
Old = oldAff,
|
|
|
|
|
New = newAff,
|
|
|
|
|
UpdateType = WaifuUpdateType.AffinityChanged
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
if (!sucess)
|
|
|
|
|
{
|
|
|
|
|
if (cooldown)
|
|
|
|
|
{
|
2017-02-19 01:11:31 +00:00
|
|
|
|
var remaining = _affinityLimit.Subtract(difference);
|
|
|
|
|
await ReplyErrorLocalized("waifu_affinity_cooldown",
|
|
|
|
|
Format.Bold(((int)remaining.TotalHours).ToString()),
|
|
|
|
|
Format.Bold(remaining.Minutes.ToString())).ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2017-02-19 01:11:31 +00:00
|
|
|
|
{
|
|
|
|
|
await ReplyErrorLocalized("waifu_affinity_already").ConfigureAwait(false);
|
|
|
|
|
}
|
2017-01-22 20:06:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (u == null)
|
2017-02-19 01:11:31 +00:00
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("waifu_affinity_reset").ConfigureAwait(false);
|
|
|
|
|
}
|
2017-01-22 20:06:10 +00:00
|
|
|
|
else if (oldAff == null)
|
2017-02-19 01:11:31 +00:00
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("waifu_affinity_set", Format.Bold(u.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
2017-01-22 20:06:10 +00:00
|
|
|
|
else
|
2017-02-19 01:11:31 +00:00
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("waifu_affinity_changed", Format.Bold(oldAff.ToString()), Format.Bold(u.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-06-14 15:28:57 +00:00
|
|
|
|
public async Task WaifuLeaderboard(int page = 1)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-06-14 15:28:57 +00:00
|
|
|
|
page--;
|
|
|
|
|
|
|
|
|
|
if (page < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-01-22 20:06:10 +00:00
|
|
|
|
IList<WaifuInfo> waifus;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-06-14 15:28:57 +00:00
|
|
|
|
waifus = uow.Waifus.GetTop(9, page * 9);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (waifus.Count == 0)
|
|
|
|
|
{
|
2017-02-22 10:40:51 +00:00
|
|
|
|
await ReplyConfirmLocalized("waifus_none").ConfigureAwait(false);
|
2017-01-22 20:06:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-02-19 01:11:31 +00:00
|
|
|
|
|
2017-01-22 20:06:10 +00:00
|
|
|
|
var embed = new EmbedBuilder()
|
2017-02-19 01:11:31 +00:00
|
|
|
|
.WithTitle(GetText("waifus_top_waifus"))
|
2017-01-22 20:06:10 +00:00
|
|
|
|
.WithOkColor();
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
for (var i = 0; i < waifus.Count; i++)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
var w = waifus[i];
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
var j = i;
|
2017-07-20 03:10:39 +00:00
|
|
|
|
embed.AddField(efb => efb.WithName("#" + ((page * 9) + j + 1) + " - " + w.Price + _bc.BotConfig.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-04-25 04:53:03 +00:00
|
|
|
|
public async Task WaifuInfo([Remainder]IGuildUser target = null)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
if (target == null)
|
2017-04-25 04:53:03 +00:00
|
|
|
|
target = (IGuildUser)Context.User;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
WaifuInfo w;
|
|
|
|
|
IList<WaifuInfo> claims;
|
2017-03-14 08:03:21 +00:00
|
|
|
|
int divorces;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
w = uow.Waifus.ByWaifuUserId(target.Id);
|
|
|
|
|
claims = uow.Waifus.ByClaimerUserId(target.Id);
|
|
|
|
|
divorces = uow._context.WaifuUpdates.Count(x => x.Old != null &&
|
|
|
|
|
x.Old.UserId == target.Id &&
|
|
|
|
|
x.UpdateType == WaifuUpdateType.Claimed &&
|
|
|
|
|
x.New == null);
|
|
|
|
|
if (w == null)
|
2017-02-05 09:06:36 +00:00
|
|
|
|
{
|
2017-01-22 20:06:10 +00:00
|
|
|
|
uow.Waifus.Add(w = new WaifuInfo()
|
|
|
|
|
{
|
|
|
|
|
Affinity = null,
|
|
|
|
|
Claimer = null,
|
|
|
|
|
Price = 1,
|
|
|
|
|
Waifu = uow.DiscordUsers.GetOrCreate(target),
|
|
|
|
|
});
|
2017-02-05 09:06:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
w.Waifu.Username = target.Username;
|
|
|
|
|
w.Waifu.Discriminator = target.Discriminator;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var claimInfo = GetClaimTitle(target.Id);
|
|
|
|
|
var affInfo = GetAffinityTitle(target.Id);
|
|
|
|
|
|
2017-02-21 02:04:22 +00:00
|
|
|
|
var rng = new NadekoRandom();
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
var nobody = GetText("nobody");
|
2017-01-22 20:06:10 +00:00
|
|
|
|
var embed = new EmbedBuilder()
|
|
|
|
|
.WithOkColor()
|
2017-02-14 23:59:10 +00:00
|
|
|
|
.WithTitle("Waifu " + w.Waifu + " - \"the " + claimInfo.Title + "\"")
|
2017-02-19 01:11:31 +00:00
|
|
|
|
.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))
|
2017-09-10 01:52:34 +00:00
|
|
|
|
.AddField(efb => efb.WithName(GetText("gifts")).WithValue(!w.Items.Any() ? "-" : string.Join("\n", w.Items.OrderBy(x => x.Price).GroupBy(x => x.ItemEmoji).Select(x => $"{x.Key} x{x.Count()}"))).WithIsInline(false))
|
2017-08-14 05:25:32 +00:00
|
|
|
|
.AddField(efb => efb.WithName($"Waifus ({claims.Count})").WithValue(claims.Count == 0 ? nobody : string.Join("\n", claims.OrderBy(x => rng.Next()).Take(30).Select(x => x.Waifu))).WithIsInline(false));
|
2017-01-22 20:06:10 +00:00
|
|
|
|
|
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-14 05:25:32 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[Priority(1)]
|
|
|
|
|
public async Task WaifuGift()
|
|
|
|
|
{
|
|
|
|
|
var embed = new EmbedBuilder()
|
|
|
|
|
.WithTitle(GetText("waifu_gift_shop"))
|
|
|
|
|
.WithOkColor();
|
|
|
|
|
|
|
|
|
|
Enum.GetValues(typeof(WaifuItem.ItemName))
|
|
|
|
|
.Cast<WaifuItem.ItemName>()
|
|
|
|
|
.Select(x => WaifuItem.GetItem(x))
|
|
|
|
|
.ForEach(x => embed.AddField(f => f.WithName(x.ItemEmoji + " " + x.Item).WithValue(x.Price).WithIsInline(true)));
|
|
|
|
|
|
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[Priority(0)]
|
|
|
|
|
public async Task WaifuGift(WaifuItem.ItemName item, [Remainder] IUser waifu)
|
|
|
|
|
{
|
2017-08-15 20:59:48 +00:00
|
|
|
|
if (waifu.Id == Context.User.Id)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-08-14 05:25:32 +00:00
|
|
|
|
var itemObj = WaifuItem.GetItem(item);
|
|
|
|
|
|
|
|
|
|
using (var uow = _db.UnitOfWork)
|
|
|
|
|
{
|
|
|
|
|
var w = uow.Waifus.ByWaifuUserId(waifu.Id);
|
|
|
|
|
|
|
|
|
|
//try to buy the item first
|
|
|
|
|
|
|
|
|
|
if (!await _cs.RemoveAsync(Context.User.Id, "Bought waifu item", itemObj.Price, uow))
|
|
|
|
|
{
|
|
|
|
|
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (w == null)
|
|
|
|
|
{
|
|
|
|
|
uow.Waifus.Add(w = new WaifuInfo()
|
|
|
|
|
{
|
|
|
|
|
Affinity = null,
|
|
|
|
|
Claimer = null,
|
|
|
|
|
Price = 1,
|
|
|
|
|
Waifu = uow.DiscordUsers.GetOrCreate(waifu),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
w.Waifu.Username = waifu.Username;
|
|
|
|
|
w.Waifu.Discriminator = waifu.Discriminator;
|
|
|
|
|
}
|
|
|
|
|
w.Items.Add(itemObj);
|
|
|
|
|
if (w.Claimer?.UserId == Context.User.Id)
|
|
|
|
|
{
|
|
|
|
|
w.Price += itemObj.Price;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
w.Price += itemObj.Price / 2;
|
|
|
|
|
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ReplyConfirmLocalized("waifu_gift", Format.Bold(item.ToString() + " " +itemObj.ItemEmoji), Format.Bold(waifu.ToString())).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-22 20:06:10 +00:00
|
|
|
|
|
|
|
|
|
public struct WaifuProfileTitle
|
|
|
|
|
{
|
|
|
|
|
public int Count { get; }
|
|
|
|
|
public string Title { get; }
|
|
|
|
|
|
|
|
|
|
public WaifuProfileTitle(int count, string title)
|
|
|
|
|
{
|
|
|
|
|
Count = count;
|
|
|
|
|
Title = title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 20:28:16 +00:00
|
|
|
|
private WaifuProfileTitle GetClaimTitle(ulong userId)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-02-19 01:11:31 +00:00
|
|
|
|
int count;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
|
|
|
|
count = uow.Waifus.ByClaimerUserId(userId).Count;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
ClaimTitles title;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
if (count == 0)
|
|
|
|
|
title = ClaimTitles.Lonely;
|
|
|
|
|
else if (count == 1)
|
|
|
|
|
title = ClaimTitles.Devoted;
|
|
|
|
|
else if (count < 4)
|
|
|
|
|
title = ClaimTitles.Rookie;
|
|
|
|
|
else if (count < 6)
|
|
|
|
|
title = ClaimTitles.Schemer;
|
|
|
|
|
else if (count < 8)
|
|
|
|
|
title = ClaimTitles.Dilettante;
|
|
|
|
|
else if (count < 10)
|
|
|
|
|
title = ClaimTitles.Intermediate;
|
|
|
|
|
else if (count < 12)
|
|
|
|
|
title = ClaimTitles.Seducer;
|
|
|
|
|
else if (count < 15)
|
|
|
|
|
title = ClaimTitles.Expert;
|
|
|
|
|
else if (count < 17)
|
|
|
|
|
title = ClaimTitles.Veteran;
|
|
|
|
|
else if (count < 25)
|
|
|
|
|
title = ClaimTitles.Incubis;
|
|
|
|
|
else if (count < 50)
|
|
|
|
|
title = ClaimTitles.Harem_King;
|
|
|
|
|
else
|
|
|
|
|
title = ClaimTitles.Harem_God;
|
|
|
|
|
|
|
|
|
|
return new WaifuProfileTitle(count, title.ToString().Replace('_', ' '));
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 20:28:16 +00:00
|
|
|
|
private WaifuProfileTitle GetAffinityTitle(ulong userId)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-02-19 01:11:31 +00:00
|
|
|
|
int count;
|
2017-05-24 20:28:16 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-01-22 20:06:10 +00:00
|
|
|
|
{
|
2017-03-14 08:03:21 +00:00
|
|
|
|
count = uow._context.WaifuUpdates
|
|
|
|
|
.Where(w => w.User.UserId == userId && w.UpdateType == WaifuUpdateType.AffinityChanged && w.New != null)
|
|
|
|
|
.GroupBy(x => x.New)
|
|
|
|
|
.Count();
|
2017-01-22 20:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 01:11:31 +00:00
|
|
|
|
AffinityTitles title;
|
2017-01-22 20:06:10 +00:00
|
|
|
|
if (count < 1)
|
|
|
|
|
title = AffinityTitles.Pure;
|
|
|
|
|
else if (count < 2)
|
|
|
|
|
title = AffinityTitles.Faithful;
|
|
|
|
|
else if (count < 4)
|
|
|
|
|
title = AffinityTitles.Defiled;
|
|
|
|
|
else if (count < 7)
|
|
|
|
|
title = AffinityTitles.Cheater;
|
|
|
|
|
else if (count < 9)
|
|
|
|
|
title = AffinityTitles.Tainted;
|
|
|
|
|
else if (count < 11)
|
|
|
|
|
title = AffinityTitles.Corrupted;
|
|
|
|
|
else if (count < 13)
|
|
|
|
|
title = AffinityTitles.Lewd;
|
|
|
|
|
else if (count < 15)
|
|
|
|
|
title = AffinityTitles.Sloot;
|
|
|
|
|
else if (count < 17)
|
|
|
|
|
title = AffinityTitles.Depraved;
|
2017-01-29 22:26:55 +00:00
|
|
|
|
else
|
2017-01-22 20:06:10 +00:00
|
|
|
|
title = AffinityTitles.Harlot;
|
|
|
|
|
|
|
|
|
|
return new WaifuProfileTitle(count, title.ToString().Replace('_', ' '));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|