2016-03-09 23:58:54 +01:00
|
|
|
|
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;
|
2016-03-10 17:46:58 +01:00
|
|
|
|
using NadekoBot.Classes;
|
2016-03-09 23:58:54 +01:00
|
|
|
|
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 VoicePlusTextCommand() {
|
2016-03-10 17:46:58 +01:00
|
|
|
|
// changing servers may cause bugs
|
2016-03-09 23:58:54 +01:00
|
|
|
|
NadekoBot.Client.UserUpdated += async (sender, e) => {
|
|
|
|
|
try {
|
2016-03-10 17:46:58 +01:00
|
|
|
|
var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
2016-03-09 23:58:54 +01:00
|
|
|
|
if (e.Before.VoiceChannel == e.After.VoiceChannel) return;
|
2016-03-10 17:46:58 +01:00
|
|
|
|
if (!(config.VoicePlusTextEnabled ?? false))
|
|
|
|
|
return;
|
2016-03-09 23:58:54 +01:00
|
|
|
|
|
|
|
|
|
var beforeVch = e.Before.VoiceChannel;
|
|
|
|
|
if (beforeVch != null) {
|
|
|
|
|
var textChannel =
|
|
|
|
|
e.Server.FindChannels(beforeVch.Name + "-voice", ChannelType.Text).FirstOrDefault();
|
2016-03-10 17:46:58 +01:00
|
|
|
|
if (textChannel != null)
|
|
|
|
|
await textChannel.AddPermissionsRule(e.Before,
|
|
|
|
|
new ChPermOverride(readMessages: PermValue.Deny,
|
|
|
|
|
sendMessages: PermValue.Deny));
|
2016-03-09 23:58:54 +01:00
|
|
|
|
}
|
|
|
|
|
var afterVch = e.After.VoiceChannel;
|
|
|
|
|
if (afterVch != null) {
|
2016-03-10 10:06:36 +01:00
|
|
|
|
var textChannel = e.Server.FindChannels(
|
|
|
|
|
$"{afterVch.Name}-voice",
|
|
|
|
|
ChannelType.Text)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
if (textChannel == null) {
|
|
|
|
|
textChannel = (await e.Server.CreateChannel(afterVch.Name + "-voice", ChannelType.Text));
|
|
|
|
|
await textChannel.AddPermissionsRule(e.Server.EveryoneRole,
|
|
|
|
|
new ChPermOverride(readMessages: PermValue.Deny,
|
|
|
|
|
sendMessages: PermValue.Deny));
|
|
|
|
|
}
|
2016-03-09 23:58:54 +01:00
|
|
|
|
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")
|
2016-03-10 17:46:58 +01:00
|
|
|
|
.Description("Creates a text channel for each voice channel only users in that voice channel can see." +
|
|
|
|
|
"If you are server owner, keep in mind you will see them all the time regardless.")
|
2016-03-09 23:58:54 +01:00
|
|
|
|
.AddCheck(SimpleCheckers.ManageChannels())
|
|
|
|
|
.AddCheck(SimpleCheckers.CanManageRoles)
|
|
|
|
|
.Do(async e => {
|
2016-03-10 17:46:58 +01:00
|
|
|
|
try {
|
|
|
|
|
var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
|
|
|
|
if (config.VoicePlusTextEnabled == true) {
|
|
|
|
|
config.VoicePlusTextEnabled = false;
|
|
|
|
|
foreach (var textChannel in e.Server.TextChannels.Where(c => c.Name.EndsWith("-voice"))) {
|
|
|
|
|
try {
|
|
|
|
|
await textChannel.Delete();
|
|
|
|
|
} catch {
|
|
|
|
|
await
|
|
|
|
|
e.Channel.SendMessage(
|
|
|
|
|
":anger: Error: Most likely i don't have permissions to do this.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-03-09 23:58:54 +01:00
|
|
|
|
}
|
2016-03-10 17:46:58 +01:00
|
|
|
|
await e.Channel.SendMessage("Successfuly removed voice + text feature.");
|
|
|
|
|
return;
|
2016-03-09 23:58:54 +01:00
|
|
|
|
}
|
2016-03-10 17:46:58 +01:00
|
|
|
|
config.VoicePlusTextEnabled = true;
|
|
|
|
|
await e.Channel.SendMessage("Successfuly enabled voice + text feature. " +
|
|
|
|
|
"**Make sure the bot has manage roles and manage channels permissions**");
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
await e.Channel.SendMessage(ex.ToString());
|
2016-03-09 23:58:54 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|