gambling fixed

This commit is contained in:
Master Kwoth 2017-05-24 22:28:16 +02:00
parent c183e8ad58
commit 9e3dc6d5a1
13 changed files with 229 additions and 145 deletions

View File

@ -12,9 +12,8 @@ namespace NadekoBot.Attributes
public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo executingCommand, IServiceProvider services)
{
var creds = (IBotCredentials)services.GetService(typeof(IBotCredentials));
var client = (IDiscordClient)services.GetService(typeof(IDiscordClient));
return Task.FromResult((creds.IsOwner(context.User) || client.CurrentUser.Id == context.User.Id ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner")));
return Task.FromResult((creds.IsOwner(context.User) || context.Client.CurrentUser.Id == context.User.Id ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner")));
}
}
}

View File

@ -4,6 +4,7 @@ using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NLog;
using System;
using System.Collections.Concurrent;
@ -19,13 +20,26 @@ namespace NadekoBot.Modules.Gambling
[Group]
public class AnimalRacing : NadekoSubmodule
{
private readonly BotConfig _bc;
private readonly CurrencyHandler _ch;
private readonly DiscordShardedClient _client;
public static ConcurrentDictionary<ulong, AnimalRace> AnimalRaces { get; } = new ConcurrentDictionary<ulong, AnimalRace>();
public AnimalRacing(BotConfig bc, CurrencyHandler ch, DiscordShardedClient client)
{
_bc = bc;
_ch = ch;
_client = client;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Race()
{
var ar = new AnimalRace(Context.Guild.Id, (ITextChannel)Context.Channel, Prefix);
var ar = new AnimalRace(Context.Guild.Id, (ITextChannel)Context.Channel, Prefix,
_bc, _ch, _client,_localization, _strings);
if (ar.Fail)
await ReplyErrorLocalized("race_failed_starting").ConfigureAwait(false);
@ -49,6 +63,8 @@ namespace NadekoBot.Modules.Gambling
await ar.JoinRace(Context.User as IGuildUser, amount);
}
//todo needs to be completely isolated, shouldn't use any services in the constructor,
//then move the rest either to the module itself, or the service
public class AnimalRace
{
@ -64,21 +80,35 @@ namespace NadekoBot.Modules.Gambling
private readonly Logger _log;
private readonly ITextChannel _raceChannel;
private readonly BotConfig _bc;
private readonly CurrencyHandler _ch;
private readonly DiscordShardedClient _client;
private readonly ILocalization _localization;
private readonly NadekoStrings _strings;
public bool Started { get; private set; }
public AnimalRace(ulong serverId, ITextChannel ch, string prefix)
public AnimalRace(ulong serverId, ITextChannel channel, string prefix, BotConfig bc,
CurrencyHandler ch, DiscordShardedClient client, ILocalization localization,
NadekoStrings strings)
{
_prefix = prefix;
_bc = bc;
_ch = ch;
_log = LogManager.GetCurrentClassLogger();
_serverId = serverId;
_raceChannel = ch;
_raceChannel = channel;
_client = client;
_localization = localization;
_strings = strings;
if (!AnimalRaces.TryAdd(serverId, this))
{
Fail = true;
return;
}
animals = new ConcurrentQueue<string>(NadekoBot.BotConfig.RaceAnimals.Select(ra => ra.Icon).Shuffle());
animals = new ConcurrentQueue<string>(_bc.RaceAnimals.Select(ra => ra.Icon).Shuffle());
var cancelSource = new CancellationTokenSource();
@ -114,7 +144,7 @@ namespace NadekoBot.Modules.Gambling
var p = _participants.FirstOrDefault();
if (p != null && p.AmountBet > 0)
await CurrencyHandler.AddCurrencyAsync(p.User, "BetRace", p.AmountBet, false).ConfigureAwait(false);
await _ch.AddCurrencyAsync(p.User, "BetRace", p.AmountBet, false).ConfigureAwait(false);
End();
return;
}
@ -139,7 +169,7 @@ namespace NadekoBot.Modules.Gambling
var place = 1;
try
{
NadekoBot.Client.MessageReceived += Client_MessageReceived;
_client.MessageReceived += Client_MessageReceived;
while (!_participants.All(p => p.Total >= 60))
{
@ -193,7 +223,7 @@ namespace NadekoBot.Modules.Gambling
}
finally
{
NadekoBot.Client.MessageReceived -= Client_MessageReceived;
_client.MessageReceived -= Client_MessageReceived;
}
if (winner != null)
@ -202,11 +232,11 @@ namespace NadekoBot.Modules.Gambling
{
var wonAmount = winner.AmountBet * (_participants.Count - 1);
await CurrencyHandler.AddCurrencyAsync(winner.User, "Won a Race", wonAmount, true)
await _ch.AddCurrencyAsync(winner.User, "Won a Race", wonAmount, true)
.ConfigureAwait(false);
await _raceChannel.SendConfirmAsync(GetText("animal_race"),
Format.Bold(GetText("animal_race_won_money", winner.User.Mention,
winner.Animal, wonAmount + CurrencySign)))
winner.Animal, wonAmount + _bc.CurrencySign)))
.ConfigureAwait(false);
}
else
@ -223,7 +253,7 @@ namespace NadekoBot.Modules.Gambling
var msg = imsg as SocketUserMessage;
if (msg == null)
return Task.CompletedTask;
if (msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != _raceChannel)
if ((msg.Author.Id == _client.CurrentUser.Id) || !(imsg.Channel is ITextChannel) || imsg.Channel != _raceChannel)
return Task.CompletedTask;
_messagesSinceGameStarted++;
return Task.CompletedTask;
@ -257,28 +287,28 @@ namespace NadekoBot.Modules.Gambling
return;
}
if (amount > 0)
if (!await CurrencyHandler.RemoveCurrencyAsync(u, "BetRace", amount, false).ConfigureAwait(false))
if (!await _ch.RemoveCurrencyAsync(u, "BetRace", amount, false).ConfigureAwait(false))
{
await _raceChannel.SendErrorAsync(GetText("not_enough", CurrencySign)).ConfigureAwait(false);
await _raceChannel.SendErrorAsync(GetText("not_enough", _bc.CurrencySign)).ConfigureAwait(false);
return;
}
_participants.Add(p);
string confStr;
if (amount > 0)
confStr = GetText("animal_race_join_bet", u.Mention, p.Animal, amount + CurrencySign);
confStr = GetText("animal_race_join_bet", u.Mention, p.Animal, amount + _bc.CurrencySign);
else
confStr = GetText("animal_race_join", u.Mention, p.Animal);
await _raceChannel.SendConfirmAsync(GetText("animal_race"), Format.Bold(confStr)).ConfigureAwait(false);
}
private string GetText(string text)
=> NadekoTopLevelModule.GetTextStatic(text,
NadekoBot.Localization.GetCultureInfo(_raceChannel.Guild),
=> _strings.GetText(text,
_localization.GetCultureInfo(_raceChannel.Guild),
typeof(Gambling).Name.ToLowerInvariant());
private string GetText(string text, params object[] replacements)
=> NadekoTopLevelModule.GetTextStatic(text,
NadekoBot.Localization.GetCultureInfo(_raceChannel.Guild),
=> _strings.GetText(text,
_localization.GetCultureInfo(_raceChannel.Guild),
typeof(Gambling).Name.ToLowerInvariant(),
replacements);
}

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Discord.WebSocket;
using System.Threading;
using NLog;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Gambling
{
@ -26,14 +27,23 @@ namespace NadekoBot.Modules.Gambling
//flower reaction event
private static readonly ConcurrentHashSet<ulong> _sneakyGameAwardedUsers = new ConcurrentHashSet<ulong>();
private static readonly char[] _sneakyGameStatusChars = Enumerable.Range(48, 10)
.Concat(Enumerable.Range(65, 26))
.Concat(Enumerable.Range(97, 26))
.Select(x => (char)x)
.ToArray();
private static string _secretCode = string.Empty;
private string _secretCode = string.Empty;
private readonly DiscordShardedClient _client;
private readonly BotConfig _bc;
private readonly CurrencyHandler _ch;
public CurrencyEvents(DiscordShardedClient client, BotConfig bc, CurrencyHandler ch)
{
_client = client;
_bc = bc;
_ch = ch;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
@ -68,12 +78,12 @@ namespace NadekoBot.Modules.Gambling
_secretCode += _sneakyGameStatusChars[rng.Next(0, _sneakyGameStatusChars.Length)];
}
await NadekoBot.Client.SetGameAsync($"type {_secretCode} for " + NadekoBot.BotConfig.CurrencyPluralName)
await _client.SetGameAsync($"type {_secretCode} for " + _bc.CurrencyPluralName)
.ConfigureAwait(false);
try
{
var title = GetText("sneakygamestatus_title");
var desc = GetText("sneakygamestatus_desc", Format.Bold(100.ToString()) + CurrencySign, Format.Bold(num.ToString()));
var desc = GetText("sneakygamestatus_desc", Format.Bold(100.ToString()) + _bc.CurrencySign, Format.Bold(num.ToString()));
await context.Channel.SendConfirmAsync(title, desc).ConfigureAwait(false);
}
catch
@ -82,26 +92,26 @@ namespace NadekoBot.Modules.Gambling
}
NadekoBot.Client.MessageReceived += SneakyGameMessageReceivedEventHandler;
_client.MessageReceived += SneakyGameMessageReceivedEventHandler;
await Task.Delay(num * 1000);
NadekoBot.Client.MessageReceived -= SneakyGameMessageReceivedEventHandler;
_client.MessageReceived -= SneakyGameMessageReceivedEventHandler;
var cnt = _sneakyGameAwardedUsers.Count;
_sneakyGameAwardedUsers.Clear();
_secretCode = string.Empty;
await NadekoBot.Client.SetGameAsync(GetText("sneakygamestatus_end", cnt))
await _client.SetGameAsync(GetText("sneakygamestatus_end", cnt))
.ConfigureAwait(false);
}
private static Task SneakyGameMessageReceivedEventHandler(SocketMessage arg)
private Task SneakyGameMessageReceivedEventHandler(SocketMessage arg)
{
if (arg.Content == _secretCode &&
_sneakyGameAwardedUsers.Add(arg.Author.Id))
{
var _ = Task.Run(async () =>
{
await CurrencyHandler.AddCurrencyAsync(arg.Author, "Sneaky Game Event", 100, false)
await _ch.AddCurrencyAsync(arg.Author, "Sneaky Game Event", 100, false)
.ConfigureAwait(false);
try { await arg.DeleteAsync(new RequestOptions() { RetryMode = RetryMode.AlwaysFail }).ConfigureAwait(false); }
@ -121,13 +131,13 @@ namespace NadekoBot.Modules.Gambling
amount = 100;
var title = GetText("flowerreaction_title");
var desc = GetText("flowerreaction_desc", "🌸", Format.Bold(amount.ToString()) + CurrencySign);
var desc = GetText("flowerreaction_desc", "🌸", Format.Bold(amount.ToString()) + _bc.CurrencySign);
var footer = GetText("flowerreaction_footer", 24);
var msg = await context.Channel.SendConfirmAsync(title,
desc, footer: footer)
.ConfigureAwait(false);
await new FlowerReactionEvent().Start(msg, context, amount);
await new FlowerReactionEvent(_client, _ch).Start(msg, context, amount);
}
}
}
@ -141,15 +151,19 @@ namespace NadekoBot.Modules.Gambling
{
private readonly ConcurrentHashSet<ulong> _flowerReactionAwardedUsers = new ConcurrentHashSet<ulong>();
private readonly Logger _log;
private readonly DiscordShardedClient _client;
private readonly CurrencyHandler _ch;
private IUserMessage StartingMessage { get; set; }
private CancellationTokenSource Source { get; }
private CancellationToken CancelToken { get; }
public FlowerReactionEvent()
public FlowerReactionEvent(DiscordShardedClient client, CurrencyHandler ch)
{
_log = LogManager.GetCurrentClassLogger();
_client = client;
_ch = ch;
Source = new CancellationTokenSource();
CancelToken = Source.Token;
}
@ -162,7 +176,7 @@ namespace NadekoBot.Modules.Gambling
if(!Source.IsCancellationRequested)
Source.Cancel();
NadekoBot.Client.MessageDeleted -= MessageDeletedEventHandler;
_client.MessageDeleted -= MessageDeletedEventHandler;
}
private Task MessageDeletedEventHandler(Cacheable<IMessage, ulong> msg, ISocketMessageChannel channel) {
@ -178,25 +192,25 @@ namespace NadekoBot.Modules.Gambling
public override async Task Start(IUserMessage umsg, ICommandContext context, int amount)
{
StartingMessage = umsg;
NadekoBot.Client.MessageDeleted += MessageDeletedEventHandler;
_client.MessageDeleted += MessageDeletedEventHandler;
try { await StartingMessage.AddReactionAsync("🌸").ConfigureAwait(false); }
try { await StartingMessage.AddReactionAsync(Emote.Parse("🌸")).ConfigureAwait(false); }
catch
{
try { await StartingMessage.AddReactionAsync("🌸").ConfigureAwait(false); }
try { await StartingMessage.AddReactionAsync(Emote.Parse("🌸")).ConfigureAwait(false); }
catch
{
try { await StartingMessage.DeleteAsync().ConfigureAwait(false); }
catch { return; }
}
}
using (StartingMessage.OnReaction(async (r) =>
using (StartingMessage.OnReaction(_client, async (r) =>
{
try
{
if (r.Emoji.Name == "🌸" && r.User.IsSpecified && ((DateTime.UtcNow - r.User.Value.CreatedAt).TotalDays > 5) && _flowerReactionAwardedUsers.Add(r.User.Value.Id))
if (r.Emote.Name == "🌸" && r.User.IsSpecified && ((DateTime.UtcNow - r.User.Value.CreatedAt).TotalDays > 5) && _flowerReactionAwardedUsers.Add(r.User.Value.Id))
{
await CurrencyHandler.AddCurrencyAsync(r.User.Value, "Flower Reaction Event", amount, false)
await _ch.AddCurrencyAsync(r.User.Value, "Flower Reaction Event", amount, false)
.ConfigureAwait(false);
}
}

View File

@ -22,6 +22,13 @@ namespace NadekoBot.Modules.Gambling
private Regex fudgeRegex { get; } = new Regex(@"^(?<n1>\d+)d(?:F|f)$", RegexOptions.Compiled);
private readonly char[] _fateRolls = { '-', ' ', '+' };
private readonly IImagesService _images;
public DriceRollCommands(IImagesService images)
{
_images = images;
}
[NadekoCommand, Usage, Description, Aliases]
public async Task Roll()
@ -212,7 +219,7 @@ namespace NadekoBot.Modules.Gambling
if (num == 10)
{
var images = NadekoBot.Images.Dice;
var images = _images.Dice;
using (var imgOneStream = images[1].Value.ToStream())
using (var imgZeroStream = images[0].Value.ToStream())
{
@ -222,7 +229,7 @@ namespace NadekoBot.Modules.Gambling
return new[] { imgOne, imgZero }.Merge();
}
}
using (var die = NadekoBot.Images.Dice[num].Value.ToStream())
using (var die = _images.Dice[num].Value.ToStream())
{
return new Image(die);
}

View File

@ -18,7 +18,6 @@ namespace NadekoBot.Modules.Gambling
public class DrawCommands : NadekoSubmodule
{
private static readonly ConcurrentDictionary<IGuild, Cards> _allDecks = new ConcurrentDictionary<IGuild, Cards>();
private const string _cardsPath = "data/images/cards";
[NadekoCommand, Usage, Description, Aliases]

View File

@ -3,6 +3,7 @@ using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -16,13 +17,16 @@ namespace NadekoBot.Modules.Gambling
public class FlipCoinCommands : NadekoSubmodule
{
private readonly IImagesService _images;
private readonly BotConfig _bc;
private readonly CurrencyHandler _ch;
private static NadekoRandom rng { get; } = new NadekoRandom();
private readonly NadekoRandom rng = new NadekoRandom();
public FlipCoinCommands()
public FlipCoinCommands(IImagesService images, CurrencyHandler ch, BotConfig bc)
{
//todo DI in the future, can't atm
_images = NadekoBot.Images;
_images = images;
_bc = bc;
_ch = ch;
}
[NadekoCommand, Usage, Description, Aliases]
@ -77,15 +81,15 @@ namespace NadekoBot.Modules.Gambling
if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
return;
if (amount < NadekoBot.BotConfig.MinimumBetAmount)
if (amount < _bc.MinimumBetAmount)
{
await ReplyErrorLocalized("min_bet_limit", NadekoBot.BotConfig.MinimumBetAmount + CurrencySign).ConfigureAwait(false);
await ReplyErrorLocalized("min_bet_limit", _bc.MinimumBetAmount + _bc.CurrencySign).ConfigureAwait(false);
return;
}
var removed = await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);
var removed = await _ch.RemoveCurrencyAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);
if (!removed)
{
await ReplyErrorLocalized("not_enough", CurrencyPluralName).ConfigureAwait(false);
await ReplyErrorLocalized("not_enough", _bc.CurrencyPluralName).ConfigureAwait(false);
return;
}
//heads = true
@ -108,9 +112,9 @@ namespace NadekoBot.Modules.Gambling
string str;
if (isHeads == result)
{
var toWin = (int)Math.Round(amount * NadekoBot.BotConfig.BetflipMultiplier);
str = Context.User.Mention + " " + GetText("flip_guess", toWin + CurrencySign);
await CurrencyHandler.AddCurrencyAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false);
var toWin = (int)Math.Round(amount * _bc.BetflipMultiplier);
str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.CurrencySign);
await _ch.AddCurrencyAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false);
}
else
{

View File

@ -1,5 +1,6 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Attributes;
using NadekoBot.DataStructures;
@ -19,6 +20,11 @@ namespace NadekoBot.Modules.Gambling
[Group]
public class FlowerShop : NadekoSubmodule
{
private readonly BotConfig _bc;
private readonly DbHandler _db;
private readonly CurrencyHandler _ch;
private readonly DiscordShardedClient _client;
public enum Role
{
Role
@ -29,6 +35,14 @@ namespace NadekoBot.Modules.Gambling
List
}
public FlowerShop(BotConfig bc, DbHandler db, CurrencyHandler ch, DiscordShardedClient client)
{
_db = db;
_bc = bc;
_ch = ch;
_client = client;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Shop(int page = 1)
@ -37,14 +51,14 @@ namespace NadekoBot.Modules.Gambling
return;
page -= 1;
List<ShopEntry> entries;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
entries = new IndexedCollection<ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries);
}
await Context.Channel.SendPaginatedConfirmAsync(page + 1, (curPage) =>
await Context.Channel.SendPaginatedConfirmAsync(_client, page + 1, (curPage) =>
{
var theseEntries = entries.Skip((curPage - 1) * 9).Take(9);
@ -52,12 +66,12 @@ namespace NadekoBot.Modules.Gambling
return new EmbedBuilder().WithErrorColor()
.WithDescription(GetText("shop_none"));
var embed = new EmbedBuilder().WithOkColor()
.WithTitle(GetText("shop", CurrencySign));
.WithTitle(GetText("shop", _bc.CurrencySign));
for (int i = 0; i < entries.Count; i++)
{
var entry = entries[i];
embed.AddField(efb => efb.WithName($"#{i + 1} - {entry.Price}{CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
embed.AddField(efb => efb.WithName($"#{i + 1} - {entry.Price}{_bc.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
}
return embed;
}, entries.Count / 9, true);
@ -71,7 +85,7 @@ namespace NadekoBot.Modules.Gambling
if (index < 0)
return;
ShopEntry entry;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set
.Include(x => x.ShopEntries)
@ -98,7 +112,7 @@ namespace NadekoBot.Modules.Gambling
return;
}
if (await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
if (await _ch.RemoveCurrencyAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
{
try
{
@ -107,17 +121,17 @@ namespace NadekoBot.Modules.Gambling
catch (Exception ex)
{
_log.Warn(ex);
await CurrencyHandler.AddCurrencyAsync(Context.User.Id, $"Shop error refund", entry.Price);
await _ch.AddCurrencyAsync(Context.User.Id, $"Shop error refund", entry.Price);
await ReplyErrorLocalized("shop_role_purchase_error").ConfigureAwait(false);
return;
}
await CurrencyHandler.AddCurrencyAsync(entry.AuthorId, $"Shop sell item - {entry.Type}", GetProfitAmount(entry.Price));
await _ch.AddCurrencyAsync(entry.AuthorId, $"Shop sell item - {entry.Type}", GetProfitAmount(entry.Price));
await ReplyConfirmLocalized("shop_role_purchase", Format.Bold(role.Name)).ConfigureAwait(false);
return;
}
else
{
await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
return;
}
}
@ -131,10 +145,10 @@ namespace NadekoBot.Modules.Gambling
var item = entry.Items.ToArray()[new NadekoRandom().Next(0, entry.Items.Count)];
if (await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
if (await _ch.RemoveCurrencyAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
{
int removed;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
var x = uow._context.Set<ShopEntryItem>().Remove(item);
@ -150,18 +164,18 @@ namespace NadekoBot.Modules.Gambling
.AddField(efb => efb.WithName(GetText("name")).WithValue(entry.Name).WithIsInline(true)))
.ConfigureAwait(false);
await CurrencyHandler.AddCurrencyAsync(entry.AuthorId,
await _ch.AddCurrencyAsync(entry.AuthorId,
$"Shop sell item - {entry.Name}",
GetProfitAmount(entry.Price)).ConfigureAwait(false);
}
catch
{
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
uow._context.Set<ShopEntryItem>().Add(item);
uow.Complete();
await CurrencyHandler.AddCurrencyAsync(Context.User.Id,
await _ch.AddCurrencyAsync(Context.User.Id,
$"Shop error refund - {entry.Name}",
entry.Price,
uow).ConfigureAwait(false);
@ -173,7 +187,7 @@ namespace NadekoBot.Modules.Gambling
}
else
{
await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
return;
}
}
@ -198,7 +212,7 @@ namespace NadekoBot.Modules.Gambling
RoleId = role.Id,
RoleName = role.Name
};
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
set => set.Include(x => x.ShopEntries)
@ -226,7 +240,7 @@ namespace NadekoBot.Modules.Gambling
AuthorId = Context.User.Id,
Items = new HashSet<ShopEntryItem>(),
};
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
set => set.Include(x => x.ShopEntries)
@ -256,7 +270,7 @@ namespace NadekoBot.Modules.Gambling
ShopEntry entry;
bool rightType = false;
bool added = false;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigs.For(Context.Guild.Id,
set => set.Include(x => x.ShopEntries)
@ -289,7 +303,7 @@ namespace NadekoBot.Modules.Gambling
if (index < 0)
return;
ShopEntry removed;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
var config = uow.GuildConfigs.For(Context.Guild.Id, set => set
.Include(x => x.ShopEntries)

View File

@ -4,6 +4,7 @@ using ImageSharp;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -21,6 +22,9 @@ namespace NadekoBot.Modules.Gambling
private static int _totalBet;
private static int _totalPaidOut;
private static readonly HashSet<ulong> _runningUsers = new HashSet<ulong>();
private readonly BotConfig _bc;
private const int _alphaCutOut = byte.MaxValue / 3;
//here is a payout chart
@ -28,10 +32,13 @@ namespace NadekoBot.Modules.Gambling
//thanks to judge for helping me with this
private readonly IImagesService _images;
private readonly CurrencyHandler _ch;
public Slots()
public Slots(IImagesService images, BotConfig bc, CurrencyHandler ch)
{
_images = NadekoBot.Images;
_images = images;
_bc = bc;
_ch = ch;
}
public class SlotMachine
@ -130,8 +137,6 @@ namespace NadekoBot.Modules.Gambling
footer: $"Total Bet: {tests * bet} | Payout: {payout * bet} | {payout * 1.0f / tests * 100}%");
}
private static readonly HashSet<ulong> _runningUsers = new HashSet<ulong>();
[NadekoCommand, Usage, Description, Aliases]
public async Task Slot(int amount = 0)
{
@ -141,24 +146,24 @@ namespace NadekoBot.Modules.Gambling
{
if (amount < 1)
{
await ReplyErrorLocalized("min_bet_limit", 1 + CurrencySign).ConfigureAwait(false);
await ReplyErrorLocalized("min_bet_limit", 1 + _bc.CurrencySign).ConfigureAwait(false);
return;
}
const int maxAmount = 9999;
if (amount > maxAmount)
{
GetText("slot_maxbet", maxAmount + CurrencySign);
await ReplyErrorLocalized("max_bet_limit", maxAmount + CurrencySign).ConfigureAwait(false);
GetText("slot_maxbet", maxAmount + _bc.CurrencySign);
await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.CurrencySign).ConfigureAwait(false);
return;
}
if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Slot Machine", amount, false))
if (!await _ch.RemoveCurrencyAsync(Context.User, "Slot Machine", amount, false))
{
await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
return;
}
Interlocked.Add(ref _totalBet, amount);
using (var bgFileStream = NadekoBot.Images.SlotBackground.ToStream())
using (var bgFileStream = _images.SlotBackground.ToStream())
{
var bgImage = new ImageSharp.Image(bgFileStream);
@ -180,7 +185,7 @@ namespace NadekoBot.Modules.Gambling
do
{
var digit = printWon % 10;
using (var fs = NadekoBot.Images.SlotNumbers[digit].ToStream())
using (var fs = _images.SlotNumbers[digit].ToStream())
using (var img = new ImageSharp.Image(fs))
{
bgImage.DrawImage(img, 100, default(Size), new Point(230 - n * 16, 462));
@ -204,19 +209,19 @@ namespace NadekoBot.Modules.Gambling
var msg = GetText("better_luck");
if (result.Multiplier != 0)
{
await CurrencyHandler.AddCurrencyAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount * result.Multiplier, false);
await _ch.AddCurrencyAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount * result.Multiplier, false);
Interlocked.Add(ref _totalPaidOut, amount * result.Multiplier);
if (result.Multiplier == 1)
msg = GetText("slot_single", CurrencySign, 1);
msg = GetText("slot_single", _bc.CurrencySign, 1);
else if (result.Multiplier == 4)
msg = GetText("slot_two", CurrencySign, 4);
msg = GetText("slot_two", _bc.CurrencySign, 4);
else if (result.Multiplier == 10)
msg = GetText("slot_three", 10);
else if (result.Multiplier == 30)
msg = GetText("slot_jackpot", 30);
}
await Context.Channel.SendFileAsync(bgImage.ToStream(), "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("slot_won")}:` {amount * result.Multiplier}{NadekoBot.BotConfig.CurrencySign}").ConfigureAwait(false);
await Context.Channel.SendFileAsync(bgImage.ToStream(), "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("slot_won")}:` {amount * result.Multiplier}{_bc.CurrencySign}").ConfigureAwait(false);
}
}
finally

View File

@ -57,13 +57,20 @@ namespace NadekoBot.Modules.Gambling
InsufficientAmount
}
public WaifuClaimCommands(BotConfig bc, CurrencyHandler ch, DbHandler db)
{
_bc = bc;
_ch = ch;
_db = db;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task WaifuClaim(int amount, [Remainder]IUser target)
{
if (amount < 50)
{
await ReplyErrorLocalized("waifu_isnt_cheap", 50 + CurrencySign).ConfigureAwait(false);
await ReplyErrorLocalized("waifu_isnt_cheap", 50 + _bc.CurrencySign).ConfigureAwait(false);
return;
}
@ -76,7 +83,7 @@ namespace NadekoBot.Modules.Gambling
WaifuClaimResult result;
WaifuInfo w;
bool isAffinity;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
w = uow.Waifus.ByWaifuUserId(target.Id);
isAffinity = (w?.Affinity?.UserId == Context.User.Id);
@ -84,7 +91,7 @@ namespace NadekoBot.Modules.Gambling
{
var claimer = uow.DiscordUsers.GetOrCreate(Context.User);
var waifu = uow.DiscordUsers.GetOrCreate(target);
if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
if (!await _ch.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
{
result = WaifuClaimResult.NotEnoughFunds;
}
@ -109,7 +116,7 @@ namespace NadekoBot.Modules.Gambling
}
else if (isAffinity && amount > w.Price * 0.88f)
{
if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
if (!await _ch.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
{
result = WaifuClaimResult.NotEnoughFunds;
}
@ -131,7 +138,7 @@ namespace NadekoBot.Modules.Gambling
}
else if (amount >= w.Price * 1.1f) // if no affinity
{
if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
if (!await _ch.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
{
result = WaifuClaimResult.NotEnoughFunds;
}
@ -165,14 +172,14 @@ namespace NadekoBot.Modules.Gambling
}
if (result == WaifuClaimResult.NotEnoughFunds)
{
await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
return;
}
var msg = GetText("waifu_claimed",
Format.Bold(target.ToString()),
amount + CurrencySign);
amount + _bc.CurrencySign);
if (w.Affinity?.UserId == Context.User.Id)
msg += "\n" + GetText("waifu_fulfilled", target, w.Price + CurrencySign);
msg += "\n" + GetText("waifu_fulfilled", target, w.Price + _bc.CurrencySign);
else
msg = " " + msg;
await Context.Channel.SendConfirmAsync(Context.User.Mention + msg).ConfigureAwait(false);
@ -205,7 +212,7 @@ namespace NadekoBot.Modules.Gambling
var difference = TimeSpan.Zero;
var amount = 0;
WaifuInfo w = null;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
w = uow.Waifus.ByWaifuUserId(targetId);
var now = DateTime.UtcNow;
@ -223,13 +230,13 @@ namespace NadekoBot.Modules.Gambling
if (w.Affinity?.UserId == Context.User.Id)
{
await CurrencyHandler.AddCurrencyAsync(w.Waifu.UserId, "Waifu Compensation", amount, uow).ConfigureAwait(false);
await _ch.AddCurrencyAsync(w.Waifu.UserId, "Waifu Compensation", amount, uow).ConfigureAwait(false);
w.Price = (int)Math.Floor(w.Price * 0.75f);
result = DivorceResult.SucessWithPenalty;
}
else
{
await CurrencyHandler.AddCurrencyAsync(Context.User.Id, "Waifu Refund", amount, uow).ConfigureAwait(false);
await _ch.AddCurrencyAsync(Context.User.Id, "Waifu Refund", amount, uow).ConfigureAwait(false);
result = DivorceResult.Success;
}
@ -250,11 +257,11 @@ namespace NadekoBot.Modules.Gambling
if (result == DivorceResult.SucessWithPenalty)
{
await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + CurrencySign).ConfigureAwait(false);
await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + _bc.CurrencySign).ConfigureAwait(false);
}
else if (result == DivorceResult.Success)
{
await ReplyConfirmLocalized("waifu_divorced_notlike", amount + CurrencySign).ConfigureAwait(false);
await ReplyConfirmLocalized("waifu_divorced_notlike", amount + _bc.CurrencySign).ConfigureAwait(false);
}
else if (result == DivorceResult.NotYourWife)
{
@ -270,6 +277,10 @@ namespace NadekoBot.Modules.Gambling
}
private static readonly TimeSpan _affinityLimit = TimeSpan.FromMinutes(30);
private readonly BotConfig _bc;
private readonly CurrencyHandler _ch;
private readonly DbHandler _db;
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task WaifuClaimerAffinity([Remainder]IGuildUser u = null)
@ -283,7 +294,7 @@ namespace NadekoBot.Modules.Gambling
var sucess = false;
var cooldown = false;
var difference = TimeSpan.Zero;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
var w = uow.Waifus.ByWaifuUserId(Context.User.Id);
var newAff = u == null ? null : uow.DiscordUsers.GetOrCreate(u);
@ -369,7 +380,7 @@ namespace NadekoBot.Modules.Gambling
public async Task WaifuLeaderboard()
{
IList<WaifuInfo> waifus;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
waifus = uow.Waifus.GetTop(9);
}
@ -389,7 +400,7 @@ namespace NadekoBot.Modules.Gambling
var w = waifus[i];
var j = i;
embed.AddField(efb => efb.WithName("#" + (j + 1) + " - " + w.Price + NadekoBot.BotConfig.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
embed.AddField(efb => efb.WithName("#" + (j + 1) + " - " + w.Price + _bc.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
}
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
@ -404,7 +415,7 @@ namespace NadekoBot.Modules.Gambling
WaifuInfo w;
IList<WaifuInfo> claims;
int divorces;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
w = uow.Waifus.ByWaifuUserId(target.Id);
claims = uow.Waifus.ByClaimerUserId(target.Id);
@ -460,10 +471,10 @@ namespace NadekoBot.Modules.Gambling
}
}
private static WaifuProfileTitle GetClaimTitle(ulong userId)
private WaifuProfileTitle GetClaimTitle(ulong userId)
{
int count;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
count = uow.Waifus.ByClaimerUserId(userId).Count;
}
@ -497,10 +508,10 @@ namespace NadekoBot.Modules.Gambling
return new WaifuProfileTitle(count, title.ToString().Replace('_', ' '));
}
private static WaifuProfileTitle GetAffinityTitle(ulong userId)
private WaifuProfileTitle GetAffinityTitle(ulong userId)
{
int count;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
count = uow._context.WaifuUpdates
.Where(w => w.User.UserId == userId && w.UpdateType == WaifuUpdateType.AffinityChanged && w.New != null)

View File

@ -11,23 +11,26 @@ using System.Collections.Generic;
namespace NadekoBot.Modules.Gambling
{
[NadekoModule("Gambling", "$")]
public partial class Gambling : NadekoTopLevelModule
{
public static string CurrencyName { get; set; }
public static string CurrencyPluralName { get; set; }
public static string CurrencySign { get; set; }
private readonly BotConfig _bc;
private readonly DbHandler _db;
private readonly CurrencyHandler _currency;
static Gambling()
private string CurrencyName => _bc.CurrencyName;
private string CurrencyPluralName => _bc.CurrencyPluralName;
private string CurrencySign => _bc.CurrencySign;
public Gambling(BotConfig bc, DbHandler db, CurrencyHandler currency)
{
CurrencyName = NadekoBot.BotConfig.CurrencyName;
CurrencyPluralName = NadekoBot.BotConfig.CurrencyPluralName;
CurrencySign = NadekoBot.BotConfig.CurrencySign;
_bc = bc;
_db = db;
_currency = currency;
}
public static long GetCurrency(ulong id)
public long GetCurrency(ulong id)
{
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
return uow.Currency.GetUserCurrency(id);
}
@ -69,13 +72,13 @@ namespace NadekoBot.Modules.Gambling
{
if (amount <= 0 || Context.User.Id == receiver.Id)
return;
var success = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)Context.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, false).ConfigureAwait(false);
var success = await _currency.RemoveCurrencyAsync((IGuildUser)Context.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, false).ConfigureAwait(false);
if (!success)
{
await ReplyErrorLocalized("not_enough", CurrencyPluralName).ConfigureAwait(false);
return;
}
await CurrencyHandler.AddCurrencyAsync(receiver, $"Gift from {Context.User.Username} ({Context.User.Id}).", amount, true).ConfigureAwait(false);
await _currency.AddCurrencyAsync(receiver, $"Gift from {Context.User.Username} ({Context.User.Id}).", amount, true).ConfigureAwait(false);
await ReplyConfirmLocalized("gifted", amount + CurrencySign, Format.Bold(receiver.ToString()))
.ConfigureAwait(false);
}
@ -95,7 +98,7 @@ namespace NadekoBot.Modules.Gambling
if (amount <= 0)
return;
await CurrencyHandler.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false);
await _currency.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false);
await ReplyConfirmLocalized("awarded", amount + CurrencySign, $"<@{usrId}>").ConfigureAwait(false);
}
@ -108,7 +111,7 @@ namespace NadekoBot.Modules.Gambling
var users = (await Context.Guild.GetUsersAsync())
.Where(u => u.GetRoles().Contains(role))
.ToList();
await Task.WhenAll(users.Select(u => CurrencyHandler.AddCurrencyAsync(u.Id,
await Task.WhenAll(users.Select(u => _currency.AddCurrencyAsync(u.Id,
$"Awarded by bot owner to **{role.Name}** role. ({Context.User.Username}/{Context.User.Id})",
amount)))
.ConfigureAwait(false);
@ -127,7 +130,7 @@ namespace NadekoBot.Modules.Gambling
if (amount <= 0)
return;
if (await CurrencyHandler.RemoveCurrencyAsync(user, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount, true).ConfigureAwait(false))
if (await _currency.RemoveCurrencyAsync(user, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount, true).ConfigureAwait(false))
await ReplyConfirmLocalized("take", amount+CurrencySign, Format.Bold(user.ToString())).ConfigureAwait(false);
else
await ReplyErrorLocalized("take_fail", amount + CurrencySign, Format.Bold(user.ToString()), CurrencyPluralName).ConfigureAwait(false);
@ -141,7 +144,7 @@ namespace NadekoBot.Modules.Gambling
if (amount <= 0)
return;
if (await CurrencyHandler.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false))
if (await _currency.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false))
await ReplyConfirmLocalized("take", amount + CurrencySign, $"<@{usrId}>").ConfigureAwait(false);
else
await ReplyErrorLocalized("take_fail", amount + CurrencySign, Format.Code(usrId.ToString()), CurrencyPluralName).ConfigureAwait(false);
@ -208,7 +211,7 @@ namespace NadekoBot.Modules.Gambling
if (amount < 1)
return;
if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User, "Betroll Gamble", amount, false).ConfigureAwait(false))
if (!await _currency.RemoveCurrencyAsync(Context.User, "Betroll Gamble", amount, false).ConfigureAwait(false))
{
await ReplyErrorLocalized("not_enough", CurrencyPluralName).ConfigureAwait(false);
return;
@ -224,21 +227,21 @@ namespace NadekoBot.Modules.Gambling
{
if (rnd < 91)
{
str += GetText("br_win", (amount * NadekoBot.BotConfig.Betroll67Multiplier) + CurrencySign, 66);
await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble",
(int) (amount * NadekoBot.BotConfig.Betroll67Multiplier), false).ConfigureAwait(false);
str += GetText("br_win", (amount * _bc.Betroll67Multiplier) + CurrencySign, 66);
await _currency.AddCurrencyAsync(Context.User, "Betroll Gamble",
(int) (amount * _bc.Betroll67Multiplier), false).ConfigureAwait(false);
}
else if (rnd < 100)
{
str += GetText("br_win", (amount * NadekoBot.BotConfig.Betroll91Multiplier) + CurrencySign, 90);
await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble",
(int) (amount * NadekoBot.BotConfig.Betroll91Multiplier), false).ConfigureAwait(false);
str += GetText("br_win", (amount * _bc.Betroll91Multiplier) + CurrencySign, 90);
await _currency.AddCurrencyAsync(Context.User, "Betroll Gamble",
(int) (amount * _bc.Betroll91Multiplier), false).ConfigureAwait(false);
}
else
{
str += GetText("br_win", (amount * NadekoBot.BotConfig.Betroll100Multiplier) + CurrencySign, 100) + " 👑";
await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble",
(int) (amount * NadekoBot.BotConfig.Betroll100Multiplier), false).ConfigureAwait(false);
str += GetText("br_win", (amount * _bc.Betroll100Multiplier) + CurrencySign, 100) + " 👑";
await _currency.AddCurrencyAsync(Context.User, "Betroll Gamble",
(int) (amount * _bc.Betroll100Multiplier), false).ConfigureAwait(false);
}
}
await Context.Channel.SendConfirmAsync(str).ConfigureAwait(false);
@ -251,14 +254,14 @@ namespace NadekoBot.Modules.Gambling
return;
List<Currency> richest;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
richest = uow.Currency.GetTopRichest(9, 9 * (page - 1)).ToList();
}
var embed = new EmbedBuilder()
.WithOkColor()
.WithTitle(NadekoBot.BotConfig.CurrencySign +
.WithTitle(CurrencySign +
" " + GetText("leaderboard"))
.WithFooter(efb => efb.WithText(GetText("page", page)));
@ -279,7 +282,7 @@ namespace NadekoBot.Modules.Gambling
var j = i;
embed.AddField(efb => efb.WithName("#" + (9 * (page - 1) + j + 1) + " " + usrStr)
.WithValue(x.Amount.ToString() + " " + NadekoBot.BotConfig.CurrencySign)
.WithValue(x.Amount.ToString() + " " + CurrencySign)
.WithIsInline(true));
}

View File

@ -30,25 +30,27 @@
<Compile Remove="data\**\*;credentials.json;credentials_example.json" />
<Compile Remove="Modules\Administration\**" />
<Compile Remove="Modules\CustomReactions\**" />
<Compile Remove="Modules\Gambling\**" />
<Compile Remove="Modules\Games\**" />
<Compile Remove="Modules\NSFW\**" />
<Compile Remove="Modules\Permissions\**" />
<Compile Remove="Modules\Searches\**" />
<Compile Remove="Services\CustomReactions\**" />
<EmbeddedResource Remove="Modules\Administration\**" />
<EmbeddedResource Remove="Modules\CustomReactions\**" />
<EmbeddedResource Remove="Modules\Gambling\**" />
<EmbeddedResource Remove="Modules\Games\**" />
<EmbeddedResource Remove="Modules\NSFW\**" />
<EmbeddedResource Remove="Modules\Permissions\**" />
<EmbeddedResource Remove="Modules\Searches\**" />
<EmbeddedResource Remove="Services\CustomReactions\**" />
<None Remove="Modules\Administration\**" />
<None Remove="Modules\CustomReactions\**" />
<None Remove="Modules\Gambling\**" />
<None Remove="Modules\Games\**" />
<None Remove="Modules\NSFW\**" />
<None Remove="Modules\Permissions\**" />
<None Remove="Modules\Searches\**" />
<None Remove="Services\CustomReactions\**" />
<Compile Remove="Modules\Gambling\Commands\Lucky7Commands.cs" />
<Compile Remove="Modules\Gambling\Commands\WaifuClaimCommands.cs" />
<None Update="libsodium.dll;opus.dll;libsodium.so;libopus.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

View File

@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Discord;
using NLog;
using Discord.Commands;
using Discord.Net;
using NadekoBot.Extensions;
using System.Collections.Concurrent;
using System.Threading;
@ -469,7 +468,7 @@ namespace NadekoBot.Services
var commands = searchResult.Commands;
for (int i = commands.Count - 1; i >= 0; i--)
{
var preconditionResult = await commands[i].CheckPreconditionsAsync(context).ConfigureAwait(false);
var preconditionResult = await commands[i].CheckPreconditionsAsync(context, serviceProvider).ConfigureAwait(false);
if (!preconditionResult.IsSuccess)
{
if (commands.Count == 1)

View File

@ -4,8 +4,6 @@ using System.Linq;
using System.Threading.Tasks;
using Discord;
using NadekoBot.Extensions;
using NadekoBot.Modules;
using NadekoBot.Services.Impl;
using NadekoBot.Services.Database.Models;
using System.Text.RegularExpressions;
using NLog;
@ -22,7 +20,6 @@ namespace NadekoBot.Services.Music
private readonly IGoogleApiService _google;
private readonly NadekoStrings _strings;
private readonly ILocalization _localization;
private GoogleApiService google;
private readonly DbHandler _db;
private readonly Logger _log;
private readonly SoundCloudApiService _sc;