Work on gambling, lolban
This commit is contained in:
parent
acebc6e914
commit
c446b889c7
@ -1,4 +1,6 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Classes;
|
||||
using NadekoBot.Extensions;
|
||||
using System;
|
||||
@ -9,154 +11,142 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
public partial class DiceRollCommands
|
||||
public partial class Gambling
|
||||
{
|
||||
private Regex dndRegex { get; } = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
|
||||
////todo drawing
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public Task Roll(IMessage imsg, [Remainder] string arg = null) =>
|
||||
// InternalRoll(imsg, arg, true);
|
||||
|
||||
public DiceRollCommand(DiscordModule module) : base(module) { }
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public Task Rolluo(IMessage imsg, [Remainder] string arg = null) =>
|
||||
// InternalRoll(imsg, arg, false);
|
||||
|
||||
//private async Task InternalRoll(IMessage imsg, string arg, bool ordered) {
|
||||
// var channel = imsg.Channel as ITextChannel;
|
||||
// var r = new Random();
|
||||
// if (string.IsNullOrWhiteSpace(arg))
|
||||
// {
|
||||
// var gen = r.Next(0, 101);
|
||||
|
||||
internal override void Init(CommandGroupBuilder cgb)
|
||||
// var num1 = gen / 10;
|
||||
// var num2 = gen % 10;
|
||||
|
||||
// var imageStream = await new Image[2] { GetDice(num1), GetDice(num2) }.Merge().ToStream(ImageFormat.Png);
|
||||
|
||||
// await channel.SendFileAsync(imageStream, "dice.png").ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
// Match m;
|
||||
// if ((m = dndRegex.Match(arg)).Length != 0)
|
||||
// {
|
||||
// int n1;
|
||||
// int n2;
|
||||
// if (int.TryParse(m.Groups["n1"].ToString(), out n1) &&
|
||||
// int.TryParse(m.Groups["n2"].ToString(), out n2) &&
|
||||
// n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
|
||||
// {
|
||||
// var arr = new int[n1];
|
||||
// for (int i = 0; i < n1; i++)
|
||||
// {
|
||||
// arr[i] = r.Next(1, n2 + 1);
|
||||
// }
|
||||
// var elemCnt = 0;
|
||||
// await channel.SendMessageAsync($"`Rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// try
|
||||
// {
|
||||
// var num = int.Parse(e.Args[0]);
|
||||
// if (num < 1) num = 1;
|
||||
// if (num > 30)
|
||||
// {
|
||||
// await channel.SendMessageAsync("You can roll up to 30 dice at a time.").ConfigureAwait(false);
|
||||
// num = 30;
|
||||
// }
|
||||
// var dices = new List<Image>(num);
|
||||
// var values = new List<int>(num);
|
||||
// for (var i = 0; i < num; i++)
|
||||
// {
|
||||
// var randomNumber = r.Next(1, 7);
|
||||
// var toInsert = dices.Count;
|
||||
// if (ordered)
|
||||
// {
|
||||
// if (randomNumber == 6 || dices.Count == 0)
|
||||
// toInsert = 0;
|
||||
// else if (randomNumber != 1)
|
||||
// for (var j = 0; j < dices.Count; j++)
|
||||
// {
|
||||
// if (values[j] < randomNumber)
|
||||
// {
|
||||
// toInsert = j;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// toInsert = dices.Count;
|
||||
// }
|
||||
// dices.Insert(toInsert, GetDice(randomNumber));
|
||||
// values.Insert(toInsert, randomNumber);
|
||||
// }
|
||||
|
||||
// var bitmap = dices.Merge();
|
||||
// await channel.SendMessageAsync(values.Count + " Dice rolled. Total: **" + values.Sum() + "** Average: **" + (values.Sum() / (1.0f * values.Count)).ToString("N2") + "**").ConfigureAwait(false);
|
||||
// await channel.SendFileAsync("dice.png", bitmap.ToStream(ImageFormat.Png)).ConfigureAwait(false);
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// await channel.SendMessageAsync("Please enter a number of dice to roll.").ConfigureAwait(false);
|
||||
// }
|
||||
//}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task NRoll(IMessage imsg, [Remainder] string range)
|
||||
{
|
||||
cgb.CreateCommand(Module.Prefix + "roll")
|
||||
.Description("Rolls 0-100. If you supply a number [x] it rolls up to 30 normal dice." +
|
||||
$" If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y. | `{Prefix}roll` or `{Prefix}roll 7` or `{Prefix}roll 3d5`")
|
||||
.Parameter("num", ParameterType.Optional)
|
||||
.Do(RollFunc());
|
||||
|
||||
cgb.CreateCommand(Module.Prefix + "rolluo")
|
||||
.Description("Rolls 0-100. If you supply a number [x] it rolls up to 30 normal dice (unordered)." +
|
||||
$" If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y. | `{Prefix}roll` or `{Prefix}roll` 7 or `{Prefix}roll 3d5`")
|
||||
.Parameter("num", ParameterType.Optional)
|
||||
.Do(RollFunc(false));
|
||||
|
||||
cgb.CreateCommand(Module.Prefix + "nroll")
|
||||
.Description($"Rolls in a given range. | `{Prefix}nroll 5` (rolls 0-5) or `{Prefix}nroll 5-15`")
|
||||
.Parameter("range", ParameterType.Required)
|
||||
.Do(NRollFunc());
|
||||
}
|
||||
|
||||
private Image GetDice(int num) => num != 10
|
||||
? Properties.Resources.ResourceManager.GetObject("_" + num) as Image
|
||||
: new[]
|
||||
{
|
||||
(Properties.Resources.ResourceManager.GetObject("_" + 1) as Image),
|
||||
(Properties.Resources.ResourceManager.GetObject("_" + 0) as Image),
|
||||
}.Merge();
|
||||
var channel = imsg.Channel as ITextChannel;
|
||||
|
||||
|
||||
Regex dndRegex = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
|
||||
private Func<CommandEventArgs, Task> RollFunc(bool ordered = true)
|
||||
{
|
||||
var r = new Random();
|
||||
return async e =>
|
||||
try
|
||||
{
|
||||
var arg = e.Args[0]?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(arg))
|
||||
int rolled;
|
||||
if (range.Contains("-"))
|
||||
{
|
||||
var gen = r.Next(0, 101);
|
||||
|
||||
var num1 = gen / 10;
|
||||
var num2 = gen % 10;
|
||||
|
||||
var imageStream = new Image[2] { GetDice(num1), GetDice(num2) }.Merge().ToStream(ImageFormat.Png);
|
||||
|
||||
await e.Channel.SendFile("dice.png", imageStream).ConfigureAwait(false);
|
||||
return;
|
||||
var arr = range.Split('-')
|
||||
.Take(2)
|
||||
.Select(int.Parse)
|
||||
.ToArray();
|
||||
if (arr[0] > arr[1])
|
||||
throw new ArgumentException("First argument should be bigger than the second one.");
|
||||
rolled = new Random().Next(arr[0], arr[1] + 1);
|
||||
}
|
||||
Match m;
|
||||
if ((m = dndRegex.Match(arg)).Length != 0)
|
||||
else
|
||||
{
|
||||
int n1;
|
||||
int n2;
|
||||
if (int.TryParse(m.Groups["n1"].ToString(), out n1) &&
|
||||
int.TryParse(m.Groups["n2"].ToString(), out n2) &&
|
||||
n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
|
||||
{
|
||||
var arr = new int[n1];
|
||||
for (int i = 0; i < n1; i++)
|
||||
{
|
||||
arr[i] = r.Next(1, n2 + 1);
|
||||
}
|
||||
var elemCnt = 0;
|
||||
await channel.SendMessageAsync($"`Rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
||||
}
|
||||
return;
|
||||
rolled = new Random().Next(0, int.Parse(range) + 1);
|
||||
}
|
||||
try
|
||||
{
|
||||
var num = int.Parse(e.Args[0]);
|
||||
if (num < 1) num = 1;
|
||||
if (num > 30)
|
||||
{
|
||||
await channel.SendMessageAsync("You can roll up to 30 dice at a time.").ConfigureAwait(false);
|
||||
num = 30;
|
||||
}
|
||||
var dices = new List<Image>(num);
|
||||
var values = new List<int>(num);
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
var randomNumber = r.Next(1, 7);
|
||||
var toInsert = dices.Count;
|
||||
if (ordered)
|
||||
{
|
||||
if (randomNumber == 6 || dices.Count == 0)
|
||||
toInsert = 0;
|
||||
else if (randomNumber != 1)
|
||||
for (var j = 0; j < dices.Count; j++)
|
||||
{
|
||||
if (values[j] < randomNumber)
|
||||
{
|
||||
toInsert = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
toInsert = dices.Count;
|
||||
}
|
||||
dices.Insert(toInsert, GetDice(randomNumber));
|
||||
values.Insert(toInsert, randomNumber);
|
||||
}
|
||||
|
||||
var bitmap = dices.Merge();
|
||||
await channel.SendMessageAsync(values.Count + " Dice rolled. Total: **" + values.Sum() + "** Average: **" + (values.Sum() / (1.0f * values.Count)).ToString("N2") + "**").ConfigureAwait(false);
|
||||
await e.Channel.SendFile("dice.png", bitmap.ToStream(ImageFormat.Png)).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await channel.SendMessageAsync("Please enter a number of dice to roll.").ConfigureAwait(false);
|
||||
}
|
||||
};
|
||||
await channel.SendMessageAsync($"{imsg.Author.Mention} rolled **{rolled}**.").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await channel.SendMessageAsync($":anger: {ex.Message}").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Func<CommandEventArgs, Task> NRollFunc() =>
|
||||
async e =>
|
||||
{
|
||||
try
|
||||
{
|
||||
int rolled;
|
||||
if (e.GetArg("range").Contains("-"))
|
||||
{
|
||||
var arr = e.GetArg("range").Split('-')
|
||||
.Take(2)
|
||||
.Select(int.Parse)
|
||||
.ToArray();
|
||||
if (arr[0] > arr[1])
|
||||
throw new ArgumentException("First argument should be bigger than the second one.");
|
||||
rolled = new Random().Next(arr[0], arr[1] + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
rolled = new Random().Next(0, int.Parse(e.GetArg("range")) + 1);
|
||||
}
|
||||
|
||||
await channel.SendMessageAsync($"{imsg.Author.Mention} rolled **{rolled}**.").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await channel.SendMessageAsync($":anger: {ex.Message}").ConfigureAwait(false);
|
||||
}
|
||||
};
|
||||
////todo drawing
|
||||
//private Image GetDice(int num) => num != 10
|
||||
// ? Properties.Resources.ResourceManager.GetObject("_" + num) as Image
|
||||
// : new[]
|
||||
// {
|
||||
// (Properties.Resources.ResourceManager.GetObject("_" + 1) as Image),
|
||||
// (Properties.Resources.ResourceManager.GetObject("_" + 0) as Image),
|
||||
// }.Merge();
|
||||
}
|
||||
}
|
@ -1,91 +1,92 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Classes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Gambling.Helpers;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
//using Discord.Commands;
|
||||
//using NadekoBot.Classes;
|
||||
//using NadekoBot.Extensions;
|
||||
//using NadekoBot.Modules.Gambling.Helpers;
|
||||
//using System;
|
||||
//using System.Collections.Concurrent;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Drawing;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
internal class DrawCommand : DiscordCommand
|
||||
{
|
||||
public DrawCommand(DiscordModule module) : base(module) { }
|
||||
////todo drawing
|
||||
//namespace NadekoBot.Modules.Gambling
|
||||
//{
|
||||
// internal class DrawCommand : DiscordCommand
|
||||
// {
|
||||
// public DrawCommand(DiscordModule module) : base(module) { }
|
||||
|
||||
internal override void Init(CommandGroupBuilder cgb)
|
||||
{
|
||||
cgb.CreateCommand(Module.Prefix + "draw")
|
||||
.Description($"Draws a card from the deck.If you supply number [x], she draws up to 5 cards from the deck. | `{Prefix}draw [x]`")
|
||||
.Parameter("count", ParameterType.Optional)
|
||||
.Do(DrawCardFunc());
|
||||
// internal override void Init(CommandGroupBuilder cgb)
|
||||
// {
|
||||
// cgb.CreateCommand(Module.Prefix + "draw")
|
||||
// .Description($"Draws a card from the deck.If you supply number [x], she draws up to 5 cards from the deck. | `{Prefix}draw [x]`")
|
||||
// .Parameter("count", ParameterType.Optional)
|
||||
// .Do(DrawCardFunc());
|
||||
|
||||
cgb.CreateCommand(Module.Prefix + "shuffle")
|
||||
.Alias(Module.Prefix + "sh")
|
||||
.Description($"Reshuffles all cards back into the deck.|`{Prefix}shuffle`")
|
||||
.Do(ReshuffleTask());
|
||||
}
|
||||
// cgb.CreateCommand(Module.Prefix + "shuffle")
|
||||
// .Alias(Module.Prefix + "sh")
|
||||
// .Description($"Reshuffles all cards back into the deck.|`{Prefix}shuffle`")
|
||||
// .Do(ReshuffleTask());
|
||||
// }
|
||||
|
||||
private static readonly ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>();
|
||||
// private static readonly ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>();
|
||||
|
||||
private static Func<CommandEventArgs, Task> ReshuffleTask()
|
||||
{
|
||||
return async e =>
|
||||
{
|
||||
AllDecks.AddOrUpdate(e.Server,
|
||||
(s) => new Cards(),
|
||||
(s, c) =>
|
||||
{
|
||||
c.Restart();
|
||||
return c;
|
||||
});
|
||||
// private static Func<CommandEventArgs, Task> ReshuffleTask()
|
||||
// {
|
||||
// return async e =>
|
||||
// {
|
||||
// AllDecks.AddOrUpdate(e.Server,
|
||||
// (s) => new Cards(),
|
||||
// (s, c) =>
|
||||
// {
|
||||
// c.Restart();
|
||||
// return c;
|
||||
// });
|
||||
|
||||
await channel.SendMessageAsync("Deck reshuffled.").ConfigureAwait(false);
|
||||
};
|
||||
}
|
||||
// await channel.SendMessageAsync("Deck reshuffled.").ConfigureAwait(false);
|
||||
// };
|
||||
// }
|
||||
|
||||
private Func<CommandEventArgs, Task> DrawCardFunc() => async (e) =>
|
||||
{
|
||||
var cards = AllDecks.GetOrAdd(e.Server, (s) => new Cards());
|
||||
// private Func<CommandEventArgs, Task> DrawCardFunc() => async (e) =>
|
||||
// {
|
||||
// var cards = AllDecks.GetOrAdd(e.Server, (s) => new Cards());
|
||||
|
||||
try
|
||||
{
|
||||
var num = 1;
|
||||
var isParsed = int.TryParse(e.GetArg("count"), out num);
|
||||
if (!isParsed || num < 2)
|
||||
{
|
||||
var c = cards.DrawACard();
|
||||
await e.Channel.SendFile(c.Name + ".jpg", (Properties.Resources.ResourceManager.GetObject(c.Name) as Image).ToStream()).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
if (num > 5)
|
||||
num = 5;
|
||||
// try
|
||||
// {
|
||||
// var num = 1;
|
||||
// var isParsed = int.TryParse(e.GetArg("count"), out num);
|
||||
// if (!isParsed || num < 2)
|
||||
// {
|
||||
// var c = cards.DrawACard();
|
||||
// await e.Channel.SendFile(c.Name + ".jpg", (Properties.Resources.ResourceManager.GetObject(c.Name) as Image).ToStream()).ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
// if (num > 5)
|
||||
// num = 5;
|
||||
|
||||
var images = new List<Image>();
|
||||
var cardObjects = new List<Cards.Card>();
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
if (cards.CardPool.Count == 0 && i != 0)
|
||||
{
|
||||
await channel.SendMessageAsync("No more cards in a deck.").ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
var currentCard = cards.DrawACard();
|
||||
cardObjects.Add(currentCard);
|
||||
images.Add(Properties.Resources.ResourceManager.GetObject(currentCard.Name) as Image);
|
||||
}
|
||||
var bitmap = images.Merge();
|
||||
await e.Channel.SendFile(images.Count + " cards.jpg", bitmap.ToStream()).ConfigureAwait(false);
|
||||
if (cardObjects.Count == 5)
|
||||
{
|
||||
await channel.SendMessageAsync($"{imsg.Author.Mention} `{Cards.GetHandValue(cardObjects)}`").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error drawing (a) card(s) " + ex.ToString());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
// var images = new List<Image>();
|
||||
// var cardObjects = new List<Cards.Card>();
|
||||
// for (var i = 0; i < num; i++)
|
||||
// {
|
||||
// if (cards.CardPool.Count == 0 && i != 0)
|
||||
// {
|
||||
// await channel.SendMessageAsync("No more cards in a deck.").ConfigureAwait(false);
|
||||
// break;
|
||||
// }
|
||||
// var currentCard = cards.DrawACard();
|
||||
// cardObjects.Add(currentCard);
|
||||
// images.Add(Properties.Resources.ResourceManager.GetObject(currentCard.Name) as Image);
|
||||
// }
|
||||
// var bitmap = images.Merge();
|
||||
// await e.Channel.SendFile(images.Count + " cards.jpg", bitmap.ToStream()).ConfigureAwait(false);
|
||||
// if (cardObjects.Count == 5)
|
||||
// {
|
||||
// await channel.SendMessageAsync($"{imsg.Author.Mention} `{Cards.GetHandValue(cardObjects)}`").ConfigureAwait(false);
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine("Error drawing (a) card(s) " + ex.ToString());
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
|
@ -1,112 +1,113 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Classes;
|
||||
using NadekoBot.Extensions;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
//using Discord.Commands;
|
||||
//using NadekoBot.Classes;
|
||||
//using NadekoBot.Extensions;
|
||||
//using System;
|
||||
//using System.Drawing;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
internal class FlipCoinCommand : DiscordCommand
|
||||
{
|
||||
////todo drawing
|
||||
//namespace NadekoBot.Modules.Gambling
|
||||
//{
|
||||
// internal class FlipCoinCommand : DiscordCommand
|
||||
// {
|
||||
|
||||
public FlipCoinCommand(DiscordModule module) : base(module) { }
|
||||
// public FlipCoinCommand(DiscordModule module) : base(module) { }
|
||||
|
||||
internal override void Init(CommandGroupBuilder cgb)
|
||||
{
|
||||
cgb.CreateCommand(Module.Prefix + "flip")
|
||||
.Description($"Flips coin(s) - heads or tails, and shows an image. | `{Prefix}flip` or `{Prefix}flip 3`")
|
||||
.Parameter("count", ParameterType.Optional)
|
||||
.Do(FlipCoinFunc());
|
||||
// internal override void Init(CommandGroupBuilder cgb)
|
||||
// {
|
||||
// cgb.CreateCommand(Module.Prefix + "flip")
|
||||
// .Description($"Flips coin(s) - heads or tails, and shows an image. | `{Prefix}flip` or `{Prefix}flip 3`")
|
||||
// .Parameter("count", ParameterType.Optional)
|
||||
// .Do(FlipCoinFunc());
|
||||
|
||||
cgb.CreateCommand(Module.Prefix + "betflip")
|
||||
.Alias(Prefix+"bf")
|
||||
.Description($"Bet to guess will the result be heads or tails. Guessing award you double flowers you've bet. | `{Prefix}bf 5 heads` or `{Prefix}bf 3 t`")
|
||||
.Parameter("amount", ParameterType.Required)
|
||||
.Parameter("guess", ParameterType.Required)
|
||||
.Do(BetFlipCoinFunc());
|
||||
}
|
||||
// cgb.CreateCommand(Module.Prefix + "betflip")
|
||||
// .Alias(Prefix+"bf")
|
||||
// .Description($"Bet to guess will the result be heads or tails. Guessing award you double flowers you've bet. | `{Prefix}bf 5 heads` or `{Prefix}bf 3 t`")
|
||||
// .Parameter("amount", ParameterType.Required)
|
||||
// .Parameter("guess", ParameterType.Required)
|
||||
// .Do(BetFlipCoinFunc());
|
||||
// }
|
||||
|
||||
|
||||
|
||||
private readonly Random rng = new Random();
|
||||
public Func<CommandEventArgs, Task> BetFlipCoinFunc() => async e =>
|
||||
{
|
||||
// private readonly Random rng = new Random();
|
||||
// public Func<CommandEventArgs, Task> BetFlipCoinFunc() => async e =>
|
||||
// {
|
||||
|
||||
var amountstr = e.GetArg("amount").Trim();
|
||||
// var amountstr = e.GetArg("amount").Trim();
|
||||
|
||||
var guessStr = e.GetArg("guess").Trim().ToUpperInvariant();
|
||||
if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
|
||||
return;
|
||||
// var guessStr = e.GetArg("guess").Trim().ToUpperInvariant();
|
||||
// if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
|
||||
// return;
|
||||
|
||||
int amount;
|
||||
if (!int.TryParse(amountstr, out amount) || amount < 1)
|
||||
return;
|
||||
// int amount;
|
||||
// if (!int.TryParse(amountstr, out amount) || amount < 1)
|
||||
// return;
|
||||
|
||||
var userFlowers = GamblingModule.GetUserFlowers(e.User.Id);
|
||||
// var userFlowers = Gambling.GetUserFlowers(imsg.Author.Id);
|
||||
|
||||
if (userFlowers < amount)
|
||||
{
|
||||
await imsg.Channel.SendMessageAsync($"{e.User.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
// if (userFlowers < amount)
|
||||
// {
|
||||
// await channel.SendMessageAsync($"{imsg.Author.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
|
||||
await FlowersHandler.RemoveFlowers(e.User, "Betflip Gamble", (int)amount, true).ConfigureAwait(false);
|
||||
//heads = true
|
||||
//tails = false
|
||||
// await FlowersHandler.RemoveFlowers(imsg.Author, "Betflip Gamble", (int)amount, true).ConfigureAwait(false);
|
||||
// //heads = true
|
||||
// //tails = false
|
||||
|
||||
var guess = guessStr == "HEADS" || guessStr == "H";
|
||||
bool result = false;
|
||||
if (rng.Next(0, 2) == 1) {
|
||||
await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
result = true;
|
||||
}
|
||||
else {
|
||||
await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
}
|
||||
// var guess = guessStr == "HEADS" || guessStr == "H";
|
||||
// bool result = false;
|
||||
// if (rng.Next(0, 2) == 1) {
|
||||
// await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
// result = true;
|
||||
// }
|
||||
// else {
|
||||
// await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
string str;
|
||||
if (guess == result)
|
||||
{
|
||||
str = $"{e.User.Mention}`You guessed it!` You won {amount * 2}{NadekoBot.Config.CurrencySign}";
|
||||
await FlowersHandler.AddFlowersAsync(e.User, "Betflip Gamble", amount * 2, true).ConfigureAwait(false);
|
||||
// string str;
|
||||
// if (guess == result)
|
||||
// {
|
||||
// str = $"{imsg.Author.Mention}`You guessed it!` You won {amount * 2}{NadekoBot.Config.CurrencySign}";
|
||||
// await FlowersHandler.AddFlowersAsync(imsg.Author, "Betflip Gamble", amount * 2, true).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
else
|
||||
str = $"{e.User.Mention}`More luck next time.`";
|
||||
// }
|
||||
// else
|
||||
// str = $"{imsg.Author.Mention}`More luck next time.`";
|
||||
|
||||
await imsg.Channel.SendMessageAsync(str).ConfigureAwait(false);
|
||||
};
|
||||
// await channel.SendMessageAsync(str).ConfigureAwait(false);
|
||||
// };
|
||||
|
||||
public Func<CommandEventArgs, Task> FlipCoinFunc() => async e =>
|
||||
{
|
||||
// public Func<CommandEventArgs, Task> FlipCoinFunc() => async e =>
|
||||
// {
|
||||
|
||||
if (e.GetArg("count") == "")
|
||||
{
|
||||
if (rng.Next(0, 2) == 1)
|
||||
await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
else
|
||||
await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
int result;
|
||||
if (int.TryParse(e.GetArg("count"), out result))
|
||||
{
|
||||
if (result > 10)
|
||||
result = 10;
|
||||
var imgs = new Image[result];
|
||||
for (var i = 0; i < result; i++)
|
||||
{
|
||||
imgs[i] = rng.Next(0, 2) == 0 ?
|
||||
Properties.Resources.tails :
|
||||
Properties.Resources.heads;
|
||||
}
|
||||
await e.Channel.SendFile($"{result} coins.png", imgs.Merge().ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
await imsg.Channel.SendMessageAsync("Invalid number").ConfigureAwait(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
// if (e.GetArg("count") == "")
|
||||
// {
|
||||
// if (rng.Next(0, 2) == 1)
|
||||
// await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
// else
|
||||
// await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// int result;
|
||||
// if (int.TryParse(e.GetArg("count"), out result))
|
||||
// {
|
||||
// if (result > 10)
|
||||
// result = 10;
|
||||
// var imgs = new Image[result];
|
||||
// for (var i = 0; i < result; i++)
|
||||
// {
|
||||
// imgs[i] = rng.Next(0, 2) == 0 ?
|
||||
// Properties.Resources.tails :
|
||||
// Properties.Resources.heads;
|
||||
// }
|
||||
// await e.Channel.SendFile($"{result} coins.png", imgs.Merge().ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
// await channel.SendMessageAsync("Invalid number").ConfigureAwait(false);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
|
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Helpers
|
||||
namespace NadekoBot.Modules.Gambling.Commands.Models
|
||||
{
|
||||
public class Cards
|
||||
{
|
@ -175,6 +175,6 @@ namespace NadekoBot.Modules.Gambling
|
||||
//$@"┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫
|
||||
//┃{(e.Server.Users.Where(u => u.Id == (ulong)cs.UserId).FirstOrDefault()?.Name.TrimTo(18, true) ?? cs.UserId.ToString()),-20} ┃ {cs.Value,5} ┃")
|
||||
// ).ToString() + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```").ConfigureAwait(false);
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Games.Commands
|
||||
var num = 1;
|
||||
msgToSend = answers.Aggregate(msgToSend, (current, answ) => current + $"`{num++}.` **{answ}**\n");
|
||||
msgToSend += "\n**Private Message me with the corresponding number of the answer.**";
|
||||
await channel.SendMessageAsync(msgToSend).ConfigureAwait(false);
|
||||
await imsg.Channel.SendMessageAsync(msgToSend).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task StopPoll(IGuildChannel ch)
|
||||
@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Games.Commands
|
||||
var totalVotesCast = results.Sum(kvp => kvp.Value);
|
||||
if (totalVotesCast == 0)
|
||||
{
|
||||
await channel.SendMessageAsync("📄 **No votes have been cast.**").ConfigureAwait(false);
|
||||
await imsg.Channel.SendMessageAsync("📄 **No votes have been cast.**").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var closeMessage = $"--------------**POLL CLOSED**--------------\n" +
|
||||
@ -100,7 +100,7 @@ namespace NadekoBot.Modules.Games.Commands
|
||||
$" has {kvp.Value} votes." +
|
||||
$"({kvp.Value * 1.0f / totalVotesCast * 100}%)\n");
|
||||
|
||||
await channel.SendMessageAsync($"📄 **Total votes cast**: {totalVotesCast}\n{closeMessage}").ConfigureAwait(false);
|
||||
await imsg.Channel.SendMessageAsync($"📄 **Total votes cast**: {totalVotesCast}\n{closeMessage}").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1,19 +1,75 @@
|
||||
//using Discord.Commands;
|
||||
//using NadekoBot.Classes;
|
||||
//using NadekoBot.Extensions;
|
||||
//using Newtonsoft.Json.Linq;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Drawing;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
////todo drawing
|
||||
//namespace NadekoBot.Modules.Searches.Commands
|
||||
//{
|
||||
// internal class LoLCommands : DiscordCommand
|
||||
// {
|
||||
//todo drawing
|
||||
namespace NadekoBot.Modules.Searches.Commands
|
||||
{
|
||||
public partial class Searches
|
||||
{
|
||||
private class ChampionNameComparer : IEqualityComparer<JToken>
|
||||
{
|
||||
public bool Equals(JToken a, JToken b) => a["name"].ToString() == b["name"].ToString();
|
||||
|
||||
public int GetHashCode(JToken obj) =>
|
||||
obj["name"].GetHashCode();
|
||||
}
|
||||
|
||||
private string[] trashTalk { get; } = { "Better ban your counters. You are going to carry the game anyway.",
|
||||
"Go with the flow. Don't think. Just ban one of these.",
|
||||
"DONT READ BELOW! Ban Urgot mid OP 100%. Im smurf Diamond 1.",
|
||||
"Ask your teammates what would they like to play, and ban that.",
|
||||
"If you consider playing teemo, do it. If you consider teemo, you deserve him.",
|
||||
"Doesn't matter what you ban really. Enemy will ban your main and you will lose." };
|
||||
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Lolban(IMessage imsg)
|
||||
{
|
||||
var channel = imsg.Channel as ITextChannel;
|
||||
|
||||
|
||||
|
||||
var showCount = 8;
|
||||
//http://api.champion.gg/stats/champs/mostBanned?api_key=YOUR_API_TOKEN&page=1&limit=2
|
||||
try
|
||||
{
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
var data = JObject.Parse(await http.GetStringAsync($"http://api.champion.gg/stats/champs/mostBanned?" +
|
||||
$"api_key={NadekoBot.Credentials.LoLApiKey}&page=1&" +
|
||||
$"limit={showCount}")
|
||||
.ConfigureAwait(false))["data"] as JArray;
|
||||
var dataList = data.Distinct(new ChampionNameComparer()).Take(showCount).ToList();
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"**Showing {showCount} top banned champions.**");
|
||||
sb.AppendLine($"`{trashTalk[new Random().Next(0, trashTalk.Length)]}`");
|
||||
for (var i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
if (i % 2 == 0 && i != 0)
|
||||
sb.AppendLine();
|
||||
sb.Append($"`{i + 1}.` **{dataList[i]["name"]}** ");
|
||||
}
|
||||
|
||||
await channel.SendMessageAsync(sb.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await channel.SendMessageAsync($":anger: Fail: Champion.gg didsabled ban data until next patch. Sorry for the inconvenience.").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private class CachedChampion
|
||||
// {
|
||||
@ -22,14 +78,7 @@
|
||||
// public string Name { get; set; }
|
||||
// }
|
||||
|
||||
// private class ChampionNameComparer : IEqualityComparer<JToken>
|
||||
// {
|
||||
// public bool Equals(JToken a, JToken b) => a["name"].ToString() == b["name"].ToString();
|
||||
|
||||
// public int GetHashCode(JToken obj) =>
|
||||
// obj["name"].GetHashCode();
|
||||
// }
|
||||
|
||||
//
|
||||
// private static Dictionary<string, CachedChampion> CachedChampionImages = new Dictionary<string, CachedChampion>();
|
||||
|
||||
// private System.Timers.Timer clearTimer { get; } = new System.Timers.Timer();
|
||||
@ -41,21 +90,14 @@
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// CachedChampionImages = CachedChampionImages
|
||||
// .Where(kvp => DateTime.Now - kvp.Value.AddedAt > new TimeSpan(1, 0, 0))
|
||||
// .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
// CachedChampionImages = CachedChampionImages
|
||||
// .Where(kvp => DateTime.Now - kvp.Value.AddedAt > new TimeSpan(1, 0, 0))
|
||||
// .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
// }
|
||||
// catch { }
|
||||
// };
|
||||
// }
|
||||
|
||||
// private readonly string[] trashTalk = { "Better ban your counters. You are going to carry the game anyway.",
|
||||
// "Go with the flow. Don't think. Just ban one of these.",
|
||||
// "DONT READ BELOW! Ban Urgot mid OP 100%. Im smurf Diamond 1.",
|
||||
// "Ask your teammates what would they like to play, and ban that.",
|
||||
// "If you consider playing teemo, do it. If you consider teemo, you deserve him.",
|
||||
// "Doesn't matter what you ban really. Enemy will ban your main and you will lose." };
|
||||
|
||||
// public Func<CommandEventArgs, Task> DoFunc()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
@ -86,7 +128,7 @@
|
||||
// var name = e.GetArg("champ").Replace(" ", "").ToLower();
|
||||
// CachedChampion champ = null;
|
||||
|
||||
// if(CachedChampionImages.TryGetValue(name + "_" + resolvedRole, out champ))
|
||||
// if (CachedChampionImages.TryGetValue(name + "_" + resolvedRole, out champ))
|
||||
// if (champ != null)
|
||||
// {
|
||||
// champ.ImageStream.Position = 0;
|
||||
@ -117,7 +159,7 @@
|
||||
// role = allData[0]["role"].ToString();
|
||||
// resolvedRole = ResolvePos(role);
|
||||
// }
|
||||
// if(CachedChampionImages.TryGetValue(name + "_" + resolvedRole, out champ))
|
||||
// if (CachedChampionImages.TryGetValue(name + "_" + resolvedRole, out champ))
|
||||
// if (champ != null)
|
||||
// {
|
||||
// champ.ImageStream.Position = 0;
|
||||
@ -279,42 +321,6 @@
|
||||
// await channel.SendMessageAsync("💢 Failed retreiving data for that champion.").ConfigureAwait(false);
|
||||
// }
|
||||
// });
|
||||
|
||||
// cgb.CreateCommand(Module.Prefix + "lolban")
|
||||
// .Description($"Shows top 6 banned champions ordered by ban rate. Ban these champions and you will be Plat 5 in no time. | `{Prefix}lolban`")
|
||||
// .Do(async e =>
|
||||
// {
|
||||
|
||||
// var showCount = 8;
|
||||
// //http://api.champion.gg/stats/champs/mostBanned?api_key=YOUR_API_TOKEN&page=1&limit=2
|
||||
// try
|
||||
// {
|
||||
// var data = JObject.Parse(
|
||||
// await Classes
|
||||
// .SearchHelper
|
||||
// .GetResponseStringAsync($"http://api.champion.gg/stats/champs/mostBanned?" +
|
||||
// $"api_key={NadekoBot.Creds.LOLAPIKey}&page=1&" +
|
||||
// $"limit={showCount}")
|
||||
// .ConfigureAwait(false))["data"] as JArray;
|
||||
// var dataList = data.Distinct(new ChampionNameComparer()).Take(showCount).ToList();
|
||||
// var sb = new StringBuilder();
|
||||
// sb.AppendLine($"**Showing {showCount} top banned champions.**");
|
||||
// sb.AppendLine($"`{trashTalk[new Random().Next(0, trashTalk.Length)]}`");
|
||||
// for (var i = 0; i < dataList.Count; i++)
|
||||
// {
|
||||
// if (i % 2 == 0 && i != 0)
|
||||
// sb.AppendLine();
|
||||
// sb.Append($"`{i + 1}.` **{dataList[i]["name"]}** ");
|
||||
// //sb.AppendLine($" ({dataList[i]["general"]["banRate"]}%)");
|
||||
// }
|
||||
|
||||
// await channel.SendMessageAsync(sb.ToString()).ConfigureAwait(false);
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// await channel.SendMessageAsync($":anger: Fail: Champion.gg didsabled ban data until next patch. Sorry for the inconvenience.").ConfigureAwait(false);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// private enum GetImageType
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Discord;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
@ -9,7 +10,8 @@ namespace NadekoBot.Services
|
||||
string Token { get; }
|
||||
string GoogleApiKey { get; }
|
||||
ulong[] OwnerIds { get; }
|
||||
|
||||
IEnumerable<string> MashapeKey { get; }
|
||||
string LoLApiKey { get; }
|
||||
|
||||
bool IsOwner(IUser u);
|
||||
}
|
||||
|
@ -20,16 +20,20 @@ namespace NadekoBot.Services.Impl
|
||||
|
||||
public ulong[] OwnerIds { get; }
|
||||
|
||||
public string LoLApiKey { get; }
|
||||
|
||||
public BotCredentials()
|
||||
{
|
||||
var cm = JsonConvert.DeserializeObject<CredentialsModel>(File.ReadAllText("./credentials.json"));
|
||||
Token = cm.Token;
|
||||
OwnerIds = cm.OwnerIds;
|
||||
LoLApiKey = cm.LoLApiKey;
|
||||
}
|
||||
|
||||
private class CredentialsModel {
|
||||
public string Token { get; set; }
|
||||
public ulong[] OwnerIds { get; set; }
|
||||
public string LoLApiKey { get; set; }
|
||||
}
|
||||
|
||||
public bool IsOwner(IUser u) => OwnerIds.Contains(u.Id);
|
||||
|
Loading…
Reference in New Issue
Block a user