Moved some changes and fixes over from b2 branch

This commit is contained in:
Kwoth 2016-12-22 06:12:04 +01:00
parent 0b1d47fc4e
commit 22c8278673
11 changed files with 93 additions and 142 deletions

View File

@ -46,54 +46,52 @@ namespace NadekoBot.Modules.Gambling
await channel.SendFileAsync(imageStream, "dice.png", $"{umsg.Author.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false);
}
//todo merge into internallDndRoll and internalRoll
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(1)]
public async Task Roll(IUserMessage umsg, string arg)
{
var channel = (ITextChannel)umsg.Channel;
if (channel == null)
return;
var ordered = true;
var rng = new NadekoRandom();
Match match;
if ((match = dndRegex.Match(arg)).Length != 0)
public enum RollOrderType
{
int n1;
int n2;
if (int.TryParse(match.Groups["n1"].ToString(), out n1) &&
int.TryParse(match.Groups["n2"].ToString(), out n2) &&
n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
{
var add = 0;
var sub = 0;
int.TryParse(match.Groups["add"].Value, out add);
int.TryParse(match.Groups["sub"].Value, out sub);
var arr = new int[n1];
for (int i = 0; i < n1; i++)
{
arr[i] = rng.Next(1, n2 + 1) + add - sub;
}
var elemCnt = 0;
await channel.SendConfirmAsync($"{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
}
}
Ordered,
Unordered
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(0)]
public async Task Roll(IUserMessage umsg, int num)
{
await InternalRoll(umsg, num, true).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(0)]
public async Task Rolluo(IUserMessage umsg, int num)
{
await InternalRoll(umsg, num, false).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(1)]
public async Task Roll(IUserMessage umsg, string arg)
{
await InternallDndRoll(umsg, arg, true).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(1)]
public async Task Rolluo(IUserMessage umsg, string arg)
{
await InternallDndRoll(umsg, arg, false).ConfigureAwait(false);
}
private async Task InternalRoll(IUserMessage umsg, int num, bool ordered)
{
var channel = (ITextChannel)umsg.Channel;
if (channel == null)
return;
var ordered = true;
if (num < 1 || num > 30)
{
await channel.SendErrorAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);
@ -137,15 +135,12 @@ namespace NadekoBot.Modules.Gambling
await channel.SendFileAsync(ms, "dice.png", $"{umsg.Author.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Rolluo(IUserMessage umsg, string arg)
private async Task InternallDndRoll(IUserMessage umsg, string arg, bool ordered)
{
var channel = (ITextChannel)umsg.Channel;
if (channel == null)
return;
var ordered = false;
var rng = new NadekoRandom();
Match match;
if ((match = dndRegex.Match(arg)).Length != 0)
@ -172,59 +167,6 @@ namespace NadekoBot.Modules.Gambling
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Rolluo(IUserMessage umsg, int num)
{
var channel = (ITextChannel)umsg.Channel;
if (channel == null)
return;
var ordered = false;
if (num < 1 || num > 30)
{
await channel.SendErrorAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);
return;
}
var rng = new NadekoRandom();
var dice = new List<Image>(num);
var values = new List<int>(num);
for (var i = 0; i < num; i++)
{
var randomNumber = rng.Next(1, 7);
var toInsert = dice.Count;
if (ordered)
{
if (randomNumber == 6 || dice.Count == 0)
toInsert = 0;
else if (randomNumber != 1)
for (var j = 0; j < dice.Count; j++)
{
if (values[j] < randomNumber)
{
toInsert = j;
break;
}
}
}
else
{
toInsert = dice.Count;
}
dice.Insert(toInsert, GetDice(randomNumber));
values.Insert(toInsert, randomNumber);
}
var bitmap = dice.Merge();
var ms = new MemoryStream();
bitmap.SaveAsPng(ms);
ms.Position = 0;
await channel.SendFileAsync(ms, "dice.png", $"{umsg.Author.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task NRoll(IUserMessage umsg, [Remainder] string range)
@ -241,7 +183,7 @@ namespace NadekoBot.Modules.Gambling
.Select(int.Parse)
.ToArray();
if (arr[0] > arr[1])
throw new ArgumentException("First argument should be bigger than the second one.");
throw new ArgumentException("Second argument must be larger than the first one.");
rolled = new NadekoRandom().Next(arr[0], arr[1] + 1);
}
else

View File

@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Gambling
MemoryStream bitmapStream = new MemoryStream();
images.Merge().SaveAsPng(bitmapStream);
bitmapStream.Position = 0;
//todo CARD NAMES?
var toSend = $"{msg.Author.Mention}";
if (cardObjects.Count == 5)
toSend += $" drew `{Cards.GetHandValue(cardObjects)}`";

View File

@ -63,20 +63,11 @@ namespace NadekoBot.Modules.Gambling
.ConfigureAwait(false);
return;
}
// todo update this
long userFlowers;
using (var uow = DbHandler.UnitOfWork())
var removed = await CurrencyHandler.RemoveCurrencyAsync(guildUser, "Betflip Gamble", amount, false).ConfigureAwait(false);
if (!removed)
{
userFlowers = uow.Currency.GetOrCreate(umsg.Author.Id).Amount;
await channel.SendErrorAsync($"{guildUser.Mention} You don't have enough {Gambling.CurrencyPluralName}.").ConfigureAwait(false);
}
if (userFlowers < amount)
{
await channel.SendErrorAsync($"{umsg.Author.Mention} You don't have enough {Gambling.CurrencyPluralName}. You only have {userFlowers}{Gambling.CurrencySign}.").ConfigureAwait(false);
return;
}
await CurrencyHandler.RemoveCurrencyAsync(guildUser, "Betflip Gamble", amount, false).ConfigureAwait(false);
//heads = true
//tails = false

View File

@ -144,9 +144,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
return Task.CompletedTask;
var guess = char.ToUpperInvariant(msg.Content[0]);
// todo hmmmm
// how do i want to limit the users on guessing?
// one guess every 5 seconds if wrong?
Task.Run(async () =>
{
try

View File

@ -17,8 +17,6 @@ using System.Threading.Tasks;
namespace NadekoBot.Modules.Games
{
//todo make currency generation change and cooldown modifyable
//only by bot owner through commands
public partial class Games
{
/// <summary>

View File

@ -130,6 +130,7 @@ namespace NadekoBot.Modules.Music.Classes
{
Console.WriteLine("Music thread almost crashed.");
Console.WriteLine(ex);
await Task.Delay(3000).ConfigureAwait(false);
}
finally
{

View File

@ -49,6 +49,7 @@ namespace NadekoBot.Modules.Searches
using (var http = new HttpClient())
{
var response = await http.GetStringAsync("http://api.yomomma.info/").ConfigureAwait(false);
System.Console.WriteLine(response);
await msg.Channel.SendConfirmAsync(JObject.Parse(response)["joke"].ToString() + " 😆").ConfigureAwait(false);
}
}

View File

@ -31,6 +31,8 @@ namespace NadekoBot.Modules.Searches
if (string.IsNullOrWhiteSpace(query))
return;
var battletag = Regex.Replace(query, "#", "-", RegexOptions.IgnoreCase);
await channel.TriggerTypingAsync().ConfigureAwait(false);
try
{
var model = await GetProfile(region, battletag);

View File

@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Utility
"Equals",
"GetHashCode",
"GetType"});
await msg.Channel.SendConfirmAsync(string.Join(", ",selection));
await msg.Channel.SendConfirmAsync("Available functions in calc", string.Join(", ", selection));
}
}

View File

@ -132,13 +132,30 @@ namespace NadekoBot.Modules.Utility
if (page < 1 || page > 100)
return;
if (target != null)
{
await channel.SendConfirmAsync($"⚔ **Page #{page} of roles for {target.Username}**", $"```css\n• " + string.Join("\n• ", target.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * RolesPerPage).Take(RolesPerPage)).SanitizeMentions() + "\n```");
var roles = target.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * RolesPerPage).Take(RolesPerPage);
if (!roles.Any())
{
await channel.SendErrorAsync("No roles on this page.").ConfigureAwait(false);
}
else
{
await channel.SendConfirmAsync($"⚔ **Page #{page} of all roles on this server:**", $"```css\n• " + string.Join("\n• ", guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * RolesPerPage).Take(RolesPerPage)).SanitizeMentions() + "\n```");
await channel.SendConfirmAsync($"⚔ **Page #{page} of roles for {target.Username}**", $"```css\n• " + string.Join("\n• ", roles).SanitizeMentions() + "\n```").ConfigureAwait(false);
}
}
else
{
var roles = guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * RolesPerPage).Take(RolesPerPage);
if (!roles.Any())
{
await channel.SendErrorAsync("No roles on this page.").ConfigureAwait(false);
}
else
{
await channel.SendConfirmAsync($"⚔ **Page #{page} of all roles on this server:**", $"```css\n• " + string.Join("\n• ", roles).SanitizeMentions() + "\n```").ConfigureAwait(false);
}
}
}

View File

@ -167,7 +167,8 @@ namespace NadekoBot.Services.Impl
remaining -= toGet;
var q = yt.Videos.List("contentDetails");
q.Id = string.Join(",", videoIds);
q.Id = string.Join(",", videoIdsList.Take(toGet));
videoIdsList = videoIdsList.Skip(toGet).ToList();
var items = (await q.ExecuteAsync().ConfigureAwait(false)).Items;
foreach (var i in items)
{