small changes and improvements

This commit is contained in:
Master Kwoth 2016-03-06 08:50:25 +01:00
parent af891b53f5
commit cdf90a15be
4 changed files with 24 additions and 22 deletions

View File

@ -59,7 +59,8 @@ namespace NadekoBot.Classes.Music {
Task.Run(async () => {
while (!Destroyed) {
try {
audioClient = await PlaybackVoiceChannel.JoinAudio();
if(audioClient?.State != ConnectionState.Connected)
audioClient = await PlaybackVoiceChannel.JoinAudio();
} catch {
await Task.Delay(1000);
continue;
@ -171,6 +172,7 @@ namespace NadekoBot.Classes.Music {
lock (playlistLock) {
playlist.Clear();
Destroyed = true;
CurrentSong = null;
if (!SongCancelSource.IsCancellationRequested)
SongCancelSource.Cancel();
audioClient.Disconnect();

View File

@ -8,21 +8,13 @@ using NadekoBot.Extensions;
namespace NadekoBot.Commands {
internal class DrawCommand : IDiscordCommand {
private static ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>();
public DrawCommand() {
}
private static readonly ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>();
public Func<CommandEventArgs, Task> DoFunc() => async (e) => {
if (!AllDecks.ContainsKey(e.Server)) {
await e.Channel.SendMessage("Shuffling cards...");
AllDecks.TryAdd(e.Server, new Cards());
}
var cards = AllDecks.GetOrAdd(e.Server, (s) => new Cards());
try {
var cards = AllDecks[e.Server];
int num = 1;
var num = 1;
var isParsed = int.TryParse(e.GetArg("count"), out num);
if (!isParsed || num < 2) {
var c = cards.DrawACard();
@ -32,9 +24,9 @@ namespace NadekoBot.Commands {
if (num > 5)
num = 5;
List<Image> images = new List<Image>();
List<Cards.Card> cardObjects = new List<Cards.Card>();
for (int i = 0; i < num; i++) {
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 e.Channel.SendMessage("No more cards in a deck.");
break;
@ -43,7 +35,7 @@ namespace NadekoBot.Commands {
cardObjects.Add(currentCard);
images.Add(Properties.Resources.ResourceManager.GetObject(currentCard.Name) as Image);
}
Bitmap bitmap = images.Merge();
var bitmap = images.Merge();
await e.Channel.SendFile(images.Count + " cards.jpg", bitmap.ToStream());
if (cardObjects.Count == 5) {
await e.Channel.SendMessage(Cards.GetHandValue(cardObjects));
@ -63,9 +55,13 @@ namespace NadekoBot.Commands {
.Alias("$reshuffle")
.Description("Reshuffles all cards back into the deck.")
.Do(async e => {
if (!AllDecks.ContainsKey(e.Server))
AllDecks.TryAdd(e.Server, new Cards());
AllDecks[e.Server].Restart();
AllDecks.AddOrUpdate(e.Server,
(s) => new Cards(),
(s, c) => {
c.Restart();
return c;
});
await e.Channel.SendMessage("Deck reshuffled.");
});
}

View File

@ -11,7 +11,7 @@ using NadekoBot.Extensions;
namespace NadekoBot.Modules {
internal class Games : DiscordModule {
private readonly string[] _8BallAnswers;
private Random rng = new Random();
private readonly Random rng = new Random();
public Games() {
commands.Add(new Trivia());
@ -53,7 +53,7 @@ namespace NadekoBot.Modules {
return;
try {
await e.Channel.SendMessage(
$":question: **Question**: `{question}` \n:crystal_ball: **8Ball Answers**: `{_8BallAnswers[rng.Next(0, _8BallAnswers.Length)]}`");
$":question: **Question**: `{question}` \n🎱 **8Ball Answers**: `{_8BallAnswers[rng.Next(0, _8BallAnswers.Length)]}`");
} catch { }
});
@ -63,6 +63,10 @@ namespace NadekoBot.Modules {
.Parameter("target", Discord.Commands.ParameterType.Required)
.Do(async e => {
var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault();
if (usr == null) {
await e.Channel.SendMessage("No such person.");
return;
}
var usrType = GetType(usr.Id);
var response = "";
var dmg = GetDamage(usrType, e.GetArg("attack_type").ToLowerInvariant());

View File

@ -67,7 +67,7 @@ namespace NadekoBot {
//create new discord client and log
Client = new DiscordClient(new DiscordConfigBuilder() {
MessageCacheSize = 20,
MessageCacheSize = 10,
LogLevel = LogSeverity.Warning,
LogHandler = (s, e) =>
Console.WriteLine($"Severity: {e.Severity}" +