Using native videolib api. added .mute and .deafen
This commit is contained in:
parent
7820f98e82
commit
f4f927c7a5
@ -12,7 +12,7 @@ using System.Diagnostics;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Threading;
|
||||
using Timer = System.Timers.Timer;
|
||||
using YoutubeExtractor;
|
||||
using VideoLibrary;
|
||||
|
||||
namespace NadekoBot.Classes.Music {
|
||||
public enum StreamState {
|
||||
@ -51,18 +51,20 @@ namespace NadekoBot.Classes.Music {
|
||||
this.VoiceClient = mc.VoiceClient;
|
||||
this.Server = e.Server;
|
||||
this.Query = query;
|
||||
Task.Run(() => ResolveStreamLink());
|
||||
Task.Run(async () => await ResolveStreamLink());
|
||||
}
|
||||
|
||||
private void ResolveStreamLink() {
|
||||
VideoInfo video = null;
|
||||
private async Task ResolveStreamLink() {
|
||||
VideoLibrary.YouTubeVideo video = null;
|
||||
try {
|
||||
if (OnResolving != null)
|
||||
OnResolving();
|
||||
Console.WriteLine("Resolving video link");
|
||||
video = DownloadUrlResolver.GetDownloadUrls(Searches.FindYoutubeUrlByKeywords(Query))
|
||||
.Where(v => v.AdaptiveType == AdaptiveType.Audio)
|
||||
.OrderByDescending(v => v.AudioBitrate).FirstOrDefault();
|
||||
|
||||
video = (await YouTube.Default.GetAllVideosAsync(Searches.FindYoutubeUrlByKeywords(Query)))
|
||||
.Where(v => v.AdaptiveKind == AdaptiveKind.Audio)
|
||||
.OrderByDescending(v => v.AudioBitrate)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (video == null) // do something with this error
|
||||
throw new Exception("Could not load any video elements based on the query.");
|
||||
@ -76,9 +78,10 @@ namespace NadekoBot.Classes.Music {
|
||||
return;
|
||||
}
|
||||
|
||||
musicStreamer = new MusicStreamer(this, video.DownloadUrl, Channel);
|
||||
musicStreamer = new MusicStreamer(this, video.Uri, Channel);
|
||||
if (OnQueued != null)
|
||||
OnQueued();
|
||||
return;
|
||||
}
|
||||
|
||||
internal string PrintStats() => musicStreamer?.Stats();
|
||||
|
@ -11,16 +11,17 @@ using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
//github.com/micmorris contributed quite a bit to making trivia better!
|
||||
namespace NadekoBot {
|
||||
public class Trivia : DiscordCommand {
|
||||
public static float HINT_TIME_SECONDS = 6;
|
||||
|
||||
public static Dictionary<ulong, TriviaGame> runningTrivias;
|
||||
public static ConcurrentDictionary<ulong, TriviaGame> runningTrivias;
|
||||
|
||||
public Trivia() : base() {
|
||||
runningTrivias = new Dictionary<ulong, TriviaGame>();
|
||||
runningTrivias = new ConcurrentDictionary<ulong, TriviaGame>();
|
||||
}
|
||||
|
||||
public static TriviaGame StartNewGame(CommandEventArgs e) {
|
||||
@ -28,7 +29,7 @@ namespace NadekoBot {
|
||||
return null;
|
||||
|
||||
var tg = new TriviaGame(e, NadekoBot.client);
|
||||
runningTrivias.Add(e.Server.Id, tg);
|
||||
runningTrivias.TryAdd(e.Server.Id, tg);
|
||||
|
||||
return tg;
|
||||
}
|
||||
@ -86,7 +87,8 @@ namespace NadekoBot {
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,6 +184,87 @@ namespace NadekoBot.Modules {
|
||||
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")
|
||||
.Description("Removes a voice channel with a given name.")
|
||||
@ -302,7 +383,7 @@ namespace NadekoBot.Modules {
|
||||
try {
|
||||
var msgs = await e.Channel.DownloadMessages(100);
|
||||
var lastmessage = e.Channel.Messages.LastOrDefault();
|
||||
while (num > 0 && lastmessage!=null) {
|
||||
while (num > 0 && lastmessage != null) {
|
||||
msgs.ForEach(async m => await m.Delete());
|
||||
num -= 100;
|
||||
lastmessage = msgs.LastOrDefault();
|
||||
@ -404,8 +485,9 @@ namespace NadekoBot.Modules {
|
||||
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")
|
||||
.Do(async e => {
|
||||
Newtonsoft.Json.Linq.JArray data = Newtonsoft.Json.Linq.JArray.Parse(File.ReadAllText("data.json"));
|
||||
|
@ -124,10 +124,12 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<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">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<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>
|
||||
<Private>True</Private>
|
||||
|
Loading…
Reference in New Issue
Block a user