Using native videolib api. added .mute and .deafen

This commit is contained in:
Master Kwoth 2016-01-30 16:23:52 +01:00
parent 7820f98e82
commit f4f927c7a5
4 changed files with 104 additions and 15 deletions

View File

@ -12,7 +12,7 @@ using System.Diagnostics;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.Threading; using System.Threading;
using Timer = System.Timers.Timer; using Timer = System.Timers.Timer;
using YoutubeExtractor; using VideoLibrary;
namespace NadekoBot.Classes.Music { namespace NadekoBot.Classes.Music {
public enum StreamState { public enum StreamState {
@ -51,18 +51,20 @@ namespace NadekoBot.Classes.Music {
this.VoiceClient = mc.VoiceClient; this.VoiceClient = mc.VoiceClient;
this.Server = e.Server; this.Server = e.Server;
this.Query = query; this.Query = query;
Task.Run(() => ResolveStreamLink()); Task.Run(async () => await ResolveStreamLink());
} }
private void ResolveStreamLink() { private async Task ResolveStreamLink() {
VideoInfo video = null; VideoLibrary.YouTubeVideo video = null;
try { try {
if (OnResolving != null) if (OnResolving != null)
OnResolving(); OnResolving();
Console.WriteLine("Resolving video link"); Console.WriteLine("Resolving video link");
video = DownloadUrlResolver.GetDownloadUrls(Searches.FindYoutubeUrlByKeywords(Query))
.Where(v => v.AdaptiveType == AdaptiveType.Audio) video = (await YouTube.Default.GetAllVideosAsync(Searches.FindYoutubeUrlByKeywords(Query)))
.OrderByDescending(v => v.AudioBitrate).FirstOrDefault(); .Where(v => v.AdaptiveKind == AdaptiveKind.Audio)
.OrderByDescending(v => v.AudioBitrate)
.FirstOrDefault();
if (video == null) // do something with this error if (video == null) // do something with this error
throw new Exception("Could not load any video elements based on the query."); throw new Exception("Could not load any video elements based on the query.");
@ -76,9 +78,10 @@ namespace NadekoBot.Classes.Music {
return; return;
} }
musicStreamer = new MusicStreamer(this, video.DownloadUrl, Channel); musicStreamer = new MusicStreamer(this, video.Uri, Channel);
if (OnQueued != null) if (OnQueued != null)
OnQueued(); OnQueued();
return;
} }
internal string PrintStats() => musicStreamer?.Stats(); internal string PrintStats() => musicStreamer?.Stats();

View File

@ -11,16 +11,17 @@ using System.Threading.Tasks;
using System.Timers; using System.Timers;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System.Collections; using System.Collections;
using System.Collections.Concurrent;
//github.com/micmorris contributed quite a bit to making trivia better! //github.com/micmorris contributed quite a bit to making trivia better!
namespace NadekoBot { namespace NadekoBot {
public class Trivia : DiscordCommand { public class Trivia : DiscordCommand {
public static float HINT_TIME_SECONDS = 6; public static float HINT_TIME_SECONDS = 6;
public static Dictionary<ulong, TriviaGame> runningTrivias; public static ConcurrentDictionary<ulong, TriviaGame> runningTrivias;
public Trivia() : base() { public Trivia() : base() {
runningTrivias = new Dictionary<ulong, TriviaGame>(); runningTrivias = new ConcurrentDictionary<ulong, TriviaGame>();
} }
public static TriviaGame StartNewGame(CommandEventArgs e) { public static TriviaGame StartNewGame(CommandEventArgs e) {
@ -28,7 +29,7 @@ namespace NadekoBot {
return null; return null;
var tg = new TriviaGame(e, NadekoBot.client); var tg = new TriviaGame(e, NadekoBot.client);
runningTrivias.Add(e.Server.Id, tg); runningTrivias.TryAdd(e.Server.Id, tg);
return tg; return tg;
} }
@ -86,7 +87,8 @@ namespace NadekoBot {
}; };
internal static void FinishGame(TriviaGame triviaGame) { internal static void FinishGame(TriviaGame triviaGame) {
runningTrivias.Remove(runningTrivias.Where(kvp => kvp.Value == triviaGame).First().Key); TriviaGame throwaway;
runningTrivias.TryRemove(runningTrivias.Where(kvp => kvp.Value == triviaGame).First().Key,out throwaway);
} }
} }

View File

@ -184,6 +184,87 @@ namespace NadekoBot.Modules {
await e.Send("No sufficient permissions."); await e.Send("No sufficient permissions.");
} }
}); });
cgb.CreateCommand(".mute")
.Description("Mutes mentioned user or users")
.Parameter("throwaway", ParameterType.Unparsed)
.Do(async e => {
if (!e.User.ServerPermissions.MuteMembers) {
await e.Send("You do not have permission to do that.");
return;
}
if (e.Message.MentionedUsers.Count() == 0)
return;
try {
foreach (var u in e.Message.MentionedUsers) {
await u.Edit(isMuted: true);
}
await e.Send("Mute successful");
} catch (Exception) {
await e.Send("I do not have permission to do that most likely.");
}
});
cgb.CreateCommand(".unmute")
.Description("Unmutes mentioned user or users")
.Parameter("throwaway", ParameterType.Unparsed)
.Do(async e => {
if (!e.User.ServerPermissions.MuteMembers) {
await e.Send("You do not have permission to do that.");
return;
}
if (e.Message.MentionedUsers.Count() == 0)
return;
try {
foreach (var u in e.Message.MentionedUsers) {
await u.Edit(isMuted: false);
}
await e.Send("Unmute successful");
} catch (Exception) {
await e.Send("I do not have permission to do that most likely.");
}
});
cgb.CreateCommand(".deafen")
.Alias(".deaf")
.Description("Deafens mentioned user or users")
.Parameter("throwaway", ParameterType.Unparsed)
.Do(async e => {
if (!e.User.ServerPermissions.DeafenMembers) {
await e.Send("You do not have permission to do that.");
return;
}
if (e.Message.MentionedUsers.Count() == 0)
return;
try {
foreach (var u in e.Message.MentionedUsers) {
await u.Edit(isDeafened: true);
}
await e.Send("Deafen successful");
} catch (Exception) {
await e.Send("I do not have permission to do that most likely.");
}
});
cgb.CreateCommand(".undeafen")
.Alias(".undeaf")
.Description("Undeafens mentioned user or users")
.Parameter("throwaway", ParameterType.Unparsed)
.Do(async e => {
if (!e.User.ServerPermissions.DeafenMembers) {
await e.Send("You do not have permission to do that.");
return;
}
if (e.Message.MentionedUsers.Count() == 0)
return;
try {
foreach (var u in e.Message.MentionedUsers) {
await u.Edit(isDeafened: false);
}
await e.Send("Undeafen successful");
} catch (Exception) {
await e.Send("I do not have permission to do that most likely.");
}
});
cgb.CreateCommand(".rvch") cgb.CreateCommand(".rvch")
.Description("Removes a voice channel with a given name.") .Description("Removes a voice channel with a given name.")
@ -404,8 +485,9 @@ namespace NadekoBot.Modules {
await e.Send("Sending failed."); await e.Send("Sending failed.");
} }
}); });
/*cgb.CreateCommand(".voicetext")
.Description("Enabled or disabled voice to text channel connection. Only people in a certain voice channel will see ")
/*
cgb.CreateCommand(".jsontype") cgb.CreateCommand(".jsontype")
.Do(async e => { .Do(async e => {
Newtonsoft.Json.Linq.JArray data = Newtonsoft.Json.Linq.JArray.Parse(File.ReadAllText("data.json")); Newtonsoft.Json.Linq.JArray data = Newtonsoft.Json.Linq.JArray.Parse(File.ReadAllText("data.json"));

View File

@ -124,10 +124,12 @@
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath> <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath> <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
<Private>True</Private> <Private>True</Private>