small changes and improvements
This commit is contained in:
parent
af891b53f5
commit
cdf90a15be
@ -59,7 +59,8 @@ namespace NadekoBot.Classes.Music {
|
|||||||
Task.Run(async () => {
|
Task.Run(async () => {
|
||||||
while (!Destroyed) {
|
while (!Destroyed) {
|
||||||
try {
|
try {
|
||||||
audioClient = await PlaybackVoiceChannel.JoinAudio();
|
if(audioClient?.State != ConnectionState.Connected)
|
||||||
|
audioClient = await PlaybackVoiceChannel.JoinAudio();
|
||||||
} catch {
|
} catch {
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
continue;
|
continue;
|
||||||
@ -171,6 +172,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
lock (playlistLock) {
|
lock (playlistLock) {
|
||||||
playlist.Clear();
|
playlist.Clear();
|
||||||
Destroyed = true;
|
Destroyed = true;
|
||||||
|
CurrentSong = null;
|
||||||
if (!SongCancelSource.IsCancellationRequested)
|
if (!SongCancelSource.IsCancellationRequested)
|
||||||
SongCancelSource.Cancel();
|
SongCancelSource.Cancel();
|
||||||
audioClient.Disconnect();
|
audioClient.Disconnect();
|
||||||
|
@ -8,21 +8,13 @@ using NadekoBot.Extensions;
|
|||||||
|
|
||||||
namespace NadekoBot.Commands {
|
namespace NadekoBot.Commands {
|
||||||
internal class DrawCommand : IDiscordCommand {
|
internal class DrawCommand : IDiscordCommand {
|
||||||
private static ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>();
|
private static readonly ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>();
|
||||||
|
|
||||||
public DrawCommand() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Func<CommandEventArgs, Task> DoFunc() => async (e) => {
|
public Func<CommandEventArgs, Task> DoFunc() => async (e) => {
|
||||||
if (!AllDecks.ContainsKey(e.Server)) {
|
var cards = AllDecks.GetOrAdd(e.Server, (s) => new Cards());
|
||||||
await e.Channel.SendMessage("Shuffling cards...");
|
|
||||||
AllDecks.TryAdd(e.Server, new Cards());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var cards = AllDecks[e.Server];
|
var num = 1;
|
||||||
int num = 1;
|
|
||||||
var isParsed = int.TryParse(e.GetArg("count"), out num);
|
var isParsed = int.TryParse(e.GetArg("count"), out num);
|
||||||
if (!isParsed || num < 2) {
|
if (!isParsed || num < 2) {
|
||||||
var c = cards.DrawACard();
|
var c = cards.DrawACard();
|
||||||
@ -32,9 +24,9 @@ namespace NadekoBot.Commands {
|
|||||||
if (num > 5)
|
if (num > 5)
|
||||||
num = 5;
|
num = 5;
|
||||||
|
|
||||||
List<Image> images = new List<Image>();
|
var images = new List<Image>();
|
||||||
List<Cards.Card> cardObjects = new List<Cards.Card>();
|
var cardObjects = new List<Cards.Card>();
|
||||||
for (int i = 0; i < num; i++) {
|
for (var i = 0; i < num; i++) {
|
||||||
if (cards.CardPool.Count == 0 && i != 0) {
|
if (cards.CardPool.Count == 0 && i != 0) {
|
||||||
await e.Channel.SendMessage("No more cards in a deck.");
|
await e.Channel.SendMessage("No more cards in a deck.");
|
||||||
break;
|
break;
|
||||||
@ -43,7 +35,7 @@ namespace NadekoBot.Commands {
|
|||||||
cardObjects.Add(currentCard);
|
cardObjects.Add(currentCard);
|
||||||
images.Add(Properties.Resources.ResourceManager.GetObject(currentCard.Name) as Image);
|
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());
|
await e.Channel.SendFile(images.Count + " cards.jpg", bitmap.ToStream());
|
||||||
if (cardObjects.Count == 5) {
|
if (cardObjects.Count == 5) {
|
||||||
await e.Channel.SendMessage(Cards.GetHandValue(cardObjects));
|
await e.Channel.SendMessage(Cards.GetHandValue(cardObjects));
|
||||||
@ -63,9 +55,13 @@ namespace NadekoBot.Commands {
|
|||||||
.Alias("$reshuffle")
|
.Alias("$reshuffle")
|
||||||
.Description("Reshuffles all cards back into the deck.")
|
.Description("Reshuffles all cards back into the deck.")
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
if (!AllDecks.ContainsKey(e.Server))
|
AllDecks.AddOrUpdate(e.Server,
|
||||||
AllDecks.TryAdd(e.Server, new Cards());
|
(s) => new Cards(),
|
||||||
AllDecks[e.Server].Restart();
|
(s, c) => {
|
||||||
|
c.Restart();
|
||||||
|
return c;
|
||||||
|
});
|
||||||
|
|
||||||
await e.Channel.SendMessage("Deck reshuffled.");
|
await e.Channel.SendMessage("Deck reshuffled.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ using NadekoBot.Extensions;
|
|||||||
namespace NadekoBot.Modules {
|
namespace NadekoBot.Modules {
|
||||||
internal class Games : DiscordModule {
|
internal class Games : DiscordModule {
|
||||||
private readonly string[] _8BallAnswers;
|
private readonly string[] _8BallAnswers;
|
||||||
private Random rng = new Random();
|
private readonly Random rng = new Random();
|
||||||
|
|
||||||
public Games() {
|
public Games() {
|
||||||
commands.Add(new Trivia());
|
commands.Add(new Trivia());
|
||||||
@ -53,7 +53,7 @@ namespace NadekoBot.Modules {
|
|||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
await e.Channel.SendMessage(
|
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 { }
|
} catch { }
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -63,6 +63,10 @@ namespace NadekoBot.Modules {
|
|||||||
.Parameter("target", Discord.Commands.ParameterType.Required)
|
.Parameter("target", Discord.Commands.ParameterType.Required)
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault();
|
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 usrType = GetType(usr.Id);
|
||||||
var response = "";
|
var response = "";
|
||||||
var dmg = GetDamage(usrType, e.GetArg("attack_type").ToLowerInvariant());
|
var dmg = GetDamage(usrType, e.GetArg("attack_type").ToLowerInvariant());
|
||||||
|
@ -67,7 +67,7 @@ namespace NadekoBot {
|
|||||||
|
|
||||||
//create new discord client and log
|
//create new discord client and log
|
||||||
Client = new DiscordClient(new DiscordConfigBuilder() {
|
Client = new DiscordClient(new DiscordConfigBuilder() {
|
||||||
MessageCacheSize = 20,
|
MessageCacheSize = 10,
|
||||||
LogLevel = LogSeverity.Warning,
|
LogLevel = LogSeverity.Warning,
|
||||||
LogHandler = (s, e) =>
|
LogHandler = (s, e) =>
|
||||||
Console.WriteLine($"Severity: {e.Severity}" +
|
Console.WriteLine($"Severity: {e.Severity}" +
|
||||||
|
Loading…
Reference in New Issue
Block a user