From 92c98545e3b289f123d87dd1a0da0e96cc35aaea Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 9 Sep 2016 00:22:55 +0200 Subject: [PATCH] Fixed bugs with currency again --- src/NadekoBot/Modules/Gambling/Gambling.cs | 6 +++--- .../Modules/Games/Commands/PlantAndPickCommands.cs | 12 ++++++------ src/NadekoBot/NadekoBot.cs | 2 +- src/NadekoBot/Services/Database/Models/BotConfig.cs | 2 +- src/NadekoBot/Services/Impl/StatsService.cs | 5 ++++- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index fbf62369..50e89cc0 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -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; } diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index f74d3c5f..c72e91ce 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Games /// https://discord.gg/0TYNJfCU4De7YIk8 /// [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 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; } diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index df7b7721..3e698605 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -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 diff --git a/src/NadekoBot/Services/Database/Models/BotConfig.cs b/src/NadekoBot/Services/Database/Models/BotConfig.cs index 25beddb7..09fa4aa7 100644 --- a/src/NadekoBot/Services/Database/Models/BotConfig.cs +++ b/src/NadekoBot/Services/Database/Models/BotConfig.cs @@ -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 ModulePrefixes { get; set; } = new List() diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 87331161..3d33bb9f 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -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()