예제 #1
0
 private void AddRole(ActivityRole newRole)
 {
     if (GuildHandler.GetRole(newRole.id) == null)
     {
         throw new InvalidOperationException("No such role exists.");
     }
     _activityRoles.MutateValue(x => x.Add(newRole));
 }
예제 #2
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);
        }
예제 #3
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 => $"{_formatNameStr} - {_formatGameStr} ({_formatAmountPlayersStr})");

            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), (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), (x, y) => "Succesfully set channel names.", "Channel", "New name");

            AddConfigInfo <SocketVoiceChannel>("Dont Name Channel", "Ignore channel", x => _toIgnore.MutateValue(y => y.Add(x.Id)), 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)), 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)), 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)), 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)), 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)), x => $"Removed channel '{GuildHandler.GetChannel(x)}' from list of ignored.", "Channel");

            AddConfigInfo <SocketGuildUser>("Set Music Bot", "Set music bot.", x => _musicBotId.SetValue(x.Id), 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), 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), x => $"Set international role to be {x}.", "Role");
            AddConfigInfo <string>("Set International Role", "Set role.", x => _internationalRoleId.SetValue(GuildHandler.GetRole(x).Id), 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(), "General 1", "Cool Game 3: The Coolest", 5)}'.");
            AddConfigInfo <string>("Set Name Format", "Set format", x => _nameFormat.SetValue(x), x => $"Set format to '{x}' which might look like this in practice: '{FormatName(x, "General 1", "Cool Game 3: The Coolest", 5)}'.", "Format");
            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));
        }
예제 #4
0
            public string ToString(GuildHandler roleSource)
            {
                SocketRole role = roleSource.GetRole(id);

                return($"Role: {role.Name}, treshold: {threshold} days.");
            }
        public override void Initialize()
        {
            AssertPermission(Discord.GuildPermission.ManageRoles);

            GuildHandler.MessageReceived       += DiscordClient_MessageReceived;
            GuildHandler.UserVoiceStateUpdated += DiscordClient_UserVoiceStateUpdated;
            GuildHandler.UserJoined            += DiscordClient_UserJoined;
            GuildHandler.RoleDeleted           += GuildHandler_RoleDeleted;

            AddConfigInfo("List Activity Roles", "Display roles", () => "Current activity roles:\n" + string.Join("\n", _activityRoles.GetValue().Select(x => x.ToString(GuildHandler)).ToArray()));

            AddConfigInfo <SocketRole, uint>("Add Activity Role", "Add new role.", (x, y) => AddRole(new ActivityRole(x.Id, y)), (success, x, y) => $"Added new activity role '{x.Name}' with a treshold of {y} days.", "Role", "Treshold (days)");
            AddConfigInfo <ulong, uint>("Add Activity Role", "Add new role.", (x, y) => AddRole(new ActivityRole(GuildHandler.GetRole(x).Id, y)), (success, x, y) => $"Added new activity role '{GuildHandler.GetRole(x).Name}' with a treshold of {y} days.", "Role", "Treshold (days)");
            AddConfigInfo <string, uint>("Add Activity Role", "Add new role.", (x, y) => AddRole(new ActivityRole(GuildHandler.GetRole(x).Id, y)), (success, x, y) => $"Added new activity role '{GuildHandler.GetRole(x).Name}' with a treshold of {y} days.", "Role", "Treshold (days)");

            AddConfigInfo <SocketRole>("Remove Activity Role", "Remove role.", x => RemoveRole(x.Id), (success, x) => $"Removed activity role {x.Name}.", "Role");
            AddConfigInfo <string>("Remove Activity Role", "Remove role.", x => RemoveRole(GuildHandler.GetRole(x).Id), (success, x) => $"Removed activity role '{x}'", "Role");

            _userActivity  = GetDataCache("UserActivity", x => new Dictionary <ulong, DateTime>());
            _activityRoles = GetConfigCache("ActivityRoles", x => new List <ActivityRole>());

            GuildHandler.Clock.OnDayPassed += CheckAll;
            PerformFilterMissing();
        }