!m d added, some improvements?!

This commit is contained in:
Master Kwoth 2016-03-04 10:45:41 +01:00
parent d62275d1c8
commit 084d9f5613
7 changed files with 73 additions and 45 deletions

View File

@ -7,6 +7,10 @@ namespace NadekoBot.Classes.JSONModels {
public bool ForwardMessages = true;
public HashSet<ulong> ServerBlacklist = new HashSet<ulong>();
public HashSet<ulong> ChannelBlacklist = new HashSet<ulong>();
public HashSet<ulong> UserBlacklist = new HashSet<ulong>();
public HashSet<ulong> UserBlacklist = new HashSet<ulong>() {
105309315895693312,
119174277298782216,
143515953525817344
};
}
}

View File

@ -43,6 +43,9 @@ namespace NadekoBot.Classes.Music {
public Channel PlaybackVoiceChannel { get; private set; }
private bool Stopped { get; set; }
private readonly object disconnectLock = new object();
public MusicPlayer(Channel startingVoiceChannel, float? defaultVolume) {
if (startingVoiceChannel == null)
throw new ArgumentNullException(nameof(startingVoiceChannel));
@ -55,7 +58,7 @@ namespace NadekoBot.Classes.Music {
cancelToken = SongCancelSource.Token;
Task.Run(async () => {
while (true) {
while (!Stopped) {
try {
audioClient = await PlaybackVoiceChannel.JoinAudio();
}
@ -96,17 +99,11 @@ namespace NadekoBot.Classes.Music {
}
}
public void Stop() {
public void Stop(bool disconnect = false) {
lock (playlistLock) {
playlist.Clear();
try {
if (!SongCancelSource.IsCancellationRequested)
SongCancelSource.Cancel();
audioClient.Disconnect();
}
catch {
Console.WriteLine("STOP");
}
if (!SongCancelSource.IsCancellationRequested)
SongCancelSource.Cancel();
}
}
@ -174,5 +171,17 @@ namespace NadekoBot.Classes.Music {
playlist.Clear();
}
}
public void Destroy() {
lock (playlistLock) {
playlist.Clear();
if (!SongCancelSource.IsCancellationRequested)
SongCancelSource.Cancel();
try {
audioClient.Disconnect();
}
catch {}
}
}
}
}

View File

@ -166,11 +166,21 @@ namespace NadekoBot.Classes.Music {
} finally {
Console.WriteLine($"Buffering done." + $" [{songBuffer.ContentLength}]");
if (p != null) {
p.CancelOutputRead();
p.StandardOutput.Dispose();
p.CloseMainWindow();
p.Close();
p.Dispose();
try {
p.CancelOutputRead();
} catch { }
try {
p.StandardOutput.Dispose();
} catch { }
try {
p.CloseMainWindow();
} catch { }
try {
p.Close();
} catch { }
try {
p.Dispose();
} catch { }
}
}
});
@ -193,8 +203,8 @@ namespace NadekoBot.Classes.Music {
var read = songBuffer.Read(buffer, blockSize);
if (read == 0)
if (attempt++ == 20) {
voiceClient.Wait();
Console.WriteLine("Nothing to read.");
voiceClient.Wait();
return;
} else
await Task.Delay(50, cancelToken);
@ -208,13 +218,7 @@ namespace NadekoBot.Classes.Music {
}
await bufferTask;
cancelToken.ThrowIfCancellationRequested();
//try {
// voiceClient.Clear();
// Console.WriteLine("CLEARED");
//}
//catch {
// Console.WriteLine("CLEAR FAILED!!!");
//}
voiceClient.Clear();
}
//stackoverflow ftw

View File

@ -41,10 +41,17 @@ namespace NadekoBot.Commands {
//cw.Start();
wars.Add(cw);
cw.OnUserTimeExpired += async (u) => {
await e.Channel.SendMessage($"❗🔰**Claim from @{u} for a war against {cw.ShortPrint()} has expired.**");
try {
await
e.Channel.SendMessage($"❗🔰**Claim from @{u} for a war against {cw.ShortPrint()} has expired.**");
}
catch {}
};
cw.OnWarEnded += async () => {
await e.Channel.SendMessage($"❗🔰**War against {cw.ShortPrint()} ended.**");
try {
await e.Channel.SendMessage($"❗🔰**War against {cw.ShortPrint()} ended.**");
}
catch {}
};
await e.Channel.SendMessage($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**");
//war with the index X started.

View File

@ -52,16 +52,24 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("s")
.Alias("stop")
.Description("Completely stops the music, unbinds the bot from the channel, and cleans up files.")
.Description("Stops the music and clears the playlist. Stays in the channel.")
.Do(async e => {
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return;
musicPlayer.Stop();
var msg = await e.Channel.SendMessage("⚠Due to music issues, NadekoBot is unable to leave voice channels at this moment.\nIf this presents inconvenience, you can use `!m mv` command to make her join your current voice channel.");
await Task.Delay(5000);
try {
await msg.Delete();
} catch { }
await Task.Run(() => {
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return;
musicPlayer.Stop();
});
});
cgb.CreateCommand("d")
.Alias("destroy")
.Description("Completely stops the music and unbinds the bot from the channel. (may cause weird behaviour)")
.Do(async e => {
await Task.Run(() => {
MusicPlayer musicPlayer;
if (!MusicPlayers.TryRemove(e.Server, out musicPlayer)) return;
musicPlayer.Destroy();
});
});
cgb.CreateCommand("p")
@ -324,8 +332,7 @@ namespace NadekoBot.Modules {
OnCompleted = async song => {
try {
await textCh.SendMessage($"🎵`Finished`{song.PrettyName}");
}
catch {}
} catch { }
},
OnStarted = async (song) => {
try {

View File

@ -171,15 +171,8 @@ namespace NadekoBot {
try {
if (e.Server != null || e.User.Id == Client.CurrentUser.Id) return;
if (PollCommand.ActivePolls.SelectMany(kvp => kvp.Key.Users.Select(u => u.Id)).Contains(e.User.Id)) return;
// just ban this trash AutoModerator
// and cancer christmass spirit
// and crappy shotaslave
if (IsBlackListed(e))
return;
if (e.User.Id == 105309315895693312 ||
e.User.Id == 119174277298782216 ||
e.User.Id == 143515953525817344)
return; // FU
if (!NadekoBot.Config.DontJoinServers) {
try {

View File

@ -3,5 +3,9 @@
"ForwardMessages": true,
"ServerBlacklist": [],
"ChannelBlacklist": [],
"UserBlacklist": []
"UserBlacklist": [
105309315895693312,
119174277298782216,
143515953525817344
]
}