Voice+Text ! thx to @Googie2149, song cutoff fix attempt
This commit is contained in:
parent
08ae95d55d
commit
1433ff0e03
@ -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;
|
||||
|
@ -12,7 +12,10 @@ namespace NadekoBot.Classes.Permissions {
|
||||
(com, user, ch) => NadekoBot.IsOwner(user.Id);
|
||||
|
||||
public static Func<Command, User, Channel, bool> ManageMessages() =>
|
||||
(com, user, ch) => NadekoBot.IsOwner(user.Id);
|
||||
(com, user, ch) => user.ServerPermissions.ManageMessages;
|
||||
|
||||
public static Func<Command, User, Channel, bool> ManageChannels() =>
|
||||
(com, user, ch) => user.ServerPermissions.ManageChannels;
|
||||
|
||||
public class ManageRoles :IPermissionChecker
|
||||
{
|
||||
|
83
NadekoBot/Commands/VoicePlusTextCommand.cs
Normal file
83
NadekoBot/Commands/VoicePlusTextCommand.cs
Normal file
@ -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 {
|
||||
/// <summary>
|
||||
/// 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 ;(
|
||||
/// </summary>
|
||||
internal class VoicePlusTextCommand : IDiscordCommand {
|
||||
public static readonly HashSet<ulong> Subscribers = new HashSet<ulong>();
|
||||
|
||||
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**");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -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 }");
|
||||
});
|
||||
|
||||
|
@ -142,6 +142,7 @@
|
||||
<Compile Include="Classes\_DataModels\TypingArticleModel.cs" />
|
||||
<Compile Include="Classes\_DataModels\UserQuoteModel.cs" />
|
||||
<Compile Include="Commands\ClashOfClans.cs" />
|
||||
<Compile Include="Commands\FilterWordsCommand.cs" />
|
||||
<Compile Include="Commands\FilterInvitesCommand.cs" />
|
||||
<Compile Include="Commands\LogCommand.cs" />
|
||||
<Compile Include="Commands\LoLCommands.cs" />
|
||||
@ -163,6 +164,7 @@
|
||||
<Compile Include="Commands\FlipCoinCommand.cs" />
|
||||
<Compile Include="Commands\HelpCommand.cs" />
|
||||
<Compile Include="Commands\VoiceNotificationCommand.cs" />
|
||||
<Compile Include="Commands\VoicePlusTextCommand.cs" />
|
||||
<Compile Include="Modules\Administration.cs" />
|
||||
<Compile Include="Modules\Conversations.cs" />
|
||||
<Compile Include="Modules\DiscordModule.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user