testing something, won't compile
This commit is contained in:
parent
9050291e85
commit
fa0b9e4f80
40
NadekoBot.Core/Modules/Gambling/Common/CurrencyRaffleGame.cs
Normal file
40
NadekoBot.Core/Modules/Gambling/Common/CurrencyRaffleGame.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using NadekoBot.Core.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Core.Modules.Gambling.Common
|
||||
{
|
||||
public class CurrencyRaffleGame
|
||||
{
|
||||
private readonly HashSet<(string, ulong)> _users = new HashSet<(string, ulong)>();
|
||||
private readonly int _amount;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DbService _db;
|
||||
private bool running;
|
||||
|
||||
public CurrencyRaffleGame(int amount, CurrencyService cs, DbService db)
|
||||
{
|
||||
if (amount < 1)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
_amount = amount;
|
||||
_cs = cs;
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<bool> AddUser(string username, ulong userId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ForceStop()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
NadekoBot.Core/Modules/Gambling/CurrencyRaffleCommands.cs
Normal file
22
NadekoBot.Core/Modules/Gambling/CurrencyRaffleCommands.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Core.Modules.Gambling.Services;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
public partial class Gambling
|
||||
{
|
||||
public class CurrencyRaffleCommands : NadekoSubmodule<CurrencyRaffleService>
|
||||
{
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task RaffleCur(int amount)
|
||||
{
|
||||
if (_service.Games.TryAdd(Context.Channel.Id,
|
||||
))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Core.Services;
|
||||
using System.Collections.Concurrent;
|
||||
using NadekoBot.Core.Modules.Gambling.Common;
|
||||
using System.Threading;
|
||||
|
||||
namespace NadekoBot.Core.Modules.Gambling.Services
|
||||
{
|
||||
public class CurrencyRaffleService : INService
|
||||
{
|
||||
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
|
||||
private readonly DbService _db;
|
||||
|
||||
public ConcurrentDictionary<ulong, CurrencyRaffleGame> Games { get; }
|
||||
|
||||
public CurrencyRaffleService(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task JoinOrCreateGame(ulong channelId, string username,
|
||||
ulong userId)
|
||||
{
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
//remove money
|
||||
if (!await _cs.RemoveAsync(userId, "Currency Raffle Join", _amount).ConfigureAwait(false))
|
||||
return false;
|
||||
}
|
||||
|
||||
//add to to list
|
||||
if (_users.Add((username, userId)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_locker.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user