Fixed bugs with currency again
This commit is contained in:
parent
814f7ca8b7
commit
92c98545e3
@ -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);
|
var success = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)umsg.Author, $"Gift to {receiver.Username} ({receiver.Id}).", amount, true).ConfigureAwait(false);
|
||||||
if (!success)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
await CurrencyHandler.AddCurrencyAsync(receiver, $"Gift from {umsg.Author.Username} ({umsg.Author.Id}).", amount, true).ConfigureAwait(false);
|
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;
|
long userFlowers;
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
userFlowers = uow.Currency.GetOrCreate(umsg.Id).Amount;
|
userFlowers = uow.Currency.GetOrCreate(umsg.Author.Id).Amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userFlowers < 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
/// https://discord.gg/0TYNJfCU4De7YIk8
|
/// https://discord.gg/0TYNJfCU4De7YIk8
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Group]
|
[Group]
|
||||||
public class PlantPick
|
public class PlantPickCommands
|
||||||
{
|
{
|
||||||
|
|
||||||
private Random rng;
|
private Random rng;
|
||||||
@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
private float chance;
|
private float chance;
|
||||||
private int cooldown;
|
private int cooldown;
|
||||||
|
|
||||||
public PlantPick()
|
public PlantPickCommands()
|
||||||
{
|
{
|
||||||
NadekoBot.Client.MessageReceived += PotentialFlowerGeneration;
|
NadekoBot.Client.MessageReceived += PotentialFlowerGeneration;
|
||||||
rng = new Random();
|
rng = new Random();
|
||||||
@ -113,14 +113,14 @@ namespace NadekoBot.Modules.Games
|
|||||||
|
|
||||||
List<IUserMessage> msgs;
|
List<IUserMessage> msgs;
|
||||||
|
|
||||||
await imsg.DeleteAsync().ConfigureAwait(false);
|
try { await imsg.DeleteAsync().ConfigureAwait(false); } catch { }
|
||||||
if (!plantedFlowers.TryRemove(channel.Id, out msgs))
|
if (!plantedFlowers.TryRemove(channel.Id, out msgs))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);
|
await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);
|
||||||
|
|
||||||
await CurrencyHandler.AddCurrencyAsync((IGuildUser)imsg.Author, "Picked a flower.", 1, false).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 a {Gambling.Gambling.CurrencyName}!").ConfigureAwait(false);
|
var msg = await channel.SendMessageAsync($"**{imsg.Author.Username}** picked {msgs.Count}{Gambling.Gambling.CurrencySign}!").ConfigureAwait(false);
|
||||||
var t = Task.Run(async () =>
|
var t = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
var removed = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)imsg.Author, "Planted a flower.", 1, false).ConfigureAwait(false);
|
var removed = await CurrencyHandler.RemoveCurrencyAsync((IGuildUser)imsg.Author, "Planted a flower.", 1, false).ConfigureAwait(false);
|
||||||
if (!removed)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ namespace NadekoBot
|
|||||||
Commands = new CommandService();
|
Commands = new CommandService();
|
||||||
Localizer = new Localization();
|
Localizer = new Localization();
|
||||||
Google = new GoogleApiService();
|
Google = new GoogleApiService();
|
||||||
Stats = new StatsService(Client);
|
|
||||||
CommandHandler = new CommandHandler(Client, Commands);
|
CommandHandler = new CommandHandler(Client, Commands);
|
||||||
|
Stats = new StatsService(Client, CommandHandler);
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
//setup DI
|
//setup DI
|
||||||
|
@ -15,7 +15,7 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public bool ForwardMessages { get; set; } = true;
|
public bool ForwardMessages { get; set; } = true;
|
||||||
public bool ForwardToAllOwners { 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 int CurrencyGenerationCooldown { get; set; } = 10;
|
||||||
|
|
||||||
public List<ModulePrefix> ModulePrefixes { get; set; } = new List<ModulePrefix>()
|
public List<ModulePrefix> ModulePrefixes { get; set; } = new List<ModulePrefix>()
|
||||||
|
@ -15,19 +15,21 @@ namespace NadekoBot.Services.Impl
|
|||||||
private int messageCounter;
|
private int messageCounter;
|
||||||
private DiscordSocketClient client;
|
private DiscordSocketClient client;
|
||||||
private DateTime started;
|
private DateTime started;
|
||||||
|
private int commandsRan = 0;
|
||||||
|
|
||||||
public string BotVersion => "1.0-alpha";
|
public string BotVersion => "1.0-alpha";
|
||||||
|
|
||||||
public string Heap => Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString();
|
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;
|
this.client = client;
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
this.client.MessageReceived += _ => Task.FromResult(messageCounter++);
|
this.client.MessageReceived += _ => Task.FromResult(messageCounter++);
|
||||||
|
cmdHandler.CommandExecuted += (_, e) => commandsRan++;
|
||||||
|
|
||||||
this.client.Disconnected += _ => Reset();
|
this.client.Disconnected += _ => Reset();
|
||||||
}
|
}
|
||||||
@ -37,6 +39,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
`Owners' Ids: {string.Join(", ", NadekoBot.Credentials.OwnerIds)}`
|
`Owners' Ids: {string.Join(", ", NadekoBot.Credentials.OwnerIds)}`
|
||||||
`Uptime: {GetUptimeString()}`
|
`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()}`
|
`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`");
|
`Messages: {messageCounter} ({messageCounter / (double)GetUptime().TotalSeconds:F2}/sec)` `Heap: {Heap} MB`");
|
||||||
|
|
||||||
public Task Reset()
|
public Task Reset()
|
||||||
|
Loading…
Reference in New Issue
Block a user