Example #1
0
        public override void HandleCommand(NotifyTextMessageEvent evt, string command, List <string> parameters, Action <string> messageCallback)
        {
            string action     = parameters[0];
            string targetUser = parameters[1];
            Client target     = Parent.Client.GetClientByNamePart(targetUser);
            Group  group      = null;

            if (action == "add" || action == "remove")
            {
                group = AccessManager.GetGroupByName(parameters[2]);
                if (group == null)
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"The group named '{ColorCoder.Bold(parameters[2])}' was not found"));
                    return;
                }
            }

            if (action == "add")
            {
                bool success = AccessManager.AddUserGroup(target.UniqueId, group);
                if (success)
                {
                    messageCallback.Invoke(ColorCoder.Success($"{ColorCoder.Username(target.Nickname)} was added to the group '{ColorCoder.Bold(group.DisplayName)}'"));
                }
                else
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"{ColorCoder.Username(target.Nickname)} is already in the group '{ColorCoder.Bold(group.DisplayName)}'"));
                }
            }
            else if (action == "remove")
            {
                bool success = AccessManager.RemoveUserGroup(target.UniqueId, group);
                if (success)
                {
                    messageCallback.Invoke(ColorCoder.Success($"{ColorCoder.Username(target.Nickname)} was removed from the group '{ColorCoder.Bold(group.DisplayName)}'"));
                }
                else
                {
                    messageCallback.Invoke(ColorCoder.ErrorBright($"{ColorCoder.Username(target.Nickname)} was not in the group '{ColorCoder.Bold(group.DisplayName)}'"));
                }
            }
            else if (action == "list")
            {
                List <Group> groups  = AccessManager.GetUserGroups(target.UniqueId);
                string       toPrint = $"{ColorCoder.Username(target.Nickname)} has the following groups:";
                foreach (Group printGroup in groups)
                {
                    toPrint += $"\n\t- {printGroup.DisplayName}";
                }
                messageCallback.Invoke(toPrint);
            }
        }