private void UpdateChannel(ulong voiceChannel, bool isLocked)
        {
            if (GuildHandler.Plugins.IsPluginActive(_autoVoiceNamePluginName))
            {
                SendMessage(_autoVoiceNamePluginName, "UpdateChannel", voiceChannel);
            }
            else
            {
                DisablePluginIfPermissionMissing(Discord.GuildPermission.ManageChannels, true);

                SocketVoiceChannel channel = GuildHandler.FindVoiceChannel(voiceChannel);
                if (channel != null)
                {
                    if (isLocked)
                    {
                        if (!channel.Name.StartsWith(_lockEmoji))
                        {
                            channel.ModifyAsync(x => x.Name = _lockEmoji + x.Name).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        if (channel.Name.StartsWith(_lockEmoji))
                        {
                            channel.ModifyAsync(x => x.Name = x.Name.Value.Substring(_lockEmoji.Length)).ConfigureAwait(false);
                        }
                    }
                }
            }
        }
        private void VoiceLock_OnUserRemoved(ulong channel, ulong user)
        {
            var voiceChannel = GuildHandler.FindVoiceChannel(channel);

            if (voiceChannel != null)
            {
                var voiceUser = voiceChannel.GetUser(user);
                if (voiceUser != null)
                {
                    voiceUser.ModifyAsync(x => x.Channel = null).ConfigureAwait(false);
                }
            }

            UpdateChannel(channel, IsLocked(channel));
        }
Пример #3
0
        public override void Initialize()
        {
            commandSet = new VoiceNameSet()
            {
                ParentPlugin = this
            };
            GuildHandler.ChannelCreated        += OnChannelCreated;
            GuildHandler.ChannelDestroyed      += OnChannelDestroyed;
            GuildHandler.UserVoiceStateUpdated += OnVoiceStateUpdated;
            GuildHandler.GuildMemberUpdated    += OnGuildMemberUpdated;
            InitDefaultTags();

            _channelNames = GetConfigCache("ChannelNames", x => x.GetGuild().VoiceChannels.ToDictionary(y => y.Id, z => z.Name));
            _toIgnore     = GetConfigCache("ToIgnore", x => new List <ulong>()
            {
                (x.GetGuild().AFKChannel?.Id).GetValueOrDefault()
            });
            //_nameFormat = GetConfigCache("NameFormat", x => "[TAGS][NAME] - [GAME]");
            _musicBotId          = GetConfigCache("MusicBotId", x => (ulong)0);
            _internationalRoleId = GetConfigCache("MusicBotId", x => (ulong)0);

            AddConfigInfo("Set Channel Name", "Display channel names", () => "Current channel names:\n" + string.Join('\n', _channelNames.GetValue().Select(x => x.Value).ToArray()));
            AddConfigInfo("Set Channel Name", "Set channel name", new Action <SocketVoiceChannel, string>((x, y) => _channelNames.MutateValue(z => z[x.Id] = y)), () => "Succesfully set channel names.", "Channel", "New name");
            AddConfigInfo("Set Channel Name", "Set channel name", new Action <string, string>((x, y) => _channelNames.MutateValue(z => z[GuildHandler.FindVoiceChannel(x).Id] = y)), () => "Succesfully set channel names.", "Channel", "New name");

            AddConfigInfo("Dont Name Channel", "Ignore channel", new Action <SocketVoiceChannel>((x) => _toIgnore.MutateValue(y => y.Add(x.Id))), () => "Added channel to list of ignored.", "Channel");
            AddConfigInfo("Dont Name Channel", "Ignore channel", new Action <ulong>((x) => _toIgnore.MutateValue(y => y.Add(x))), () => "Added channel to list of default.", "ignored");
            AddConfigInfo("Dont Name Channel", "Ignore channel", new Action <string>((x) => _toIgnore.MutateValue(y => y.Add(GuildHandler.FindVoiceChannel(x).Id))), () => "Added channel to list of ignored.", "Channel");

            AddConfigInfo("Do Name Channel", "Unignore channel", new Action <SocketVoiceChannel>((x) => _toIgnore.MutateValue(y => y.Remove(x.Id))), () => "Removed channel from list of ignored.", "Channel");
            AddConfigInfo("Do Name Channel", "Unignore channel", new Action <ulong>((x) => _toIgnore.MutateValue(y => y.Remove(x))), () => "Removed channel from list of ignored.", "Channel");
            AddConfigInfo("Do Name Channel", "Unignore channel", new Action <string>((x) => _toIgnore.MutateValue(y => y.Remove(GuildHandler.FindVoiceChannel(x).Id))), () => "Removed channel from list of ignored.", "Channel");

            AddConfigInfo("Set Music Bot", "Set music bot.", new Action <SocketGuildUser>((x) => _musicBotId.SetValue(x.Id)), () => $"Set music bot to be {GuildHandler.GetUser(_musicBotId.GetValue()).GetShownName()}.", "Music Bot");
            AddConfigInfo("Set Music Bot", "Set music bot.", new Action <string>((x) => _musicBotId.SetValue(GuildHandler.FindUser(x).Id)), () => $"Set music bot to be {GuildHandler.GetUser(_musicBotId.GetValue()).GetShownName()}.", "Music Bot");
            AddConfigInfo("Set Music Bot", "Show music bot.", () => GuildHandler.GetUser(_musicBotId.GetValue()) == null ? "Current music bot doesn't exist :(" : "Current music bot is " + GuildHandler.GetUser(_musicBotId.GetValue()).GetShownName());

            AddConfigInfo("Set International Role", "Set role.", new Action <SocketRole>((x) => _internationalRoleId.SetValue(x.Id)), () => $"Set international role to be {GuildHandler.GetRole(_internationalRoleId.GetValue()).Name}.", "Role");
            AddConfigInfo("Set International Role", "Set role.", new Action <string>((x) => _internationalRoleId.SetValue(GuildHandler.FindRole(x).Id)), () => $"Set international role to be {GuildHandler.GetRole(_internationalRoleId.GetValue()).Name}.", "Role Name");
            AddConfigInfo("Set International Role", "Show role.", () => GuildHandler.GetRole(_internationalRoleId.GetValue()) == null ? "Current international role doesn't exist :(" : "Current international role is " + GuildHandler.GetRole(_internationalRoleId.GetValue()).Name);

            SendMessage("Lomztein-Command Root", "AddCommand", commandSet);
        }
Пример #4
0
        private List <ulong> _temporaryChannels; // This isn't for config, but instead for keeping track of the active channels.

        public override void Initialize()
        {
            GuildHandler.UserVoiceStateUpdated += UserVoiceStateUpdated;
            GuildHandler.ChannelCreated        += OnChannelCreated;
            GuildHandler.ChannelDestroyed      += OnChannelDeleted;

            _defaultChannels = GetConfigCache("DefaultVoiceChannels", x => x.GetGuild().VoiceChannels.Select(y => y.Id).ToList());
            _newVoiceNames   = GetConfigCache("NewVoiceNames", x => new List <string>()
            {
                "Extra Voice 1", "Extra Voice 2"
            });
            _desiredFreeChannels = GetConfigCache("DesiredFreeChannels", x => 1);
            _ignoreChannels      = GetConfigCache("IgnoreChannels", x => new List <ulong>()
            {
                x.GetGuild().AFKChannel.ZeroIfNull()
            });
            _newChannelCategory = GetConfigCache("NewChannelCategory", x => (ulong)x.GetGuild().VoiceChannels.FirstOrDefault()?.CategoryId.GetValueOrDefault());

            AddConfigInfo("Add Default Channel", "Add default channel", new Action <SocketVoiceChannel>((x) => _defaultChannels.MutateValue(y => y.Add(x.Id))), () => "Added channel to list of default.", "Channel");
            AddConfigInfo("Add Default Channel", "Add default channel", new Action <ulong>((x) => _defaultChannels.MutateValue(y => y.Add(x))), () => "Added channel to list of default.", "Channel");
            AddConfigInfo("Add Default Channel", "Add default channel", new Action <string>((x) => _defaultChannels.MutateValue(y => y.Add(GuildHandler.FindVoiceChannel(x).Id))), () => "Added channel to list of default.", "Channel");
            AddConfigInfo("Add Default Channel", "List default channels", () => "Current default channels are:\n" + string.Join('\n', _defaultChannels.GetValue().Select(x => GuildHandler.GetVoiceChannel(x).Name)));

            AddConfigInfo("Remove Default Channel", "Remove default channel", new Action <SocketVoiceChannel>((x) => _defaultChannels.MutateValue(y => y.Remove(x.Id))), () => "Removed channel from list of default.", "Channel");
            AddConfigInfo("Remove Default Channel", "Remove default channel", new Action <ulong>((x) => _defaultChannels.MutateValue(y => y.Remove(x))), () => "Removed channel from list of default.", "Channel");
            AddConfigInfo("Remove Default Channel", "Remove default channel", new Action <string>((x) => _defaultChannels.MutateValue(y => y.Remove(GuildHandler.FindVoiceChannel(x).Id))), () => "Removed channel from list of default.", "Channel");

            AddConfigInfo("Add Voice Name", "Add voice name", new Action <string> (x => _newVoiceNames.MutateValue(y => y.Add(x))), () => "Added new voice name to list of possible options.", "Name");
            AddConfigInfo("Add Voice Name", "List voice names", () => "Current possible extra voice names: " + string.Join('\n', _newVoiceNames.GetValue()));
            AddConfigInfo("Remove Voice Name", "Remove voice name", new Action <string>(x => _newVoiceNames.MutateValue(y => y.Add(x))), () => "Removed voice name from list of possible options.", "Name");

            AddConfigInfo("Set Desired Free Channels", "Set desired amount", () => $"Set desired amount to {_desiredFreeChannels.GetValue()}");
            AddConfigInfo("Set Desired Free Channels", "Show desired amount", new Action <int> ((x) => _desiredFreeChannels.SetValue(x)), () => $"Current desired amount is {_desiredFreeChannels.GetValue()}", "Amount");

            AddConfigInfo("Ignore Channel", "Ignore channel", new Action <SocketVoiceChannel>((x) => _ignoreChannels.MutateValue(y => y.Add(x.Id))), () => "Added channel to list of ignored.", "Channel");
            AddConfigInfo("Ignore Channel", "Ignore channel", new Action <ulong>((x) => _ignoreChannels.MutateValue(y => y.Add(x))), () => "Added channel to list of default.", "ignored");
            AddConfigInfo("Ignore Channel", "Ignore channel", new Action <string>((x) => _ignoreChannels.MutateValue(y => y.Add(GuildHandler.FindVoiceChannel(x).Id))), () => "Added channel to list of ignored.", "Channel");

            AddConfigInfo("Unignore Channel", "Unignore channel", new Action <SocketVoiceChannel>((x) => _ignoreChannels.MutateValue(y => y.Remove(x.Id))), () => "Removed channel from list of ignored.", "Channel");
            AddConfigInfo("Unignore Channel", "Unignore channel", new Action <ulong>((x) => _ignoreChannels.MutateValue(y => y.Remove(x))), () => "Removed channel from list of ignored.", "Channel");
            AddConfigInfo("Unignore Channel", "Unignore channel", new Action <string>((x) => _ignoreChannels.MutateValue(y => y.Remove(GuildHandler.FindVoiceChannel(x).Id))), () => "Removed channel from list of ignored.", "Channel");

            AddConfigInfo("Set New Channel Category", "Set category", new Action <SocketCategoryChannel> ((x) => _newChannelCategory.SetValue(x.Id)), () => $"Set category where new channels will be created to {GuildHandler.GetCategoryChannel(_newChannelCategory.GetValue()).Name}", "Channel");
            AddConfigInfo("Set New Channel Category", "Set category", new Action <ulong> ((x) => _newChannelCategory.SetValue(x)), () => $"Set category where new channels will be created to {GuildHandler.GetCategoryChannel(_newChannelCategory.GetValue()).Name}", "Channel");
            AddConfigInfo("Set New Channel Category", "Set category", new Action <string> ((x) => _newChannelCategory.SetValue(GuildHandler.FindCategoryChannel(x).Id)), () => $"Set category where new channels will be created to {GuildHandler.GetCategoryChannel(_newChannelCategory.GetValue()).Name}", "Channel");
            AddConfigInfo("Set New Channel Category", "Get category", () => $"New channels will currently be created in category {GuildHandler.GetCategoryChannel(_newChannelCategory.GetValue()).Name}");
        }