Fixed bugs with currency again

This commit is contained in:
Kwoth 2016-09-09 00:22:55 +02:00
parent 814f7ca8b7
commit 92c98545e3
5 changed files with 15 additions and 12 deletions

View File

@ -75,7 +75,7 @@ namespace NadekoBot.Modules.Gambling
var success = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)umsg.Author, $"Gift to {receiver.Username} ({receiver.Id}).", amount, true).ConfigureAwait(false);
if (!success)
{
await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {Gambling.CurrencyPluralName}s.").ConfigureAwait(false);
await channel.SendMessageAsync($"{umsg.Author.Mention} You don't have enough {Gambling.CurrencyPluralName}.").ConfigureAwait(false);
return;
}
await CurrencyHandler.AddCurrencyAsync(receiver, $"Gift from {umsg.Author.Username} ({umsg.Author.Id}).", amount, true).ConfigureAwait(false);
@ -136,12 +136,12 @@ namespace NadekoBot.Modules.Gambling
long userFlowers;
using (var uow = DbHandler.UnitOfWork())
{
userFlowers = uow.Currency.GetOrCreate(umsg.Id).Amount;
userFlowers = uow.Currency.GetOrCreate(umsg.Author.Id).Amount;
}
if (userFlowers < amount)
{
await channel.SendMessageAsync($"{guildUser.Mention} You don't have enough {Gambling.CurrencyName}s. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false);
await channel.SendMessageAsync($"{guildUser.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false);
return;
}

View File

@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Games
/// https://discord.gg/0TYNJfCU4De7YIk8
/// </summary>
[Group]
public class PlantPick
public class PlantPickCommands
{
private Random rng;
@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Games
private float chance;
private int cooldown;
public PlantPick()
public PlantPickCommands()
{
NadekoBot.Client.MessageReceived += PotentialFlowerGeneration;
rng = new Random();
@ -113,14 +113,14 @@ namespace NadekoBot.Modules.Games
List<IUserMessage> msgs;
await imsg.DeleteAsync().ConfigureAwait(false);
try { await imsg.DeleteAsync().ConfigureAwait(false); } catch { }
if (!plantedFlowers.TryRemove(channel.Id, out msgs))
return;
await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);
await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked a flower.", 1, false).ConfigureAwait(false);
var msg = await channel.SendMessageAsync($"**{imsg.Author.Username}** picked a {Gambling.Gambling.CurrencyName}!").ConfigureAwait(false);
await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked flower(s).", msgs.Count, false).ConfigureAwait(false);
var msg = await channel.SendMessageAsync($"**{imsg.Author.Username}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);
var t = Task.Run(async () =>
{
try
@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Games
var removed = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)imsg.Author, "Planted a flower.", 1, false).ConfigureAwait(false);
if (!removed)
{
await channel.SendMessageAsync($"You don't have any {Gambling.Gambling.CurrencyName}s.").ConfigureAwait(false);
await channel.SendMessageAsync($"You don't have any {Gambling.Gambling.CurrencyPluralName}.").ConfigureAwait(false);
return;
}

View File

@ -44,8 +44,8 @@ namespace NadekoBot
Commands = new CommandService();
Localizer = new Localization();
Google = new GoogleApiService();
Stats = new StatsService(Client);
CommandHandler = new CommandHandler(Client, Commands);
Stats = new StatsService(Client, CommandHandler);
_log = LogManager.GetCurrentClassLogger();
//setup DI

View File

@ -15,7 +15,7 @@ namespace NadekoBot.Services.Database.Models
public bool ForwardMessages { get; set; } = true;
public bool ForwardToAllOwners { get; set; } = true;
public float CurrencyGenerationChance { get; set; } = 0.1f;
public float CurrencyGenerationChance { get; set; } = 0.02f;
public int CurrencyGenerationCooldown { get; set; } = 10;
public List<ModulePrefix> ModulePrefixes { get; set; } = new List<ModulePrefix>()

View File

@ -15,19 +15,21 @@ namespace NadekoBot.Services.Impl
private int messageCounter;
private DiscordSocketClient client;
private DateTime started;
private int commandsRan = 0;
public string BotVersion => "1.0-alpha";
public string Heap => Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString();
public StatsService(DiscordSocketClient client)
public StatsService(DiscordSocketClient client, CommandHandler cmdHandler)
{
this.client = client;
Reset();
this.client.MessageReceived += _ => Task.FromResult(messageCounter++);
cmdHandler.CommandExecuted += (_, e) => commandsRan++;
this.client.Disconnected += _ => Reset();
}
@ -37,6 +39,7 @@ namespace NadekoBot.Services.Impl
`Owners' Ids: {string.Join(", ", NadekoBot.Credentials.OwnerIds)}`
`Uptime: {GetUptimeString()}`
`Servers: {client.GetGuilds().Count} | TextChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is ITextChannel)).Count()} | VoiceChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is IVoiceChannel)).Count()}`
`Commands Ran this session: {commandsRan}`
`Messages: {messageCounter} ({messageCounter / (double)GetUptime().TotalSeconds:F2}/sec)` `Heap: {Heap} MB`");
public Task Reset()