diff --git a/NadekoBot/Classes/Music/Song.cs b/NadekoBot/Classes/Music/Song.cs index 8b594e7e..0586f73d 100644 --- a/NadekoBot/Classes/Music/Song.cs +++ b/NadekoBot/Classes/Music/Song.cs @@ -161,8 +161,10 @@ namespace NadekoBot.Classes.Music { break; else await Task.Delay(100, cancelToken); - else + else { attempt = 0; + await Task.Delay(5, cancelToken); + } await songBuffer.WriteAsync(buffer, read, cancelToken); if (songBuffer.ContentLength > 2.MB()) prebufferingComplete = true; diff --git a/NadekoBot/Classes/Permissions/SimpleCheckers.cs b/NadekoBot/Classes/Permissions/SimpleCheckers.cs index bc052a46..eabb0147 100644 --- a/NadekoBot/Classes/Permissions/SimpleCheckers.cs +++ b/NadekoBot/Classes/Permissions/SimpleCheckers.cs @@ -12,7 +12,10 @@ namespace NadekoBot.Classes.Permissions { (com, user, ch) => NadekoBot.IsOwner(user.Id); public static Func ManageMessages() => - (com, user, ch) => NadekoBot.IsOwner(user.Id); + (com, user, ch) => user.ServerPermissions.ManageMessages; + + public static Func ManageChannels() => + (com, user, ch) => user.ServerPermissions.ManageChannels; public class ManageRoles :IPermissionChecker { diff --git a/NadekoBot/Commands/VoicePlusTextCommand.cs b/NadekoBot/Commands/VoicePlusTextCommand.cs new file mode 100644 index 00000000..d6cae33d --- /dev/null +++ b/NadekoBot/Commands/VoicePlusTextCommand.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using NadekoBot.Classes.Permissions; +using ChPermOverride = Discord.ChannelPermissionOverrides; + +namespace NadekoBot.Commands { + /// + /// This is an ingenious idea by @Googie2149 a few months back. + /// He never got around to implementing it, so i grew impatient + /// and did it myself. Googie is cool guy and a creator of RoboNitori + /// You can check out his server here: https://discord.gg/0ZgChoTkuxAzARfF + /// sowwy googie ;( + /// + internal class VoicePlusTextCommand : IDiscordCommand { + public static readonly HashSet Subscribers = new HashSet(); + + public VoicePlusTextCommand() { + NadekoBot.Client.UserUpdated += async (sender, e) => { + try { + if (e.Before.VoiceChannel == e.After.VoiceChannel) return; + + var beforeVch = e.Before.VoiceChannel; + if (beforeVch != null) { + var textChannel = + e.Server.FindChannels(beforeVch.Name + "-voice", ChannelType.Text).FirstOrDefault(); + if (textChannel == null) + return; + await textChannel.AddPermissionsRule(e.Before, + new ChPermOverride(readMessages: PermValue.Deny, + sendMessages: PermValue.Deny)); + } + var afterVch = e.After.VoiceChannel; + if (afterVch != null) { + var textChannel = + e.Server.FindChannels(afterVch.Name + "-voice", ChannelType.Text).FirstOrDefault() ?? + (await e.Server.CreateChannel(afterVch.Name + "-voice", ChannelType.Text)); + if (textChannel == null) + return; + await textChannel.AddPermissionsRule(e.After, + new ChPermOverride(readMessages: PermValue.Allow, + sendMessages: PermValue.Allow)); + } + } catch (Exception ex) { + Console.WriteLine(ex); + } + }; + } + + public void Init(CommandGroupBuilder cgb) { + cgb.CreateCommand(".v+t") + .Alias(".voice+text") + .Description("Creates a text channel for each voice channel only users in that voice channel can see.") + .AddCheck(SimpleCheckers.ManageChannels()) + .AddCheck(SimpleCheckers.CanManageRoles) + .Do(async e => { + if (Subscribers.Contains(e.Server.Id)) { + Subscribers.Remove(e.Server.Id); + foreach (var textChannel in e.Server.TextChannels.Where(c => c.Name.EndsWith("-voice"))) { + var deleteTask = textChannel?.Delete(); + try { + if (deleteTask != null) + await deleteTask; + } catch { + await e.Channel.SendMessage(":anger: Error: Most likely i don't have permissions to do this."); + return; + } + } + await e.Channel.SendMessage("Successfuly removed voice + text feature."); + return; + } + Subscribers.Add(e.Server.Id); + await e.Channel.SendMessage("Successfuly enabled voice + text feature. " + + "**Make sure the bot has manage roles and manage channels permissions**"); + }); + } + } +} diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index a0db1ef9..c89cb64c 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -20,6 +20,7 @@ namespace NadekoBot.Modules { commands.Add(new MessageRepeater()); commands.Add(new PlayingRotate()); commands.Add(new RatelimitCommand()); + commands.Add(new VoicePlusTextCommand()); } public override string Prefix { get; } = "."; @@ -376,7 +377,9 @@ namespace NadekoBot.Modules { .Parameter("user", ParameterType.Optional) .Do(async e => { var usr = e.User; - if (e.GetArg("user") != null) usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault(); + if (string.IsNullOrWhiteSpace(e.GetArg("user"))) usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault(); + if (usr == null) + return; await e.Channel.SendMessage($"Id of the user { usr.Name } is { usr.Id }"); }); diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index a4c2c959..1ff487db 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -142,6 +142,7 @@ + @@ -163,6 +164,7 @@ +