$raffle, will try to wait longer for buffer read failure break

This commit is contained in:
Master Kwoth 2016-02-04 06:46:30 +01:00
parent 49c20b7f00
commit 4db016a5e4
2 changed files with 20 additions and 3 deletions

View File

@ -258,12 +258,12 @@ namespace NadekoBot.Classes.Music {
} }
if (readCount == 0) { if (readCount == 0) {
if (attempt == 2) { if (attempt == 4) {
Console.WriteLine($"Failed to read {attempt} times. Breaking out. [{DateTime.Now.Second}]"); Console.WriteLine($"Failed to read {attempt} times. Breaking out. [{DateTime.Now.Second}]");
break; break;
} else { } else {
++attempt; ++attempt;
await Task.Delay(10); await Task.Delay(15);
} }
} else } else
attempt = 0; attempt = 0;

View File

@ -1,4 +1,6 @@
using Discord.Modules; using Discord.Commands;
using Discord.Modules;
using System.Linq;
namespace NadekoBot.Modules namespace NadekoBot.Modules
{ {
@ -16,6 +18,21 @@ namespace NadekoBot.Modules
manager.CreateCommands("", cgb => manager.CreateCommands("", cgb =>
{ {
commands.ForEach(com => com.Init(cgb)); commands.ForEach(com => com.Init(cgb));
cgb.CreateCommand("$raffle")
.Description("Mentions a user from the online list from the (optional) role.")
.Parameter("role", ParameterType.Optional)
.Do(async e => {
if (!e.User.ServerPermissions.MentionEveryone) return;
var arg = string.IsNullOrWhiteSpace(e.GetArg("role")) ? "@everyone" : e.GetArg("role");
var role = e.Server.FindRoles(arg).FirstOrDefault();
if (role == null) {
await e.Channel.SendMessage(":anger: Role not found.");
return;
}
var members = role.Members.Where(u => u.Status == Discord.UserStatus.Online); // only online
await e.Channel.SendMessage($"**Raffled user:** {members.ToArray()[new System.Random().Next(0, members.Count())].Name}");
});
}); });
} }
} }