.wheel command added (wheel of fortune gambling)

This commit is contained in:
Master Kwoth 2017-08-02 22:07:19 +02:00
parent 82aac891dd
commit e0be610ec0
5 changed files with 141 additions and 2 deletions

View File

@ -112,11 +112,14 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)] [RequireUserPermission(GuildPermission.Administrator)]
public async Task AntiSpam(int messageCount = 3, PunishmentAction action = PunishmentAction.Mute) public async Task AntiSpam(int messageCount = 3, PunishmentAction action = PunishmentAction.Mute, int time = 0)
{ {
if (messageCount < 2 || messageCount > 10) if (messageCount < 2 || messageCount > 10)
return; return;
if (time < 0 || time > 60 * 12)
return;
if (_service.AntiSpamGuilds.TryRemove(Context.Guild.Id, out var removed)) if (_service.AntiSpamGuilds.TryRemove(Context.Guild.Id, out var removed))
{ {
removed.UserStats.ForEach(x => x.Value.Dispose()); removed.UserStats.ForEach(x => x.Value.Dispose());

View File

@ -0,0 +1,45 @@
using NadekoBot.Common;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Gambling.Common.WheelOfFortune
{
public class WheelOfFortune
{
private static readonly NadekoRandom _rng = new NadekoRandom();
private static readonly ImmutableArray<string> _emojis = new string[] {
"⬆",
"↖",
"⬅",
"↙",
"⬇",
"↘",
"➡",
"↗" }.ToImmutableArray();
public static readonly ImmutableArray<float> Multipliers = new float[] {
1.7f,
1.5f,
0.2f,
0.1f,
0.3f,
0.5f,
1.2f,
2.4f,
}.ToImmutableArray();
public int Result { get; }
public string Emoji => _emojis[Result];
public float Multiplier => Multipliers[Result];
public WheelOfFortune()
{
this.Result = _rng.Next(0, 8);
}
}
}

View File

@ -0,0 +1,81 @@
using Discord;
using Discord.Commands;
using NadekoBot.Common.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Modules.Gambling.Common.WheelOfFortune;
using NadekoBot.Services;
using System.Threading.Tasks;
using Wof = NadekoBot.Modules.Gambling.Common.WheelOfFortune.WheelOfFortune;
namespace NadekoBot.Modules.Gambling
{
public partial class Gambling
{
public class WheelOfFortuneCommands : NadekoSubmodule
{
private readonly CurrencyService _cs;
private readonly IBotConfigProvider _bc;
public WheelOfFortuneCommands(CurrencyService cs, IBotConfigProvider bc)
{
_cs = cs;
_bc = bc;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task WheelOfFortune(int bet)
{
const int minBet = 10;
if (bet < minBet)
{
await ReplyErrorLocalized("min_bet_limit", minBet + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
return;
}
if (!await _cs.RemoveAsync(Context.User.Id, "Wheel Of Fortune - bet", bet).ConfigureAwait(false))
{
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
return;
}
var wof = new WheelOfFortune();
var amount = (int)(bet * wof.Multiplier);
if (amount > 0)
await _cs.AddAsync(Context.User.Id, "Wheel Of Fortune - won", amount).ConfigureAwait(false);
await Context.Channel.SendConfirmAsync(
Format.Bold($@"{Context.User.ToString()} won: {amount + _bc.BotConfig.CurrencySign}
{Wof.Multipliers[1]} {Wof.Multipliers[0]} {Wof.Multipliers[7]}
{Wof.Multipliers[2]} {wof.Emoji} {Wof.Multipliers[6]}
{Wof.Multipliers[3]} {Wof.Multipliers[4]} {Wof.Multipliers[5]}")).ConfigureAwait(false);
}
//[NadekoCommand, Usage, Description, Aliases]
//[RequireContext(ContextType.Guild)]
//public async Task WofTest(int length = 1000)
//{
// var mults = new Dictionary<float, int>();
// for (int i = 0; i < length; i++)
// {
// var x = new Wof();
// if (mults.ContainsKey(x.Multiplier))
// ++mults[x.Multiplier];
// else
// mults.Add(x.Multiplier, 1);
// }
// var payout = mults.Sum(x => x.Key * x.Value);
// await Context.Channel.SendMessageAsync($"Total bet: {length}\n" +
// $"Paid out: {payout}\n" +
// $"Total Payout: {payout / length:F3}x")
// .ConfigureAwait(false);
//}
}
}
}

View File

@ -96,6 +96,7 @@ namespace NadekoBot.Modules.Utility.Services
using (var uow = _db.UnitOfWork) using (var uow = _db.UnitOfWork)
{ {
if(toRemove.Any())
uow.ConverterUnits.RemoveRange(toRemove.ToArray()); uow.ConverterUnits.RemoveRange(toRemove.ToArray());
uow.ConverterUnits.Add(baseType); uow.ConverterUnits.Add(baseType);
uow.ConverterUnits.AddRange(range); uow.ConverterUnits.AddRange(range);

View File

@ -1314,6 +1314,15 @@
<data name="betroll_usage" xml:space="preserve"> <data name="betroll_usage" xml:space="preserve">
<value>`{0}br 5`</value> <value>`{0}br 5`</value>
</data> </data>
<data name="wheeloffortune_cmd" xml:space="preserve">
<value>wheeloffortune wheel</value>
</data>
<data name="wheeloffortune_desc" xml:space="preserve">
<value>Bets a certain amount of currency on the wheel of fortune. Wheel can stop on one of many different multipliers. Won amount is rounded down to the nearest whole number.</value>
</data>
<data name="wheeloffortune_usage" xml:space="preserve">
<value>`{0}wheel 5`</value>
</data>
<data name="leaderboard_cmd" xml:space="preserve"> <data name="leaderboard_cmd" xml:space="preserve">
<value>leaderboard lb</value> <value>leaderboard lb</value>
</data> </data>