2017-11-01 13:01:42 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using NadekoBot.Core.Services;
|
2017-10-15 07:39:46 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
2017-11-01 13:01:42 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-10-15 07:39:46 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Gambling.Services
|
|
|
|
|
{
|
|
|
|
|
public class WaifuService : INService
|
|
|
|
|
{
|
2017-11-01 13:01:42 +00:00
|
|
|
|
private readonly DbService _db;
|
2017-11-02 17:22:17 +00:00
|
|
|
|
private readonly CurrencyService _cs;
|
2017-11-01 13:01:42 +00:00
|
|
|
|
|
2017-10-15 07:39:46 +00:00
|
|
|
|
public ConcurrentDictionary<ulong, DateTime> DivorceCooldowns { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
|
|
|
|
public ConcurrentDictionary<ulong, DateTime> AffinityCooldowns { get; } = new ConcurrentDictionary<ulong, DateTime>();
|
2017-10-17 05:03:56 +00:00
|
|
|
|
|
2017-11-02 17:22:17 +00:00
|
|
|
|
public WaifuService(DbService db, CurrencyService cs)
|
2017-11-01 13:01:42 +00:00
|
|
|
|
{
|
|
|
|
|
_db = db;
|
2017-11-02 17:22:17 +00:00
|
|
|
|
_cs = cs;
|
2017-11-01 13:01:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> WaifuTransfer(IUser owner, ulong waifuId, IUser newOwner)
|
|
|
|
|
{
|
2017-11-03 06:27:09 +00:00
|
|
|
|
if (owner.Id == newOwner.Id || waifuId == newOwner.Id)
|
|
|
|
|
return false;
|
2017-11-01 13:01:42 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
|
|
|
|
{
|
|
|
|
|
var waifu = uow.Waifus.ByWaifuUserId(waifuId);
|
|
|
|
|
var ownerUser = uow.DiscordUsers.GetOrCreate(owner);
|
|
|
|
|
|
|
|
|
|
// owner has to be the owner of the waifu
|
2017-11-03 06:27:09 +00:00
|
|
|
|
if (waifu == null || waifu.ClaimerId != ownerUser.Id)
|
2017-11-01 13:01:42 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-11-02 17:22:17 +00:00
|
|
|
|
if (!await _cs.RemoveAsync(owner.Id,
|
|
|
|
|
"Waifu Transfer",
|
|
|
|
|
waifu.Price / 10,
|
|
|
|
|
uow).ConfigureAwait(false))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 13:01:42 +00:00
|
|
|
|
//new claimerId is the id of the new owner
|
|
|
|
|
var newOwnerUser = uow.DiscordUsers.GetOrCreate(newOwner);
|
|
|
|
|
waifu.ClaimerId = newOwnerUser.Id;
|
|
|
|
|
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
2017-11-02 17:22:17 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2017-11-01 13:01:42 +00:00
|
|
|
|
}
|
2017-10-15 07:39:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|