示例#1
0
        public override void Initialize()
        {
            AssertPermission(GuildPermission.ManageChannels);

            _commandSet = new VoiceNameSet {
                ParentPlugin = this
            };
            GuildHandler.ChannelCreated        += OnChannelCreated;
            GuildHandler.ChannelDestroyed      += OnChannelDestroyed;
            GuildHandler.UserVoiceStateUpdated += OnVoiceStateUpdated;
            GuildHandler.GuildMemberUpdated    += OnGuildMemberUpdated;
            GuildHandler.ChannelUpdated        += OnChannelUpdated;
            InitDefaultTags();

            _channelNames = GetConfigCache("ChannelNames", x => x.GetGuild().VoiceChannels.ToDictionary(y => y.Id, z => z.Name));
            _channelNames.Store();

            _toIgnore = GetConfigCache("ToIgnore", x => new List <ulong> {
                (x.GetGuild().AFKChannel?.Id).GetValueOrDefault()
            });
            _musicBotId          = GetConfigCache("MusicBotId", x => (ulong)0);
            _internationalRoleId = GetConfigCache("MusicBotId", x => (ulong)0);
            _nameFormat          = GetConfigCache("NameFormat", x => $"{_formatStart}{_formatNameStr}{_formatEnd} - {_formatStart}{_formatGameStr}{_formatEnd} {_formatStart}({_formatAmountPlayersStr}){_formatEnd}"); // lol
            _shortenedGameNames  = GetConfigCache("ShortenedGameNames", x => new Dictionary <string, string>());

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

            AddConfigInfo <SocketVoiceChannel>("Dont Name Channel", "Ignore channel", x => _toIgnore.MutateValue(y => y.Add(x.Id)), (success, x) => $"Added channel '{x.Name}' to list of ignored channels.", "Channel");
            AddConfigInfo <ulong>("Dont Name Channel", "Ignore channel", x => _toIgnore.MutateValue(y => y.Add(GuildHandler.GetVoiceChannel(x).Id)), (success, x) => $"Added channel '{GuildHandler.GetVoiceChannel (x).Name}' to list of ignored channels.", "ignored");
            AddConfigInfo <string>("Dont Name Channel", "Ignore channel", x => _toIgnore.MutateValue(y => y.Add(GuildHandler.GetVoiceChannel(x).Id)), (success, x) => $"Added channel '{GuildHandler.GetVoiceChannel(x).Name}' to list of ignored channels.", "Channel");

            AddConfigInfo <SocketVoiceChannel>("Do Name Channel", "Unignore channel", x => _toIgnore.MutateValue(y => y.Remove(x.Id)), (success, x) => $"Removed channel '{x.Name}' from list of ignored.", "Channel");
            AddConfigInfo <ulong>("Do Name Channel", "Unignore channel", x => _toIgnore.MutateValue(y => y.Remove(GuildHandler.GetVoiceChannel(x).Id)), (success, x) => $"Removed channel '{GuildHandler.GetChannel(x)}' from list of ignored.", "Channel");
            AddConfigInfo <string>("Do Name Channel", "Unignore channel", x => _toIgnore.MutateValue(y => y.Remove(GuildHandler.GetVoiceChannel(x).Id)), (success, x) => $"Removed channel '{GuildHandler.GetChannel(x)}' from list of ignored.", "Channel");

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

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

            AddConfigInfo("Set Name Format", "Set format", () => $"Current format is '{_nameFormat.GetValue()}' which might look like this in practice: '{FormatName(_nameFormat.GetValue(), _formatStart, _formatEnd, "General 1", "Cool Game 3: The Coolest", 5)}'.");
            AddConfigInfo <string>("Set Name Format", "Set format", x => _nameFormat.SetValue(x), (success, x) => $"Set format to '{x}' which might look like this in practice: '{FormatName(x, _formatStart, _formatEnd, "General 1", "Cool Game 3: The Coolest", 5)}'.", "Format");

            AddConfigInfo <string, string>("Shorten Game Name", "Shorten a games name", (x, y) => SetShortenedGameName(x, y), (success, x, y) => $"'{x}' will now be shortened to '{y}'.", "Game", "Name");
            SendMessage("Moduthulhu-Command Root", "AddCommand", _commandSet);

            AddGeneralFeaturesStateAttribute("AutomatedVoiceNames", "Automatically changing voice channel names to reflect games played within.");

            RegisterMessageAction("AddTag", x => AddTag(new Tag((string)x[0], (string)x[1], (Func <SocketVoiceChannel, bool>)x[2])));
            RegisterMessageAction("RemoveTag", x => RemoveTag((string)x[0]));

            SetStateChangeHeaders("Tags", "The following voice channel tags has been added", "The following voice channel tags has been removed", "The following  voice channel tags has been modified");

            RegisterMessageAction("UpdateChannel", x => UpdateChannel(GuildHandler.GetVoiceChannel((ulong)x[0])).ConfigureAwait(false));
        }
示例#2
0
        public override void Initialize()
        {
            _announcementChannel = GetConfigCache("AnnouncementChannel", x => x.GetGuild().TextChannels.FirstOrDefault(y => y.Name == "general" || y.Name == "main" || y.Name == "chat").ZeroIfNull());
            _announcementMessage = GetConfigCache("AnnouncementMessage", x => "Congratulations to **[USERNAME]** as today they celebrate their [AGE] birthday!");

            AddConfigInfo <string>("Set Birthday Channel", "Set announcement channel.", x => _announcementChannel.SetValue(GuildHandler.GetVoiceChannel(x).Id), x => $"Channel channel set to {GuildHandler.GetTextChannel(x).Mention}.", "Channel Name");
            AddConfigInfo <ulong>("Set Birthday Channel", "Set announcement channel.", x => _announcementChannel.SetValue(GuildHandler.GetVoiceChannel(x).Id), x => $"Channel channel set to {GuildHandler.GetTextChannel(x).Mention}.", "Channel Id");
            AddConfigInfo <SocketTextChannel>("Set Birthday Channel", "Set announcement channel.", x => _announcementChannel.SetValue(x.Id), x => $"Channel channel set to {x.Name}", "Channel");
            AddConfigInfo("Set Birthday Channel", "Get announcement channel.", () => $"Current announcement channel is {GuildHandler.GetTextChannel(_announcementChannel.GetValue()).Mention}.");

            AddConfigInfo <string>("Set Birthday Message", "Set birthday message.", x => _announcementMessage.SetValue(x), x => $"New announcement message: '{x}'.", "Message");
            AddConfigInfo("Set Birthday Message", "Get birthday message.", () => $"Current announcement message: '{_announcementMessage.GetValue()}'.");

            _command = new BirthdayCommand {
                ParentPlugin = this
            };
            _allBirthdays = GetDataCache("Birthdays", x => new Dictionary <ulong, BirthdayDate>());

            GuildHandler.Clock.OnHourPassed += Clock_OnHourPassed;

            SendMessage("Moduthulhu-Command Root", "AddCommand", _command);

            AddGeneralFeaturesStateAttribute("BirthdayGreetings", "Automatic birthday wishing if desired.");
        }
示例#3
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}");
        }
示例#4
0
        private void AddResetter(ulong id)
        {
            TimedAction action = InvokeTimedAction(() => UpdateChannel(GuildHandler.GetVoiceChannel(id)).ConfigureAwait(false), _resetterTime);

            _resetters.Add(id, action);
        }